diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index afecde30e4eac..0bf0ae373a3b1 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -234,27 +234,18 @@ public ClusterState execute(ClusterState currentState) { ImmutableOpenMap shards = shards(currentState, indexIds, useShardGenerations(version), repositoryData); if (request.partial() == false) { - Tuple, Set> indicesWithMissingShards = indicesWithMissingShards(shards, - currentState.metadata()); - Set missing = indicesWithMissingShards.v1(); - Set closed = indicesWithMissingShards.v2(); - if (missing.isEmpty() == false || closed.isEmpty() == false) { - final StringBuilder failureMessage = new StringBuilder(); - if (missing.isEmpty() == false) { - failureMessage.append("Indices don't have primary shards "); - failureMessage.append(missing); - } - if (closed.isEmpty() == false) { - if (failureMessage.length() > 0) { - failureMessage.append("; "); - } - failureMessage.append("Indices are closed "); + Set missing = new HashSet<>(); + for (ObjectObjectCursor entry : shards) { + if (entry.value.state() == ShardState.MISSING) { + missing.add(entry.key.getIndex().getName()); } + } + if (missing.isEmpty() == false) { // TODO: We should just throw here instead of creating a FAILED and hence useless snapshot in the repository newEntry = new SnapshotsInProgress.Entry( new Snapshot(repositoryName, snapshotId), request.includeGlobalState(), false, State.FAILED, indexIds, threadPool.absoluteTimeInMillis(), repositoryData.getGenId(), shards, - failureMessage.toString(), userMeta, version); + "Indices don't have primary shards " + missing, userMeta, version); } } if (newEntry == null) { @@ -697,29 +688,6 @@ private static boolean removedNodesCleanupNeeded(SnapshotsInProgress snapshotsIn .anyMatch(removedNodes.stream().map(DiscoveryNode::getId).collect(Collectors.toSet())::contains); } - /** - * Returns list of indices with missing shards, and list of indices that are closed - * - * @param shards list of shard statuses - * @return list of failed and closed indices - */ - private static Tuple, Set> indicesWithMissingShards( - ImmutableOpenMap shards, Metadata metadata) { - Set missing = new HashSet<>(); - Set closed = new HashSet<>(); - for (ObjectObjectCursor entry : shards) { - if (entry.value.state() == ShardState.MISSING) { - if (metadata.hasIndex(entry.key.getIndex().getName()) && - metadata.getIndexSafe(entry.key.getIndex()).getState() == IndexMetadata.State.CLOSE) { - closed.add(entry.key.getIndex().getName()); - } else { - missing.add(entry.key.getIndex().getName()); - } - } - } - return new Tuple<>(missing, closed); - } - /** * Finalizes the shard in repository and then removes it from cluster state *