From f4d6d20e6313783f21b0b38e6a3c971a05e98886 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 5 Feb 2019 21:15:29 +0100 Subject: [PATCH] Fix Master Failover and DataNode Leave Blocking Snapshot * Closes #38447 --- .../java/org/elasticsearch/snapshots/SnapshotsService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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); } }