Skip to content

Commit 503f13e

Browse files
committed
update remaining nodes under the lock
1 parent b8b4a95 commit 503f13e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeRequestSender.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ void onAfter(List<DriverProfile> profiles) {
262262
if (pendingRetries.isEmpty() == false && remainingTargetShardSearchAttempts.getAndDecrement() > 0) {
263263
ongoingTargetShardResolutionAttempts.incrementAndGet();
264264
resolveShards(pendingRetries, computeListener.acquireAvoid().delegateFailure((l, resolutions) -> {
265-
for (var entry : resolutions.entrySet()) {
266-
targetShards.shards.get(entry.getKey()).remainingNodes.addAll(entry.getValue());
267-
}
265+
addRemainingNodes(targetShards, resolutions);
268266
ongoingTargetShardResolutionAttempts.decrementAndGet();
269267
trySendingRequestsForPendingShards(targetShards, computeListener);
270268
l.onResponse(null);
@@ -357,6 +355,17 @@ private void trackShardLevelFailure(ShardId shardId, boolean fatal, Exception or
357355
});
358356
}
359357

358+
private void addRemainingNodes(TargetShards targetShards, Map<ShardId, List<DiscoveryNode>> resolutions) {
359+
sendingLock.lock();
360+
try {
361+
for (var entry : resolutions.entrySet()) {
362+
targetShards.shards.get(entry.getKey()).remainingNodes.addAll(entry.getValue());
363+
}
364+
} finally {
365+
sendingLock.unlock();
366+
}
367+
}
368+
360369
/**
361370
* Result from {@link #searchShards(Set, ActionListener)} where can_match is performed to
362371
* determine what shards can be skipped and which target nodes are needed for running the ES|QL query
@@ -467,7 +476,7 @@ void searchShards(Set<String> concreteIndices, ActionListener<TargetShards> list
467476
skippedShards++;
468477
continue;
469478
}
470-
List<DiscoveryNode> allocatedNodes = Collections.synchronizedList(new ArrayList<>(group.allocatedNodes().size()));
479+
List<DiscoveryNode> allocatedNodes = new ArrayList<>(group.allocatedNodes().size());
471480
for (String n : group.allocatedNodes()) {
472481
allocatedNodes.add(nodes.get(n));
473482
}

0 commit comments

Comments
 (0)