Apply shard starts in a single batch
This commit is contained in:
parent
99eac0e7d7
commit
928d53a884
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue