Skip to content

Commit

Permalink
Remove Dead Branch from IndexMetadataGenerations#withAddedSnapshot (e…
Browse files Browse the repository at this point in the history
…lastic#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
  • Loading branch information
original-brownbear committed Jun 2, 2021
1 parent 812697e commit 73c1c1c
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,22 @@ public String indexMetaBlobId(SnapshotId snapshotId, IndexId indexId) {
*/
public IndexMetaDataGenerations withAddedSnapshot(SnapshotId snapshotId, Map<IndexId, String> newLookup,
Map<String, String> newIdentifiers) {
final Map<String, String> identifierDeduplicator = new HashMap<>(this.identifiers.size());
for (String identifier : identifiers.keySet()) {
identifierDeduplicator.put(identifier, identifier);
}
final Map<SnapshotId, Map<IndexId, String>> updatedIndexMetaLookup = new HashMap<>(this.lookup);
final Map<String, String> updatedIndexMetaIdentifiers = new HashMap<>(identifiers);
updatedIndexMetaIdentifiers.putAll(newIdentifiers);
updatedIndexMetaLookup.compute(snapshotId, (snId, lookup) -> {
if (lookup == null) {
if (newLookup.isEmpty()) {
return null;
}
final Map<IndexId, String> fixedLookup = new HashMap<>(newLookup.size());
for (Map.Entry<IndexId, String> entry : newLookup.entrySet()) {
final String generation = entry.getValue();
fixedLookup.put(entry.getKey(), identifierDeduplicator.getOrDefault(generation, generation));
}
return Collections.unmodifiableMap(new HashMap<>(fixedLookup));
} else {
final Map<IndexId, String> updated = new HashMap<>(lookup);
updated.putAll(newLookup);
return Collections.unmodifiableMap(updated);
if (newLookup.isEmpty() == false) {
final Map<String, String> identifierDeduplicator = new HashMap<>(this.identifiers.size());
for (String identifier : identifiers.keySet()) {
identifierDeduplicator.put(identifier, identifier);
}
final Map<IndexId, String> fixedLookup = new HashMap<>(newLookup.size());
for (Map.Entry<IndexId, String> entry : newLookup.entrySet()) {
final String generation = entry.getValue();
fixedLookup.put(entry.getKey(), identifierDeduplicator.getOrDefault(generation, generation));
}
});
final Map<IndexId, String> existing = updatedIndexMetaLookup.put(snapshotId, Collections.unmodifiableMap(fixedLookup));
assert existing == null : "unexpected existing index generation mappings " + existing;
}
return new IndexMetaDataGenerations(updatedIndexMetaLookup, updatedIndexMetaIdentifiers);
}

Expand Down

0 comments on commit 73c1c1c

Please sign in to comment.