From df26535cfcd3bbe8e35acbc053430b16916d1382 Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 6 Sep 2023 09:30:20 +0100 Subject: [PATCH 1/2] Fork response-sending in OpenPointInTimeAction Creating the response after opening a PIT involves O(#shards) work and has been observed to block transport worker threads which disrupts the cluster. This commit forks this work onto a more appropriate thread. --- .../TransportOpenPointInTimeAction.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java index 07fed9598ea8b..9c78e5ad62aea 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java @@ -21,7 +21,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.util.concurrent.AtomicArray; +import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.search.SearchPhaseResult; @@ -167,10 +167,29 @@ protected void executePhaseOnShard( @Override protected SearchPhase getNextPhase(SearchPhaseResults results, SearchPhaseContext context) { return new SearchPhase(getName()) { + + private void onExecuteFailure(Exception e) { + onPhaseFailure(this, "sending response failed", e); + } + @Override public void run() { - final AtomicArray atomicArray = results.getAtomicArray(); - sendSearchResponse(InternalSearchResponse.EMPTY_WITH_TOTAL_HITS, atomicArray); + execute(new AbstractRunnable() { + @Override + public void onFailure(Exception e) { + onExecuteFailure(e); + } + + @Override + protected void doRun() { + sendSearchResponse(InternalSearchResponse.EMPTY_WITH_TOTAL_HITS, results.getAtomicArray()); + } + + @Override + public boolean isForceExecution() { + return true; // we already created the PIT, no sense in rejecting the task that sends the response. + } + }); } }; } From b256d5a97ce5af1563b7439d8e34f7774cb0b280 Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 6 Sep 2023 09:34:36 +0100 Subject: [PATCH 2/2] Update docs/changelog/99222.yaml --- docs/changelog/99222.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/99222.yaml diff --git a/docs/changelog/99222.yaml b/docs/changelog/99222.yaml new file mode 100644 index 0000000000000..025c5e01d2a53 --- /dev/null +++ b/docs/changelog/99222.yaml @@ -0,0 +1,5 @@ +pr: 99222 +summary: Fork response-sending in `OpenPointInTimeAction` +area: Search +type: bug +issues: []