@@ -1874,7 +1874,9 @@ private static Tuple<ClusterState, List<SnapshotDeletionsInProgress.Entry>> read
18741874 final var projectRepo = new ProjectRepo (entry .projectId (), entry .repository ());
18751875 if (repositoriesSeen .add (projectRepo )
18761876 && entry .state () == SnapshotDeletionsInProgress .State .WAITING
1877- && snapshotsInProgress .forRepo (projectRepo ).stream ().noneMatch (SnapshotsService ::isWritingToRepository )) {
1877+ && snapshotsInProgress .forRepo (projectRepo )
1878+ .stream ()
1879+ .noneMatch (SnapshotsService ::isWritingToRepositoryOrQueueWithGeneration )) {
18781880 changed = true ;
18791881 final SnapshotDeletionsInProgress .Entry newEntry = entry .started ();
18801882 readyDeletions .add (newEntry );
@@ -2293,14 +2295,26 @@ public ClusterState execute(ClusterState currentState) {
22932295 }
22942296 // Snapshot ids that will have to be physically deleted from the repository
22952297 final Set <SnapshotId > snapshotIdsRequiringCleanup = new HashSet <>(snapshotIds );
2298+
2299+ final List <Runnable > completeAbortedQueuedWithGenerationRunnables = new ArrayList <>();
22962300 final SnapshotsInProgress updatedSnapshots = snapshotsInProgress .createCopyWithUpdatedEntriesForRepo (
22972301 projectId ,
22982302 repositoryName ,
22992303 snapshotsInProgress .forRepo (projectId , repositoryName ).stream ().map (existing -> {
23002304 if (existing .state () == SnapshotsInProgress .State .STARTED
23012305 && snapshotIdsRequiringCleanup .contains (existing .snapshot ().getSnapshotId ())) {
23022306 // snapshot is started - mark every non completed shard as aborted
2303- final SnapshotsInProgress .Entry abortedEntry = existing .abort ();
2307+ final SnapshotsInProgress .Entry abortedEntry = existing .abort (
2308+ ((shardId , shardSnapshotStatus ) -> completeAbortedQueuedWithGenerationRunnables .add (
2309+ () -> innerUpdateSnapshotState (
2310+ existing .snapshot (),
2311+ shardId ,
2312+ null ,
2313+ shardSnapshotStatus ,
2314+ ActionListener .noop ()
2315+ )
2316+ ))
2317+ );
23042318 if (abortedEntry == null ) {
23052319 // No work has been done for this snapshot yet so we remove it from the cluster state directly
23062320 final Snapshot existingNotYetStartedSnapshot = existing .snapshot ();
@@ -2318,6 +2332,9 @@ public ClusterState execute(ClusterState currentState) {
23182332 return existing ;
23192333 }).filter (Objects ::nonNull ).toList ()
23202334 );
2335+ for (var runnable : completeAbortedQueuedWithGenerationRunnables ) {
2336+ runnable .run ();
2337+ }
23212338 if (snapshotIdsRequiringCleanup .isEmpty ()) {
23222339 // We only saw snapshots that could be removed from the cluster state right away, no need to update the deletions
23232340 return updateWithSnapshots (currentState , updatedSnapshots , null );
@@ -2350,7 +2367,9 @@ public ClusterState execute(ClusterState currentState) {
23502367 List .copyOf (snapshotIdsRequiringCleanup ),
23512368 threadPool .absoluteTimeInMillis (),
23522369 repositoryData .getGenId (),
2353- updatedSnapshots .forRepo (projectId , repositoryName ).stream ().noneMatch (SnapshotsService ::isWritingToRepository )
2370+ updatedSnapshots .forRepo (projectId , repositoryName )
2371+ .stream ()
2372+ .noneMatch (SnapshotsService ::isWritingToRepositoryOrQueueWithGeneration )
23542373 && deletionsInProgress .hasExecutingDeletion (projectId , repositoryName ) == false
23552374 ? SnapshotDeletionsInProgress .State .STARTED
23562375 : SnapshotDeletionsInProgress .State .WAITING
@@ -2432,13 +2451,13 @@ public String toString() {
24322451 * @param entry snapshot entry
24332452 * @return true if entry is currently writing to the repository
24342453 */
2435- private static boolean isWritingToRepository (SnapshotsInProgress .Entry entry ) {
2454+ private static boolean isWritingToRepositoryOrQueueWithGeneration (SnapshotsInProgress .Entry entry ) {
24362455 if (entry .state ().completed ()) {
24372456 // Entry is writing to the repo because it's finalizing on master
24382457 return true ;
24392458 }
24402459 for (ShardSnapshotStatus value : entry .shardSnapshotStatusByRepoShardId ().values ()) {
2441- if (value .isActive ()) {
2460+ if (value .isActiveOrQueuedWithGeneration ()) {
24422461 // Entry is writing to the repo because it's writing to a shard on a data node or waiting to do so for a concrete shard
24432462 return true ;
24442463 }
0 commit comments