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
|
@Override
|
||||||
public BatchResult<ShardRoutingEntry> execute(ClusterState currentState, List<ShardRoutingEntry> tasks) throws Exception {
|
public BatchResult<ShardRoutingEntry> execute(ClusterState currentState, List<ShardRoutingEntry> tasks) throws Exception {
|
||||||
BatchResult.Builder<ShardRoutingEntry> builder = BatchResult.builder();
|
BatchResult.Builder<ShardRoutingEntry> builder = BatchResult.builder();
|
||||||
ClusterState accumulator = ClusterState.builder(currentState).build();
|
List<ShardRouting> shardRoutingsToBeApplied = new ArrayList<>(tasks.size());
|
||||||
for (ShardRoutingEntry task : tasks) {
|
for (ShardRoutingEntry task : tasks) {
|
||||||
task.processed = true;
|
task.processed = true;
|
||||||
try {
|
shardRoutingsToBeApplied.add(task.shardRouting);
|
||||||
RoutingAllocation.Result result =
|
}
|
||||||
allocationService.applyStartedShard(currentState, task.shardRouting, true);
|
ClusterState maybeUpdatedState = currentState;
|
||||||
builder.success(task);
|
try {
|
||||||
if (result.changed()) {
|
RoutingAllocation.Result result =
|
||||||
accumulator = ClusterState.builder(accumulator).routingResult(result).build();
|
allocationService.applyStartedShards(currentState, shardRoutingsToBeApplied, true);
|
||||||
}
|
if (result.changed()) {
|
||||||
} catch (Throwable t) {
|
maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
|
||||||
builder.failure(task, t);
|
|
||||||
}
|
}
|
||||||
|
builder.successes(tasks);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
builder.failures(tasks, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build(accumulator);
|
return builder.build(maybeUpdatedState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -63,22 +63,6 @@ public class AllocationService extends AbstractComponent {
|
||||||
this.clusterInfoService = clusterInfoService;
|
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.
|
* Applies the started shards. Note, shards can be called several times within this method.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
Loading…
Reference in New Issue