From 85262a15eb0951bad5645499fe15be07ba30e933 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Tue, 20 May 2025 13:58:53 -0700 Subject: [PATCH 1/2] Prevent closing wrong search contexts in compute service --- muted-tests.yml | 3 --- .../xpack/esql/plugin/DataNodeComputeHandler.java | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 3c93e77514925..94529c82c42a1 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -393,9 +393,6 @@ tests: - class: org.elasticsearch.packaging.test.DockerTests method: test026InstallBundledRepositoryPluginsViaConfigFile issue: https://github.com/elastic/elasticsearch/issues/127158 -- class: org.elasticsearch.xpack.esql.plugin.DataNodeRequestSenderIT - method: testSearchWhileRelocating - issue: https://github.com/elastic/elasticsearch/issues/127188 - class: org.elasticsearch.xpack.remotecluster.CrossClusterEsqlRCS2EnrichUnavailableRemotesIT method: testEsqlEnrichWithSkipUnavailable issue: https://github.com/elastic/elasticsearch/issues/127368 diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java index e423cd43f8f9b..92ebe5711c503 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java @@ -328,8 +328,8 @@ private void acquireSearchContexts( } final var doAcquire = ActionRunnable.supply(listener, () -> { final List searchContexts = new ArrayList<>(targetShards.size()); - SearchContext context = null; for (IndexShard shard : targetShards) { + SearchContext context = null; try { var aliasFilter = aliasFilters.getOrDefault(shard.shardId().getIndex(), AliasFilter.EMPTY); var shardRequest = new ShardSearchRequest( @@ -342,15 +342,16 @@ private void acquireSearchContexts( // we need to limit the number of active search contexts here or in SearchService context = searchService.createSearchContext(shardRequest, SearchService.NO_TIMEOUT); context.preProcess(); - searchContexts.add(context); } catch (Exception e) { if (addShardLevelFailure(shard.shardId(), e)) { IOUtils.close(context); + continue; } else { IOUtils.closeWhileHandlingException(context, () -> IOUtils.close(searchContexts)); throw e; } } + searchContexts.add(context); } return searchContexts; }); From 6a8994700a678330dfa7dfd672d0e2417da81152 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 21 May 2025 09:25:17 -0700 Subject: [PATCH 2/2] smaller --- .../xpack/esql/plugin/DataNodeComputeHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java index 92ebe5711c503..de431fdb8929e 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java @@ -342,16 +342,15 @@ private void acquireSearchContexts( // we need to limit the number of active search contexts here or in SearchService context = searchService.createSearchContext(shardRequest, SearchService.NO_TIMEOUT); context.preProcess(); + searchContexts.add(context); } catch (Exception e) { if (addShardLevelFailure(shard.shardId(), e)) { IOUtils.close(context); - continue; } else { IOUtils.closeWhileHandlingException(context, () -> IOUtils.close(searchContexts)); throw e; } } - searchContexts.add(context); } return searchContexts; });