diff --git a/server/src/main/java/org/elasticsearch/repositories/ShardGenerations.java b/server/src/main/java/org/elasticsearch/repositories/ShardGenerations.java index 6e8ae1956f945..e42552d3e5f3c 100644 --- a/server/src/main/java/org/elasticsearch/repositories/ShardGenerations.java +++ b/server/src/main/java/org/elasticsearch/repositories/ShardGenerations.java @@ -9,6 +9,7 @@ package org.elasticsearch.repositories; import org.elasticsearch.cluster.SnapshotsInProgress; +import org.elasticsearch.common.Strings; import org.elasticsearch.core.Nullable; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; @@ -219,12 +220,22 @@ public Builder put(IndexId indexId, int shardId, SnapshotsInProgress.ShardSnapsh } public Builder put(IndexId indexId, int shardId, ShardGeneration generation) { + assert noDuplicateIndicesWithSameName(indexId); ShardGeneration existingGeneration = generations.computeIfAbsent(indexId, i -> new HashMap<>()).put(shardId, generation); assert generation != null || existingGeneration == null : "must not overwrite existing generation with null generation [" + existingGeneration + "]"; return this; } + private boolean noDuplicateIndicesWithSameName(IndexId newId) { + for (IndexId id : generations.keySet()) { + if (id.getName().equals(newId.getName()) && id.equals(newId) == false) { + assert false : Strings.format("Unable to add: %s. There's another index id with the same name: %s", newId, id); + } + } + return true; + } + public ShardGenerations build() { return new ShardGenerations(generations.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> { final Set shardIds = entry.getValue().keySet();