Skip to content

Commit 794c2f3

Browse files
committed
Snapshot clones do not conflict with index deletes (#75298)
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.
1 parent e97c4ce commit 794c2f3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3395,7 +3395,7 @@ public static Set<Index> snapshottingIndices(final ClusterState currentState, fi
33953395

33963396
final Set<Index> indices = new HashSet<>();
33973397
for (final SnapshotsInProgress.Entry entry : snapshots.entries()) {
3398-
if (entry.partial() == false) {
3398+
if (entry.partial() == false && entry.isClone() == false) {
33993399
for (String indexName : entry.indices().keySet()) {
34003400
IndexMetadata indexMetadata = currentState.metadata().index(indexName);
34013401
if (indexMetadata != null && indicesToCheck.contains(indexMetadata.getIndex())) {

server/src/test/java/org/elasticsearch/snapshots/SnapshotsServiceTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
import java.util.stream.Collectors;
3838
import java.util.stream.StreamSupport;
3939

40+
import static java.util.Collections.singleton;
4041
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED;
42+
import static org.hamcrest.Matchers.empty;
4143
import static org.hamcrest.Matchers.is;
4244

4345
public class SnapshotsServiceTests extends ESTestCase {
@@ -384,6 +386,24 @@ public void testCompletedCloneStartsNextClone() throws Exception {
384386
assertIsNoop(updatedClusterState, completeShardClone);
385387
}
386388

389+
public void testSnapshottingIndicesExcludesClones() {
390+
final String repoName = "test-repo";
391+
final String indexName = "index";
392+
final ClusterState clusterState = stateWithSnapshots(
393+
stateWithUnassignedIndices(indexName),
394+
cloneEntry(
395+
snapshot(repoName, "target-snapshot"),
396+
snapshot(repoName, "source-snapshot").getSnapshotId(),
397+
clonesMap(new RepositoryShardId(indexId(indexName), 0), initShardStatus(uuid()))
398+
)
399+
);
400+
401+
assertThat(
402+
SnapshotsService.snapshottingIndices(clusterState, singleton(clusterState.metadata().index(indexName).getIndex())),
403+
empty()
404+
);
405+
}
406+
387407
private static DiscoveryNodes discoveryNodes(String localNodeId) {
388408
return DiscoveryNodes.builder().localNodeId(localNodeId).build();
389409
}

0 commit comments

Comments
 (0)