Skip to content

Commit

Permalink
Fixed the SnapshotsInProgress error during index deletion (#4570)
Browse files Browse the repository at this point in the history
Signed-off-by: Xue Zhou <xuezhou@amazon.com>
  • Loading branch information
xuezhou25 committed Oct 4, 2022
1 parent bd532e1 commit 0ee4ab6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,31 @@ public void testSnapshotDeleteRelocatingPrimaryIndex() throws Exception {
logger.info("--> done");
}

public void testIndexDeletionDuringSnapshotCreationInQueue() throws Exception {
assertAcked(prepareCreate("test-idx", 1, indexSettingsNoReplicas(1)));
ensureGreen();
indexRandomDocs("test-idx", 100);
createRepository("test-repo", "fs");
createSnapshot("test-repo", "test-snap", Collections.singletonList("test-idx"));

logger.info("--> create snapshot to be deleted and then delete");
createSnapshot("test-repo", "test-snap-delete", Collections.singletonList("test-idx"));
clusterAdmin().prepareDeleteSnapshot("test-repo", "test-snap-delete").execute();

logger.info("--> create snapshot before index deletion during above snapshot deletion");
clusterAdmin().prepareCreateSnapshot("test-repo", "test-snap-2")
.setWaitForCompletion(false)
.setPartial(true)
.setIndices("test-idx")
.get();

logger.info("delete index during snapshot creation");
assertAcked(admin().indices().prepareDelete("test-idx"));

clusterAdmin().prepareRestoreSnapshot("test-repo", "test-snap").get();
ensureGreen("test-idx");
}

private long calculateTotalFilesSize(List<Path> files) {
return files.stream().mapToLong(f -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2965,8 +2965,14 @@ private SnapshotsInProgress updatedSnapshotsInProgress(ClusterState currentState
updatedAssignmentsBuilder.put(shardId, updated);
}
}
snapshotEntries.add(entry.withStartedShards(updatedAssignmentsBuilder.build()));
final SnapshotsInProgress.Entry updatedEntry = entry.withShardStates(updatedAssignmentsBuilder.build());
snapshotEntries.add(updatedEntry);
changed = true;
// When all the required shards for a snapshot are missing, the snapshot state will be "completed"
// need to finalize it.
if (updatedEntry.state().completed()) {
newFinalizations.add(entry);
}
}
} else {
// Entry is already completed so we will finalize it now that the delete doesn't block us after
Expand Down

0 comments on commit 0ee4ab6

Please sign in to comment.