Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow snapshot deletion while a v2 snapshot is in progress #16430

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,13 @@ public void testDeleteWhileV2CreateOngoing() throws Exception {
awaitNumberOfSnapshotsInProgress(1);

ActionFuture<AcknowledgedResponse> a = startDeleteSnapshot(repoName, "snapshot-v1");
expectThrows(ConcurrentSnapshotExecutionException.class, a::actionGet);

unblockNode(repoName, clusterManagerName);
CreateSnapshotResponse csr = snapshotFuture.actionGet();
assertTrue(csr.getSnapshotInfo().getPinnedTimestamp() != 0);
assertTrue(a.actionGet().isAcknowledged());
List<SnapshotInfo> snapInfo = client().admin().cluster().prepareGetSnapshots(repoName).get().getSnapshots();
assertEquals(1, snapInfo.size());
assertThat(snapInfo, contains(csr.getSnapshotInfo()));
assertEquals(2, snapInfo.size());
}

@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/16205")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,8 @@
}
cleanOrphanTimestamp(repositoryName, repositoryData);
logger.info("created snapshot-v2 [{}] in repository [{}]", repositoryName, snapshotName);
leaveRepoLoop(repositoryName);
listener.onResponse(snapshotInfo);
// For snapshot-v2, we don't allow concurrent snapshots . But meanwhile non-v2 snapshot operations
// can get queued . This is triggering them.
runNextQueuedOperation(repositoryData, repositoryName, true);
}

@Override
Expand Down Expand Up @@ -1021,10 +1019,8 @@
return;
}
logger.info("snapshot-v2 clone [{}] completed successfully", snapshot);
leaveRepoLoop(repositoryName);

Check warning on line 1022 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1022 was not covered by tests
listener.onResponse(null);
// For snapshot-v2, we don't allow concurrent snapshots . But meanwhile non-v2 snapshot operations
// can get queued . This is triggering them.
runNextQueuedOperation(repositoryData, repositoryName, true);
}

@Override
Expand Down Expand Up @@ -2564,6 +2560,19 @@
public ClusterState execute(ClusterState currentState) throws Exception {
final SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY);
final List<SnapshotsInProgress.Entry> snapshotEntries = findInProgressSnapshots(snapshots, snapshotNames, repoName);
boolean isSnapshotV2 = SHALLOW_SNAPSHOT_V2.get(repository.getMetadata().settings());
boolean remoteStoreIndexShallowCopy = remoteStoreShallowCopyEnabled(repository);
List<SnapshotsInProgress.Entry> entriesForThisRepo = snapshots.entries()
.stream()
.filter(entry -> Objects.equals(entry.repository(), repoName))
.collect(Collectors.toList());
if (isSnapshotV2 && remoteStoreIndexShallowCopy && entriesForThisRepo.isEmpty() == false) {
throw new ConcurrentSnapshotExecutionException(

Check warning on line 2570 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L2570 was not covered by tests
repoName,
String.join(",", snapshotNames),

Check warning on line 2572 in server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L2572 was not covered by tests
"cannot delete snapshots in v2 repo while a snapshot is in progress"
);
}
final List<SnapshotId> snapshotIds = matchingSnapshotIds(
snapshotEntries.stream().map(e -> e.snapshot().getSnapshotId()).collect(Collectors.toList()),
repositoryData,
Expand Down
Loading