diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index 17306e1585ff8..e2628fda991bd 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -687,8 +687,9 @@ public void applyClusterState(ClusterChangedEvent event) { if (event.localNodeMaster()) { // We don't remove old master when master flips anymore. So, we need to check for change in master final SnapshotsInProgress snapshotsInProgress = event.state().custom(SnapshotsInProgress.TYPE); + final boolean newMaster = event.previousState().nodes().isLocalNodeElectedMaster() == false; if (snapshotsInProgress != null) { - if (removedNodesCleanupNeeded(snapshotsInProgress, event.nodesDelta().removedNodes())) { + if (newMaster || removedNodesCleanupNeeded(snapshotsInProgress, event.nodesDelta().removedNodes())) { processSnapshotsOnRemovedNodes(); } if (event.routingTableChanged() && waitingShardsStartedOrUnassigned(snapshotsInProgress, event)) { @@ -704,7 +705,7 @@ public void applyClusterState(ClusterChangedEvent event) { || entry.state() != State.INIT && completed(entry.shards().values()) ).forEach(this::endSnapshot); } - if (event.previousState().nodes().isLocalNodeElectedMaster() == false) { + if (newMaster) { finalizeSnapshotDeletionFromPreviousMaster(event); } }