Skip to content

Commit

Permalink
Snapshot clones do not conflict with index deletes (#75298)
Browse files Browse the repository at this point in the history
Today we refuse to delete an index if it is the subject of an ongoing
non-partial snapshot, but we also consider the indices targetted by
ongoing clones. This commit ignores clones in the conflict detection
logic.
  • Loading branch information
DaveCTurner committed Jul 13, 2021
1 parent 2cade00 commit f3946a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3395,7 +3395,7 @@ public static Set<Index> snapshottingIndices(final ClusterState currentState, fi

final Set<Index> indices = new HashSet<>();
for (final SnapshotsInProgress.Entry entry : snapshots.entries()) {
if (entry.partial() == false) {
if (entry.partial() == false && entry.isClone() == false) {
for (String indexName : entry.indices().keySet()) {
IndexMetadata indexMetadata = currentState.metadata().index(indexName);
if (indexMetadata != null && indicesToCheck.contains(indexMetadata.getIndex())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static java.util.Collections.singleton;
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;

public class SnapshotsServiceTests extends ESTestCase {
Expand Down Expand Up @@ -384,6 +386,24 @@ public void testCompletedCloneStartsNextClone() throws Exception {
assertIsNoop(updatedClusterState, completeShardClone);
}

public void testSnapshottingIndicesExcludesClones() {
final String repoName = "test-repo";
final String indexName = "index";
final ClusterState clusterState = stateWithSnapshots(
stateWithUnassignedIndices(indexName),
cloneEntry(
snapshot(repoName, "target-snapshot"),
snapshot(repoName, "source-snapshot").getSnapshotId(),
clonesMap(new RepositoryShardId(indexId(indexName), 0), initShardStatus(uuid()))
)
);

assertThat(
SnapshotsService.snapshottingIndices(clusterState, singleton(clusterState.metadata().index(indexName).getIndex())),
empty()
);
}

private static DiscoveryNodes discoveryNodes(String localNodeId) {
return DiscoveryNodes.builder().localNodeId(localNodeId).build();
}
Expand Down

0 comments on commit f3946a4

Please sign in to comment.