Skip to content

Commit a7cc3d0

Browse files
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.
1 parent 8b34388 commit a7cc3d0

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.snapshots.SnapshotId;
1616

1717
import java.util.Collection;
18-
import java.util.Collections;
1918
import java.util.HashMap;
2019
import java.util.HashSet;
2120
import java.util.Map;
@@ -32,7 +31,7 @@
3231
*/
3332
public final class IndexMetaDataGenerations {
3433

35-
public static final IndexMetaDataGenerations EMPTY = new IndexMetaDataGenerations(Collections.emptyMap(), Collections.emptyMap());
34+
public static final IndexMetaDataGenerations EMPTY = new IndexMetaDataGenerations(Map.of(), Map.of());
3635

3736
/**
3837
* Map of {@link SnapshotId} to a map of the indices in a snapshot mapping {@link IndexId} to metadata identifiers.
@@ -94,7 +93,7 @@ public String indexMetaBlobId(SnapshotId snapshotId, IndexId indexId) {
9493
*/
9594
@Nullable
9695
public String snapshotIndexMetadataIdentifier(SnapshotId snapshotId, IndexId indexId) {
97-
return lookup.getOrDefault(snapshotId, Collections.emptyMap()).get(indexId);
96+
return lookup.getOrDefault(snapshotId, Map.of()).get(indexId);
9897
}
9998

10099
/**

server/src/main/java/org/elasticsearch/repositories/RepositoryData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ private static IndexMetaDataGenerations buildIndexMetaGenerations(
875875
for (Map.Entry<String, String> generationEntry : val.entrySet()) {
876876
forSnapshot.put(indexLookup.get(generationEntry.getKey()), generationEntry.getValue());
877877
}
878-
indexGenerations.put(snapshotIdMapEntry.getKey(), forSnapshot);
878+
indexGenerations.put(snapshotIdMapEntry.getKey(), Map.copyOf(forSnapshot));
879879
}
880880
return new IndexMetaDataGenerations(indexGenerations, indexMetaIdentifiers);
881881
}

0 commit comments

Comments
 (0)