瀏覽代碼

Deduplicate RetentionLease.source (#92347)

We only ever see the strings "ccr" or "peer recovery" here.
A recent experiment with ccr and many follower clusters following
one leader, revealed 100s of MB being wasted on duplicate "ccr"
strings when fetching index stats -> lets fix this by simple
deduplication.
Armin Braun 2 年之前
父節點
當前提交
d800d26e5d
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      server/src/main/java/org/elasticsearch/index/seqno/RetentionLease.java

+ 7 - 5
server/src/main/java/org/elasticsearch/index/seqno/RetentionLease.java

@@ -99,7 +99,12 @@ public final class RetentionLease implements ToXContentObject, Writeable {
         this.id = id;
         this.retainingSequenceNumber = retainingSequenceNumber;
         this.timestamp = timestamp;
-        this.source = source;
+        // deduplicate the string instances to save memory for the known possible source values
+        this.source = switch (source) {
+            case "ccr" -> "ccr";
+            case ReplicationTracker.PEER_RECOVERY_RETENTION_LEASE_SOURCE -> ReplicationTracker.PEER_RECOVERY_RETENTION_LEASE_SOURCE;
+            default -> source;
+        };
     }
 
     /**
@@ -109,10 +114,7 @@ public final class RetentionLease implements ToXContentObject, Writeable {
      * @throws IOException if an I/O exception occurs reading from the stream
      */
     public RetentionLease(final StreamInput in) throws IOException {
-        id = in.readString();
-        retainingSequenceNumber = in.readZLong();
-        timestamp = in.readVLong();
-        source = in.readString();
+        this(in.readString(), in.readZLong(), in.readVLong(), in.readString());
     }
 
     /**