Skip to content

Commit 4e574a7

Browse files
Remove Dead Code from Closed Index Snapshot Logic (#56764) (#59398)
The code path for closed indices is dead code here ever since #39644 because `shards(currentState, indexIds, ...)` does not set `MISSING` on a closed index's shard that is assigned any longer. Before that change it would always set `MISSING` for a closed index's shard even it was assigned. => simplified the code accordingly.
1 parent 3fb9dcc commit 4e574a7

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -366,27 +366,18 @@ public ClusterState execute(ClusterState currentState) {
366366
ImmutableOpenMap<ShardId, ShardSnapshotStatus> shards =
367367
shards(currentState, indexIds, useShardGenerations(version), repositoryData);
368368
if (request.partial() == false) {
369-
Tuple<Set<String>, Set<String>> indicesWithMissingShards = indicesWithMissingShards(shards,
370-
currentState.metadata());
371-
Set<String> missing = indicesWithMissingShards.v1();
372-
Set<String> closed = indicesWithMissingShards.v2();
373-
if (missing.isEmpty() == false || closed.isEmpty() == false) {
374-
final StringBuilder failureMessage = new StringBuilder();
375-
if (missing.isEmpty() == false) {
376-
failureMessage.append("Indices don't have primary shards ");
377-
failureMessage.append(missing);
378-
}
379-
if (closed.isEmpty() == false) {
380-
if (failureMessage.length() > 0) {
381-
failureMessage.append("; ");
382-
}
383-
failureMessage.append("Indices are closed ");
369+
Set<String> missing = new HashSet<>();
370+
for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) {
371+
if (entry.value.state() == ShardState.MISSING) {
372+
missing.add(entry.key.getIndex().getName());
384373
}
374+
}
375+
if (missing.isEmpty() == false) {
385376
// TODO: We should just throw here instead of creating a FAILED and hence useless snapshot in the repository
386377
newEntry = new SnapshotsInProgress.Entry(
387378
new Snapshot(repositoryName, snapshotId), request.includeGlobalState(), false,
388379
State.FAILED, indexIds, dataStreams, threadPool.absoluteTimeInMillis(), repositoryData.getGenId(), shards,
389-
failureMessage.toString(), userMeta, version);
380+
"Indices don't have primary shards " + missing, userMeta, version);
390381
}
391382
}
392383
if (newEntry == null) {

0 commit comments

Comments
 (0)