Skip to content

Commit 8a040a2

Browse files
committed
Clear the per-request partial-result state after each query
The partial-result override and the warnings-supported flag live in QueryContext's log4j thread-locals, but only QueryProfiling was being cleared when a request finished. Transport threads are pooled, so a query that expressed no preference inherited the previous query's override from the same thread: with the cluster setting off and no request flag, an aggregation over a text/keyword conflict intermittently returned a partial result (with a warning) instead of failing -- observed 7 of 12 runs after an earlier request had set the flag. Clear both flags alongside QueryProfiling in the response listener. Verified: flag-absent requests now fail 12/12 when interleaved with explicit true requests, while explicit true still returns the partial result. Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent 44e0eaa commit 8a040a2

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public void onResponse(TransportPPLQueryResponse transportPPLQueryResponse) {
385385
try {
386386
delegate.onResponse(transportPPLQueryResponse);
387387
} finally {
388-
QueryProfiling.clear();
388+
clearRequestScopedState();
389389
}
390390
}
391391

@@ -394,9 +394,21 @@ public void onFailure(Exception e) {
394394
try {
395395
delegate.onFailure(e);
396396
} finally {
397-
QueryProfiling.clear();
397+
clearRequestScopedState();
398398
}
399399
}
400400
};
401401
}
402+
403+
/**
404+
* Clear the per-request state carried in {@link QueryContext}'s thread-locals. Transport threads
405+
* are pooled, so anything left behind is inherited by the next query to run on this thread -- a
406+
* request that expressed no partial-result preference would otherwise pick up the previous
407+
* request's override.
408+
*/
409+
private static void clearRequestScopedState() {
410+
QueryProfiling.clear();
411+
QueryContext.setPartialResultOverride(null);
412+
QueryContext.setWarningsSupported(false);
413+
}
402414
}

0 commit comments

Comments
 (0)