Skip to content

Commit 31643a5

Browse files
Remove Dead Branch from IndexMetadataGenerations#withAddedSnapshot (#73658)
We never do (nor should) call this method to overwrite a snapshots existing entry, checks and assertions upstream make sure of that. => simplified the code accordingly
1 parent b2619ec commit 31643a5

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,22 @@ public String indexMetaBlobId(SnapshotId snapshotId, IndexId indexId) {
9494
*/
9595
public IndexMetaDataGenerations withAddedSnapshot(SnapshotId snapshotId, Map<IndexId, String> newLookup,
9696
Map<String, String> newIdentifiers) {
97-
final Map<String, String> identifierDeduplicator = new HashMap<>(this.identifiers.size());
98-
for (String identifier : identifiers.keySet()) {
99-
identifierDeduplicator.put(identifier, identifier);
100-
}
10197
final Map<SnapshotId, Map<IndexId, String>> updatedIndexMetaLookup = new HashMap<>(this.lookup);
10298
final Map<String, String> updatedIndexMetaIdentifiers = new HashMap<>(identifiers);
10399
updatedIndexMetaIdentifiers.putAll(newIdentifiers);
104-
updatedIndexMetaLookup.compute(snapshotId, (snId, lookup) -> {
105-
if (lookup == null) {
106-
if (newLookup.isEmpty()) {
107-
return null;
108-
}
109-
final Map<IndexId, String> fixedLookup = new HashMap<>(newLookup.size());
110-
for (Map.Entry<IndexId, String> entry : newLookup.entrySet()) {
111-
final String generation = entry.getValue();
112-
fixedLookup.put(entry.getKey(), identifierDeduplicator.getOrDefault(generation, generation));
113-
}
114-
return Map.copyOf(fixedLookup);
115-
} else {
116-
final Map<IndexId, String> updated = new HashMap<>(lookup);
117-
updated.putAll(newLookup);
118-
return Map.copyOf(updated);
100+
if (newLookup.isEmpty() == false) {
101+
final Map<String, String> identifierDeduplicator = new HashMap<>(this.identifiers.size());
102+
for (String identifier : identifiers.keySet()) {
103+
identifierDeduplicator.put(identifier, identifier);
104+
}
105+
final Map<IndexId, String> fixedLookup = new HashMap<>(newLookup.size());
106+
for (Map.Entry<IndexId, String> entry : newLookup.entrySet()) {
107+
final String generation = entry.getValue();
108+
fixedLookup.put(entry.getKey(), identifierDeduplicator.getOrDefault(generation, generation));
119109
}
120-
});
110+
final Map<IndexId, String> existing = updatedIndexMetaLookup.put(snapshotId, Map.copyOf(fixedLookup));
111+
assert existing == null : "unexpected existing index generation mappings " + existing;
112+
}
121113
return new IndexMetaDataGenerations(updatedIndexMetaLookup, updatedIndexMetaIdentifiers);
122114
}
123115

0 commit comments

Comments
 (0)