Skip to content

Commit 7e989ab

Browse files
Remove Dead Code from Closed Index Snapshot Logic (#56764)
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 2e13702 commit 7e989ab

File tree

1 file changed

+7
-39
lines changed

1 file changed

+7
-39
lines changed

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

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -234,27 +234,18 @@ public ClusterState execute(ClusterState currentState) {
234234
ImmutableOpenMap<ShardId, ShardSnapshotStatus> shards =
235235
shards(currentState, indexIds, useShardGenerations(version), repositoryData);
236236
if (request.partial() == false) {
237-
Tuple<Set<String>, Set<String>> indicesWithMissingShards = indicesWithMissingShards(shards,
238-
currentState.metadata());
239-
Set<String> missing = indicesWithMissingShards.v1();
240-
Set<String> closed = indicesWithMissingShards.v2();
241-
if (missing.isEmpty() == false || closed.isEmpty() == false) {
242-
final StringBuilder failureMessage = new StringBuilder();
243-
if (missing.isEmpty() == false) {
244-
failureMessage.append("Indices don't have primary shards ");
245-
failureMessage.append(missing);
246-
}
247-
if (closed.isEmpty() == false) {
248-
if (failureMessage.length() > 0) {
249-
failureMessage.append("; ");
250-
}
251-
failureMessage.append("Indices are closed ");
237+
Set<String> missing = new HashSet<>();
238+
for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) {
239+
if (entry.value.state() == ShardState.MISSING) {
240+
missing.add(entry.key.getIndex().getName());
252241
}
242+
}
243+
if (missing.isEmpty() == false) {
253244
// TODO: We should just throw here instead of creating a FAILED and hence useless snapshot in the repository
254245
newEntry = new SnapshotsInProgress.Entry(
255246
new Snapshot(repositoryName, snapshotId), request.includeGlobalState(), false,
256247
State.FAILED, indexIds, threadPool.absoluteTimeInMillis(), repositoryData.getGenId(), shards,
257-
failureMessage.toString(), userMeta, version);
248+
"Indices don't have primary shards " + missing, userMeta, version);
258249
}
259250
}
260251
if (newEntry == null) {
@@ -697,29 +688,6 @@ private static boolean removedNodesCleanupNeeded(SnapshotsInProgress snapshotsIn
697688
.anyMatch(removedNodes.stream().map(DiscoveryNode::getId).collect(Collectors.toSet())::contains);
698689
}
699690

700-
/**
701-
* Returns list of indices with missing shards, and list of indices that are closed
702-
*
703-
* @param shards list of shard statuses
704-
* @return list of failed and closed indices
705-
*/
706-
private static Tuple<Set<String>, Set<String>> indicesWithMissingShards(
707-
ImmutableOpenMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards, Metadata metadata) {
708-
Set<String> missing = new HashSet<>();
709-
Set<String> closed = new HashSet<>();
710-
for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) {
711-
if (entry.value.state() == ShardState.MISSING) {
712-
if (metadata.hasIndex(entry.key.getIndex().getName()) &&
713-
metadata.getIndexSafe(entry.key.getIndex()).getState() == IndexMetadata.State.CLOSE) {
714-
closed.add(entry.key.getIndex().getName());
715-
} else {
716-
missing.add(entry.key.getIndex().getName());
717-
}
718-
}
719-
}
720-
return new Tuple<>(missing, closed);
721-
}
722-
723691
/**
724692
* Finalizes the shard in repository and then removes it from cluster state
725693
* <p>

0 commit comments

Comments
 (0)