Skip to content

Commit 418a63f

Browse files
committed
Clarify tasks needing allocation service
This commit renames a variable in ShardFailedClusterStateTaskExecutor#execute in that it contains the tasks that need the allocation service to be processed.
1 parent b08c328 commit 418a63f

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import java.util.List;
6666
import java.util.Locale;
6767
import java.util.Set;
68+
import java.util.stream.Collectors;
6869

6970
import static org.elasticsearch.cluster.routing.ShardRouting.readShardRoutingEntry;
7071

@@ -227,34 +228,38 @@ public ShardFailedClusterStateTaskExecutor(AllocationService allocationService,
227228
@Override
228229
public BatchResult<ShardRoutingEntry> execute(ClusterState currentState, List<ShardRoutingEntry> tasks) throws Exception {
229230
BatchResult.Builder<ShardRoutingEntry> batchResultBuilder = BatchResult.builder();
230-
Set<ShardRoutingEntry> nonTrivialTasks = Collections.newSetFromMap(new IdentityHashMap<>());
231-
List<FailedRerouteAllocation.FailedShard> failedShards = new ArrayList<>(tasks.size());
231+
Set<ShardRoutingEntry> tasksRequiringAllocationService = Collections.newSetFromMap(new IdentityHashMap<>());
232+
232233
for (ShardRoutingEntry task : tasks) {
233234
RoutingNodes.RoutingNodeIterator routingNodeIterator =
234235
currentState.getRoutingNodes().routingNodeIter(task.getShardRouting().currentNodeId());
235236
if (routingNodeIterator != null) {
236237
for (ShardRouting maybe : routingNodeIterator) {
237238
if (task.getShardRouting().isSameAllocation(maybe)) {
238-
nonTrivialTasks.add(task);
239-
failedShards.add(new FailedRerouteAllocation.FailedShard(task.shardRouting, task.message, task.failure));
239+
tasksRequiringAllocationService.add(task);
240240
break;
241241
}
242242
}
243243
}
244-
if (!nonTrivialTasks.contains(task)) {
244+
if (!tasksRequiringAllocationService.contains(task)) {
245245
// the requested shard does not exist
246246
batchResultBuilder.success(task);
247247
}
248248
}
249249
ClusterState maybeUpdatedState = currentState;
250250
try {
251+
List<FailedRerouteAllocation.FailedShard> failedShards =
252+
tasksRequiringAllocationService
253+
.stream()
254+
.map(task -> new FailedRerouteAllocation.FailedShard(task.shardRouting, task.message, task.failure))
255+
.collect(Collectors.toList());
251256
RoutingAllocation.Result result = allocationService.applyFailedShards(currentState, failedShards);
252257
if (result.changed()) {
253258
maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
254259
}
255-
batchResultBuilder.successes(nonTrivialTasks);
260+
batchResultBuilder.successes(tasksRequiringAllocationService);
256261
} catch (Throwable t) {
257-
batchResultBuilder.failures(nonTrivialTasks, t);
262+
batchResultBuilder.failures(tasksRequiringAllocationService, t);
258263
}
259264
return batchResultBuilder.build(maybeUpdatedState);
260265
}

0 commit comments

Comments
 (0)