make sure to reroute whenever required on the action itself (most already did, added index state case), and then, no need to do additional reroute (which probably does not do anything, and returns the same cluster state) on the routing update handler
This commit is contained in:
parent
abfc7f0db4
commit
c872be75ae
|
@ -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) {
|
||||
|
|
|
@ -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<RoutingService> 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;
|
||||
|
|
Loading…
Reference in New Issue