diff --git a/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java b/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java index b4048407841..a74b2ca5ed8 100644 --- a/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java +++ b/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java @@ -199,22 +199,24 @@ public class ShardStateAction extends AbstractComponent { @Override public BatchResult execute(ClusterState currentState, List tasks) throws Exception { BatchResult.Builder builder = BatchResult.builder(); - ClusterState accumulator = ClusterState.builder(currentState).build(); + List 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 diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java index af17c839582..f819d6fde0a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java @@ -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. *