Skip to content

Commit 8590d31

Browse files
xuezhou25sashashura
authored andcommitted
Fixed the SnapshotsInProgress error during index deletion (opensearch-project#4570)
Signed-off-by: Xue Zhou <[email protected]>
1 parent 9903f87 commit 8590d31

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
9191
- Fixed the ignore_malformed setting to also ignore objects ([#4494](https://github.com/opensearch-project/OpenSearch/pull/4494))
9292
- [Segment Replication] Ignore lock file when testing cleanupAndPreserveLatestCommitPoint ([#4544](https://github.com/opensearch-project/OpenSearch/pull/4544))
9393
- Updated jackson to 2.13.4 and snakeyml to 1.32 ([#4556](https://github.com/opensearch-project/OpenSearch/pull/4556))
94+
- Fixed the SnapshotsInProgress error during index deletion ([#4570](https://github.com/opensearch-project/OpenSearch/pull/4570))
9495
- [Segment Replication] Adding check to make sure checkpoint is not processed when a shard's shard routing is primary ([#4630](https://github.com/opensearch-project/OpenSearch/pull/4630))
9596
- [Bug]: Fixed invalid location of JDK dependency for arm64 architecture([#4613](https://github.com/opensearch-project/OpenSearch/pull/4613))
9697
- [Bug]: Alias filter lost after rollover ([#4499](https://github.com/opensearch-project/OpenSearch/pull/4499))
@@ -122,4 +123,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
122123

123124

124125
[Unreleased]: https://github.com/opensearch-project/OpenSearch/compare/2.2.0...HEAD
125-
[2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.2.0...2.x
126+
[2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.2.0...2.x

server/src/internalClusterTest/java/org/opensearch/snapshots/DedicatedClusterSnapshotRestoreIT.java

+25
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,31 @@ public void testSnapshotDeleteRelocatingPrimaryIndex() throws Exception {
14751475
logger.info("--> done");
14761476
}
14771477

1478+
public void testIndexDeletionDuringSnapshotCreationInQueue() throws Exception {
1479+
assertAcked(prepareCreate("test-idx", 1, indexSettingsNoReplicas(1)));
1480+
ensureGreen();
1481+
indexRandomDocs("test-idx", 100);
1482+
createRepository("test-repo", "fs");
1483+
createSnapshot("test-repo", "test-snap", Collections.singletonList("test-idx"));
1484+
1485+
logger.info("--> create snapshot to be deleted and then delete");
1486+
createSnapshot("test-repo", "test-snap-delete", Collections.singletonList("test-idx"));
1487+
clusterAdmin().prepareDeleteSnapshot("test-repo", "test-snap-delete").execute();
1488+
1489+
logger.info("--> create snapshot before index deletion during above snapshot deletion");
1490+
clusterAdmin().prepareCreateSnapshot("test-repo", "test-snap-2")
1491+
.setWaitForCompletion(false)
1492+
.setPartial(true)
1493+
.setIndices("test-idx")
1494+
.get();
1495+
1496+
logger.info("delete index during snapshot creation");
1497+
assertAcked(admin().indices().prepareDelete("test-idx"));
1498+
1499+
clusterAdmin().prepareRestoreSnapshot("test-repo", "test-snap").get();
1500+
ensureGreen("test-idx");
1501+
}
1502+
14781503
private long calculateTotalFilesSize(List<Path> files) {
14791504
return files.stream().mapToLong(f -> {
14801505
try {

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -2965,8 +2965,14 @@ private SnapshotsInProgress updatedSnapshotsInProgress(ClusterState currentState
29652965
updatedAssignmentsBuilder.put(shardId, updated);
29662966
}
29672967
}
2968-
snapshotEntries.add(entry.withStartedShards(updatedAssignmentsBuilder.build()));
2968+
final SnapshotsInProgress.Entry updatedEntry = entry.withShardStates(updatedAssignmentsBuilder.build());
2969+
snapshotEntries.add(updatedEntry);
29692970
changed = true;
2971+
// When all the required shards for a snapshot are missing, the snapshot state will be "completed"
2972+
// need to finalize it.
2973+
if (updatedEntry.state().completed()) {
2974+
newFinalizations.add(entry);
2975+
}
29702976
}
29712977
} else {
29722978
// Entry is already completed so we will finalize it now that the delete doesn't block us after

0 commit comments

Comments
 (0)