Skip to content

Commit bb1359f

Browse files
authored
Disallow snapshot deletion while a v2 snapshot is in progress (#16430)
--------- Signed-off-by: Gaurav Bafna <[email protected]>
1 parent 9489a21 commit bb1359f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,13 @@ public void testDeleteWhileV2CreateOngoing() throws Exception {
529529
awaitNumberOfSnapshotsInProgress(1);
530530

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

533534
unblockNode(repoName, clusterManagerName);
534535
CreateSnapshotResponse csr = snapshotFuture.actionGet();
535536
assertTrue(csr.getSnapshotInfo().getPinnedTimestamp() != 0);
536-
assertTrue(a.actionGet().isAcknowledged());
537537
List<SnapshotInfo> snapInfo = client().admin().cluster().prepareGetSnapshots(repoName).get().getSnapshots();
538-
assertEquals(1, snapInfo.size());
539-
assertThat(snapInfo, contains(csr.getSnapshotInfo()));
538+
assertEquals(2, snapInfo.size());
540539
}
541540

542541
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/16205")

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,8 @@ public void onResponse(RepositoryData repositoryData) {
619619
}
620620
cleanOrphanTimestamp(repositoryName, repositoryData);
621621
logger.info("created snapshot-v2 [{}] in repository [{}]", repositoryName, snapshotName);
622+
leaveRepoLoop(repositoryName);
622623
listener.onResponse(snapshotInfo);
623-
// For snapshot-v2, we don't allow concurrent snapshots . But meanwhile non-v2 snapshot operations
624-
// can get queued . This is triggering them.
625-
runNextQueuedOperation(repositoryData, repositoryName, true);
626624
}
627625

628626
@Override
@@ -1021,10 +1019,8 @@ public void onResponse(RepositoryData repositoryData) {
10211019
return;
10221020
}
10231021
logger.info("snapshot-v2 clone [{}] completed successfully", snapshot);
1022+
leaveRepoLoop(repositoryName);
10241023
listener.onResponse(null);
1025-
// For snapshot-v2, we don't allow concurrent snapshots . But meanwhile non-v2 snapshot operations
1026-
// can get queued . This is triggering them.
1027-
runNextQueuedOperation(repositoryData, repositoryName, true);
10281024
}
10291025

10301026
@Override
@@ -2564,6 +2560,19 @@ public void deleteSnapshots(final DeleteSnapshotRequest request, final ActionLis
25642560
public ClusterState execute(ClusterState currentState) throws Exception {
25652561
final SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY);
25662562
final List<SnapshotsInProgress.Entry> snapshotEntries = findInProgressSnapshots(snapshots, snapshotNames, repoName);
2563+
boolean isSnapshotV2 = SHALLOW_SNAPSHOT_V2.get(repository.getMetadata().settings());
2564+
boolean remoteStoreIndexShallowCopy = remoteStoreShallowCopyEnabled(repository);
2565+
List<SnapshotsInProgress.Entry> entriesForThisRepo = snapshots.entries()
2566+
.stream()
2567+
.filter(entry -> Objects.equals(entry.repository(), repoName))
2568+
.collect(Collectors.toList());
2569+
if (isSnapshotV2 && remoteStoreIndexShallowCopy && entriesForThisRepo.isEmpty() == false) {
2570+
throw new ConcurrentSnapshotExecutionException(
2571+
repoName,
2572+
String.join(",", snapshotNames),
2573+
"cannot delete snapshots in v2 repo while a snapshot is in progress"
2574+
);
2575+
}
25672576
final List<SnapshotId> snapshotIds = matchingSnapshotIds(
25682577
snapshotEntries.stream().map(e -> e.snapshot().getSnapshotId()).collect(Collectors.toList()),
25692578
repositoryData,

0 commit comments

Comments
 (0)