From 73c1c1cddb78e672b794a4631a6d29f0fd700cba Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Wed, 2 Jun 2021 14:29:25 +0200 Subject: [PATCH] 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 --- .../IndexMetaDataGenerations.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java b/server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java index 1c17aa021dc68..89d6597b39e8a 100644 --- a/server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java +++ b/server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java @@ -94,30 +94,22 @@ public String indexMetaBlobId(SnapshotId snapshotId, IndexId indexId) { */ public IndexMetaDataGenerations withAddedSnapshot(SnapshotId snapshotId, Map newLookup, Map newIdentifiers) { - final Map identifierDeduplicator = new HashMap<>(this.identifiers.size()); - for (String identifier : identifiers.keySet()) { - identifierDeduplicator.put(identifier, identifier); - } final Map> updatedIndexMetaLookup = new HashMap<>(this.lookup); final Map updatedIndexMetaIdentifiers = new HashMap<>(identifiers); updatedIndexMetaIdentifiers.putAll(newIdentifiers); - updatedIndexMetaLookup.compute(snapshotId, (snId, lookup) -> { - if (lookup == null) { - if (newLookup.isEmpty()) { - return null; - } - final Map fixedLookup = new HashMap<>(newLookup.size()); - for (Map.Entry 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 updated = new HashMap<>(lookup); - updated.putAll(newLookup); - return Collections.unmodifiableMap(updated); + if (newLookup.isEmpty() == false) { + final Map identifierDeduplicator = new HashMap<>(this.identifiers.size()); + for (String identifier : identifiers.keySet()) { + identifierDeduplicator.put(identifier, identifier); + } + final Map fixedLookup = new HashMap<>(newLookup.size()); + for (Map.Entry entry : newLookup.entrySet()) { + final String generation = entry.getValue(); + fixedLookup.put(entry.getKey(), identifierDeduplicator.getOrDefault(generation, generation)); } - }); + final Map existing = updatedIndexMetaLookup.put(snapshotId, Collections.unmodifiableMap(fixedLookup)); + assert existing == null : "unexpected existing index generation mappings " + existing; + } return new IndexMetaDataGenerations(updatedIndexMetaLookup, updatedIndexMetaIdentifiers); }