瀏覽代碼

Build more compact RepositoryData when parsing from JSON (#91817)

Low effort imporovement to #89952 mostly.

We should be turning the index identifier lookup into an immutable map
when parsing these right away. We do this conversion/copy for both the adding
and removing of snapshots from the `IndexMetadataGenerations` later on anyways
so this doesn't add any CPU cost overall. What it does however is save a massive
amount of heap for single index snapshots (where the overhead of hash map over
the immutable map is the greatest) when first parsing this structure from the repo
and potentially having it duplicated on heap many times over due to #89952.
Armin Braun 2 年之前
父節點
當前提交
a7cc3d08d6

+ 2 - 3
server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java

@@ -15,7 +15,6 @@ import org.elasticsearch.core.Nullable;
 import org.elasticsearch.snapshots.SnapshotId;
 
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -32,7 +31,7 @@ import java.util.stream.Collectors;
  */
 public final class IndexMetaDataGenerations {
 
-    public static final IndexMetaDataGenerations EMPTY = new IndexMetaDataGenerations(Collections.emptyMap(), Collections.emptyMap());
+    public static final IndexMetaDataGenerations EMPTY = new IndexMetaDataGenerations(Map.of(), Map.of());
 
     /**
      * Map of {@link SnapshotId} to a map of the indices in a snapshot mapping {@link IndexId} to metadata identifiers.
@@ -94,7 +93,7 @@ public final class IndexMetaDataGenerations {
      */
     @Nullable
     public String snapshotIndexMetadataIdentifier(SnapshotId snapshotId, IndexId indexId) {
-        return lookup.getOrDefault(snapshotId, Collections.emptyMap()).get(indexId);
+        return lookup.getOrDefault(snapshotId, Map.of()).get(indexId);
     }
 
     /**

+ 1 - 1
server/src/main/java/org/elasticsearch/repositories/RepositoryData.java

@@ -875,7 +875,7 @@ public final class RepositoryData {
             for (Map.Entry<String, String> generationEntry : val.entrySet()) {
                 forSnapshot.put(indexLookup.get(generationEntry.getKey()), generationEntry.getValue());
             }
-            indexGenerations.put(snapshotIdMapEntry.getKey(), forSnapshot);
+            indexGenerations.put(snapshotIdMapEntry.getKey(), Map.copyOf(forSnapshot));
         }
         return new IndexMetaDataGenerations(indexGenerations, indexMetaIdentifiers);
     }