Apply shard starts in a single batch

This commit is contained in:
Jason Tedor 2015-12-01 11:36:29 -05:00
parent 99eac0e7d7
commit 928d53a884
2 changed files with 13 additions and 27 deletions

View File

@ -199,22 +199,24 @@ public class ShardStateAction extends AbstractComponent {
@Override
public BatchResult<ShardRoutingEntry> execute(ClusterState currentState, List<ShardRoutingEntry> tasks) throws Exception {
BatchResult.Builder<ShardRoutingEntry> builder = BatchResult.builder();
ClusterState accumulator = ClusterState.builder(currentState).build();
List<ShardRouting> shardRoutingsToBeApplied = new ArrayList<>(tasks.size());
for (ShardRoutingEntry task : tasks) {
task.processed = true;
try {
RoutingAllocation.Result result =
allocationService.applyStartedShard(currentState, task.shardRouting, true);
builder.success(task);
if (result.changed()) {
accumulator = ClusterState.builder(accumulator).routingResult(result).build();
}
} catch (Throwable t) {
builder.failure(task, t);
shardRoutingsToBeApplied.add(task.shardRouting);
}
ClusterState maybeUpdatedState = currentState;
try {
RoutingAllocation.Result result =
allocationService.applyStartedShards(currentState, shardRoutingsToBeApplied, true);
if (result.changed()) {
maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
}
builder.successes(tasks);
} catch (Throwable t) {
builder.failures(tasks, t);
}
return builder.build(accumulator);
return builder.build(maybeUpdatedState);
}
@Override

View File

@ -63,22 +63,6 @@ public class AllocationService extends AbstractComponent {
this.clusterInfoService = clusterInfoService;
}
/**
* Applies the started shard. Note, shards can be called several
* times within this method. If the same instance of the routing
* table is returned, then no change has been made.
* @param clusterState the cluster state
* @param startedShard the shard to start
* @param withReroute whether or not to reroute the resulting allocation
* @return the resulting routing table
*/
public RoutingAllocation.Result applyStartedShard(
ClusterState clusterState,
ShardRouting startedShard,
boolean withReroute) {
return applyStartedShards(clusterState, Collections.singletonList(startedShard), withReroute);
}
/**
* Applies the started shards. Note, shards can be called several times within this method.
* <p>