diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java index 8d5cc71f472..8173ac06440 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MetaDataStateIndexService.java @@ -76,14 +76,18 @@ public class MetaDataStateIndexService extends AbstractComponent { .metaData(currentState.metaData()) .put(IndexMetaData.newIndexMetaDataBuilder(currentState.metaData().index(request.index)).state(IndexMetaData.State.CLOSE)); + ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()) + .addIndexBlock(request.index, INDEX_CLOSED_BLOCK); + + ClusterState updatedState = ClusterState.builder().state(currentState).metaData(mdBuilder).blocks(blocks).build(); + RoutingTable.Builder rtBuilder = RoutingTable.builder() .routingTable(currentState.routingTable()) .remove(request.index); - ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()) - .addIndexBlock(request.index, INDEX_CLOSED_BLOCK); + RoutingAllocation.Result routingResult = shardsAllocation.reroute(newClusterStateBuilder().state(updatedState).routingTable(rtBuilder).build()); - return ClusterState.builder().state(currentState).metaData(mdBuilder).routingTable(rtBuilder).blocks(blocks).build(); + return ClusterState.builder().state(updatedState).routingResult(routingResult).build(); } @Override public void clusterStateProcessed(ClusterState clusterState) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java index 1a7e234dec9..fb2feea1b78 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java @@ -20,7 +20,11 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.cluster.*; +import org.elasticsearch.cluster.ClusterChangedEvent; +import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ClusterStateListener; +import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.ShardsAllocation; import org.elasticsearch.common.component.AbstractLifecycleComponent; @@ -88,14 +92,15 @@ public class RoutingService extends AbstractLifecycleComponent i routingTableDirty = true; scheduledRoutingTableFuture = threadPool.scheduleWithFixedDelay(new RoutingTableUpdater(), schedule); } - if (event.nodesRemoved() || event.routingTableChanged()) { + if (event.nodesRemoved()) { // if nodes were removed, we don't want to wait for the scheduled task // since we want to get primary election as fast as possible - - // also, if the routing table changed, it means that we have new indices, or shard have started - // or failed, we want to apply this as fast as possible routingTableDirty = true; reroute(); + // Commented out since we make sure to reroute whenever shards changes state or metadata changes state +// } else if (event.routingTableChanged()) { +// routingTableDirty = true; +// reroute(); } else { if (event.nodesAdded()) { routingTableDirty = true;