@@ -1396,13 +1396,8 @@ public void onResponse(RepositoryData updatedRepositoryData) {
13961396
13971397 @ Override
13981398 public void onFailure (Exception e ) {
1399- handleFinalizationFailure (
1400- e ,
1401- snapshot ,
1402- repositoryData ,
1403- // we might have written the new root blob before failing here, so we must use the updated shardGenerations
1404- shardGenerations
1405- );
1399+ // we might have written the new root blob before failing here, so we must use the updated shardGenerations
1400+ handleFinalizationFailure (e , shardGenerations );
14061401 }
14071402 },
14081403
@@ -1456,7 +1451,7 @@ public void onFailure(Exception e) {
14561451 public void onRejection (Exception e ) {
14571452 if (e instanceof EsRejectedExecutionException esre && esre .isExecutorShutdown ()) {
14581453 logger .debug ("failing finalization of {} due to shutdown" , snapshot );
1459- handleFinalizationFailure ( e , snapshot , repositoryData , ShardGenerations . EMPTY );
1454+ handleFinalizationFailureBeforeUpdatingRootBlob ( e );
14601455 } else {
14611456 onFailure (e );
14621457 }
@@ -1466,7 +1461,7 @@ public void onRejection(Exception e) {
14661461 public void onFailure (Exception e ) {
14671462 logger .error (Strings .format ("unexpected failure finalizing %s" , snapshot ), e );
14681463 assert false : new AssertionError ("unexpected failure finalizing " + snapshot , e );
1469- handleFinalizationFailure ( e , snapshot , repositoryData , ShardGenerations . EMPTY );
1464+ handleFinalizationFailureBeforeUpdatingRootBlob ( e );
14701465 }
14711466
14721467 private static ShardGenerations buildGenerations (SnapshotsInProgress .Entry snapshot , Metadata metadata ) {
@@ -1642,23 +1637,19 @@ private static Map<String, SnapshotInfo.IndexSnapshotDetails> getIndexSnapshotDe
16421637 return indexSnapshotDetails ;
16431638 }
16441639
1640+ private void handleFinalizationFailureBeforeUpdatingRootBlob (Exception e ) {
1641+ // No need to update shard generations in cluster state if we didn't update the root blob, so use ShardGenerations.EMPTY
1642+ handleFinalizationFailure (e , ShardGenerations .EMPTY );
1643+ }
1644+
16451645 /**
16461646 * Handles failure to finalize a snapshot. If the exception indicates that this node was unable to publish a cluster state and
16471647 * stopped being the master node, then fail all snapshot create and delete listeners executing on this node by delegating to
16481648 * {@link #failAllListenersOnMasterFailOver}. Otherwise, i.e. as a result of failing to write to the snapshot repository for some
16491649 * reason, remove the snapshot's {@link SnapshotsInProgress.Entry} from the cluster state and move on with other queued snapshot
16501650 * operations if there are any.
1651- *
1652- * @param e exception encountered
1653- * @param snapshot snapshot that failed to finalize
1654- * @param repositoryData current repository data for the snapshot's repository
16551651 */
1656- private void handleFinalizationFailure (
1657- Exception e ,
1658- Snapshot snapshot ,
1659- RepositoryData repositoryData ,
1660- ShardGenerations shardGenerations
1661- ) {
1652+ private void handleFinalizationFailure (Exception e , ShardGenerations shardGenerations ) {
16621653 if (ExceptionsHelper .unwrap (e , NotMasterException .class , FailedToCommitClusterStateException .class ) != null ) {
16631654 // Failure due to not being master any more, don't try to remove snapshot from cluster state the next master
16641655 // will try ending this snapshot again
0 commit comments