Skip to content

Fail PPL queries refused by a saturated SQL worker pool with 429 - #5915

Merged
penghuo merged 3 commits into
opensearch-project:mainfrom
penghuo:feat/5801-worker-pool-rejection
Oct 30, 2026
Merged

penghuo merged 3 commits into
opensearch-project:mainfrom
penghuo:feat/5801-worker-pool-rejection

Conversation

@penghuo

@penghuo penghuo commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Description

When the SQL worker thread pools were full, a new PPL query was dropped without an error. A normal query never got a response, and an async query showed RUNNING forever and was never cleaned up.

The query was handed to sql-worker and sql-complex-worker through ThreadPool.schedule with a zero delay. The pool's rejection then happened on the scheduler thread, so it never reached the query.

Now the query is handed to the pool directly, and a rejection fails the query right away with 429 "thread pool is saturated; retry later":

  • A normal query gets 429.
  • An async submit gets 429. If the query's id was already returned, GET reports it FAILED with the same error.

A rejection by sql-complex-worker is reported straight to the query, so it does not fall back to the V2 engine and run again on the same busy node.

Normal execution does not change: the query runs on the same pool, with the same thread context.

Related Issues

Part of #5801

Parent: #5765

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…nsearch-project#5801)

OpenSearchQueryManager and ThreadPoolExecutionDispatcher submitted work
with ThreadPool.schedule and a zero delay. When sql-worker or
sql-complex-worker was full, the rejection was raised on the scheduler
thread and never reached the query's listener: a sync query got no
response and an async query stayed RUNNING forever.

Submit to the executor directly and report the rejection as 429
"[pool] thread pool is saturated; retry later". A rejection on the
complex pool goes straight to the listener so it does not trigger the
V2 fallback.

Signed-off-by: Peng Huo <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Resource Leak

The test creates a 100,000-document index (SLOW_INDEX) in init() but never deletes it in cleanUp(). Each test run leaves this index behind, consuming cluster resources. If the test suite runs repeatedly (e.g., in CI), these indexes accumulate. Add index deletion to cleanUp() or use @AfterClass to remove SLOW_INDEX.

  super.init();
  enableCalcite();
  AsyncPPLTestHelpers.createIndex(client());
  AsyncPPLTestHelpers.createIndex(client(), SLOW_INDEX, 100_000);
}
Inconsistent Behavior

When failureListener is null and the complex pool rejects the task, the code throws WorkerPoolSaturatedException (line 136). However, when failureListener is non-null, it calls failureListener.onFailure(saturated) (line 138) but does not throw. This inconsistency means the caller's flow differs based on whether a listener was provided. If the caller expects an exception when no listener is given, it will not see one when a listener is present, potentially causing the caller to proceed as if dispatch succeeded.

try {
  // The executor runs the task in this thread's ThreadContext.
  threadPool.executor(SQL_COMPLEX_WORKER_THREAD_POOL_NAME).execute(complexTask);
} catch (OpenSearchRejectedExecutionException e) {
  WorkerPoolSaturatedException saturated =
      new WorkerPoolSaturatedException(SQL_COMPLEX_WORKER_THREAD_POOL_NAME);
  if (failureListener == null) {
    throw saturated;
  }
  failureListener.onFailure(saturated);
}

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Preserve original exception cause

The catch block discards the original exception's stack trace and context. Consider
passing the original exception as the cause to WorkerPoolSaturatedException to
preserve debugging information about where the rejection occurred in the thread pool
implementation.

opensearch/src/main/java/org/opensearch/sql/opensearch/executor/OpenSearchQueryManager.java [106-111]

 try {
   // The executor runs the task in this thread's ThreadContext.
   threadPool.executor(SQL_WORKER_THREAD_POOL_NAME).execute(wrappedTask);
 } catch (OpenSearchRejectedExecutionException e) {
-  throw new WorkerPoolSaturatedException(SQL_WORKER_THREAD_POOL_NAME);
+  throw new WorkerPoolSaturatedException(SQL_WORKER_THREAD_POOL_NAME, e);
 }
Suggestion importance[1-10]: 7

__

Why: Preserving the original exception as a cause improves debugging by maintaining the full stack trace. However, since WorkerPoolSaturatedException is designed to provide a user-facing message and the original exception details may not be critical for the retry-later scenario, the impact is moderate.

Medium
Add constructor with cause parameter

Add a constructor overload that accepts the original
OpenSearchRejectedExecutionException as a cause parameter. This allows callers to
preserve the full exception chain, which is critical for debugging thread pool
rejections in production environments.

opensearch/src/main/java/org/opensearch/sql/opensearch/executor/WorkerPoolSaturatedException.java [20-22]

 public WorkerPoolSaturatedException(String poolName) {
   super(String.format(Locale.ROOT, "[%s] thread pool is saturated; retry later", poolName));
 }
 
+public WorkerPoolSaturatedException(String poolName, Throwable cause) {
+  super(String.format(Locale.ROOT, "[%s] thread pool is saturated; retry later", poolName), cause);
+}
+
Suggestion importance[1-10]: 7

__

Why: Adding a constructor overload to accept a Throwable cause enables better exception chaining and debugging. This is a good practice for custom exceptions, though not critical since the current implementation already provides a clear message about the saturation issue.

Medium

@penghuo penghuo added the PPL Piped processing language label Oct 28, 2026
@penghuo penghuo self-assigned this Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.37%. Comparing base (24bfaaf) to head (b1f16d5).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5915      +/-   ##
============================================
- Coverage     75.38%   75.37%   -0.01%     
- Complexity    10386    10387       +1     
============================================
  Files           962      963       +1     
  Lines         41089    41103      +14     
  Branches       4681     4683       +2     
============================================
+ Hits          30975    30983       +8     
- Misses         8806     8812       +6     
  Partials       1308     1308              
Flag Coverage Δ
sql-engine 75.37% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@penghuo penghuo added the enhancement New feature or request label Oct 28, 2026
@penghuo
penghuo merged commit f08c81a into opensearch-project:main Oct 30, 2026
52 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PPL Piped processing language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants