Skip to content

Commit

Permalink
Build more compact RepositoryData when parsing from JSON
Browse files Browse the repository at this point in the history
Low effort imporovement to elastic#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 elastic#89952.
  • Loading branch information
original-brownbear committed Nov 22, 2022
1 parent 7c6025d commit 43dc01c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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;
Expand All @@ -32,7 +31,7 @@
*/
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.
Expand Down Expand Up @@ -94,7 +93,7 @@ public String indexMetaBlobId(SnapshotId snapshotId, IndexId indexId) {
*/
@Nullable
public String snapshotIndexMetadataIdentifier(SnapshotId snapshotId, IndexId indexId) {
return lookup.getOrDefault(snapshotId, Collections.emptyMap()).get(indexId);
return lookup.getOrDefault(snapshotId, Map.of()).get(indexId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ private static IndexMetaDataGenerations buildIndexMetaGenerations(
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);
}
Expand Down

0 comments on commit 43dc01c

Please sign in to comment.