@@ -331,7 +331,6 @@ public void onFailure(final Exception e) {
331331 public TimeValue timeout () {
332332 return request .masterNodeTimeout ();
333333 }
334-
335334 });
336335 }
337336
@@ -394,6 +393,8 @@ private void beginSnapshot(final ClusterState clusterState,
394393
395394 boolean snapshotCreated ;
396395
396+ boolean hadAbortedInitializations ;
397+
397398 @ Override
398399 protected void doRun () {
399400 assert initializingSnapshots .contains (snapshot .snapshot ());
@@ -433,6 +434,8 @@ public ClusterState execute(ClusterState currentState) {
433434
434435 if (entry .state () == State .ABORTED ) {
435436 entries .add (entry );
437+ assert entry .shards ().isEmpty ();
438+ hadAbortedInitializations = true ;
436439 } else {
437440 // Replace the snapshot that was just initialized
438441 ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards =
@@ -491,6 +494,14 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
491494 // completion listener in this method. For the snapshot completion to work properly, the snapshot
492495 // should still exist when listener is registered.
493496 userCreateSnapshotListener .onResponse (snapshot .snapshot ());
497+
498+ if (hadAbortedInitializations ) {
499+ final SnapshotsInProgress snapshotsInProgress = newState .custom (SnapshotsInProgress .TYPE );
500+ assert snapshotsInProgress != null ;
501+ final SnapshotsInProgress .Entry entry = snapshotsInProgress .snapshot (snapshot .snapshot ());
502+ assert entry != null ;
503+ endSnapshot (entry );
504+ }
494505 }
495506 });
496507 }
@@ -701,8 +712,8 @@ public void applyClusterState(ClusterChangedEvent event) {
701712 // 3. Snapshots in any other state that have all their shard tasks completed
702713 snapshotsInProgress .entries ().stream ().filter (
703714 entry -> entry .state ().completed ()
704- || entry . state () == State . INIT && initializingSnapshots .contains (entry .snapshot ()) == false
705- || entry .state () != State .INIT && completed (entry .shards ().values ())
715+ || initializingSnapshots .contains (entry .snapshot ()) == false
716+ && ( entry .state () == State .INIT || completed (entry .shards ().values () ))
706717 ).forEach (this ::endSnapshot );
707718 }
708719 if (newMaster ) {
0 commit comments