diff --git a/src/main/java/org/elasticsearch/indices/store/IndicesStore.java b/src/main/java/org/elasticsearch/indices/store/IndicesStore.java index b965cc36dab..3d8411fc40b 100644 --- a/src/main/java/org/elasticsearch/indices/store/IndicesStore.java +++ b/src/main/java/org/elasticsearch/indices/store/IndicesStore.java @@ -140,10 +140,24 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe shardCanBeDeleted = false; break; } - String localNodeId = clusterService.localNode().id(); + + // if the allocated or relocation node id doesn't exists in the cluster state, its a stale + // node, make sure we don't do anything with this until the routing table has properly been + // rerouted to reflect the fact that the node does not exists + if (!event.state().nodes().nodeExists(shardRouting.currentNodeId())) { + shardCanBeDeleted = false; + break; + } + if (shardRouting.relocatingNodeId() != null) { + if (!event.state().nodes().nodeExists(shardRouting.relocatingNodeId())) { + shardCanBeDeleted = false; + break; + } + } + // check if shard is active on the current node or is getting relocated to the our node + String localNodeId = clusterService.localNode().id(); if (localNodeId.equals(shardRouting.currentNodeId()) || localNodeId.equals(shardRouting.relocatingNodeId())) { - // shard will be used locally - keep it shardCanBeDeleted = false; break; }