diff --git a/server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java b/server/src/main/java/org/elasticsearch/repositories/IndexMetaDataGenerations.java index adb84d9116038..b282a4129b532 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 Map.copyOf(fixedLookup); - } else { - final Map updated = new HashMap<>(lookup); - updated.putAll(newLookup); - return Map.copyOf(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, Map.copyOf(fixedLookup)); + assert existing == null : "unexpected existing index generation mappings " + existing; + } return new IndexMetaDataGenerations(updatedIndexMetaLookup, updatedIndexMetaIdentifiers); }