Skip to content

[BugFix] Keep PPLQueryTask free of opensearch module types (fixes alerting crash) - #5924

Merged
ahkcs merged 1 commit into
opensearch-project:mainfrom
ahkcs:fix/5923-ppl-task-thin-jar
Nov 2, 2026
Merged

ahkcs merged 1 commit into
opensearch-project:mainfrom
ahkcs:fix/5923-ppl-task-thin-jar

Conversation

@ahkcs

@ahkcs ahkcs commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes a node crash in 3.10.0. Any PPL alerting monitor throws NoClassDefFoundError: org/opensearch/sql/opensearch/executor/progress/ProgressTrackingTask, and because it is an Error the node exits (#5923).

Cause: #5910 made PPLQueryTask implement ProgressTrackingTask, which lives in the opensearch module. Alerting (and skills) call PPLQueryAction with an opensearch-sql-thin jar built from this plugin's classes plus the core, ppl, and protocol jars. That jar does not include the opensearch module, so the JVM cannot define PPLQueryTask.

Fix:

  • PPLQueryTask is reverted to its pre-[Feature][PPL] Report progress for asynchronous Calcite queries #5910 form, with no interface and no tracker field.
  • ProgressTrackingTask is removed.
  • QueryProgressTracker.attach(task) keeps each async query's tracker in a weak map keyed by its task (identity: Task does not override equals). QueryProgressTracker.current() looks it up through the task already set on the thread. Only TransportPPLQueryAction calls attach, and it runs in this plugin's own classloader.
  • Progress behavior is unchanged.

Guard: ThinJarClassesTest fails if PPLQueryAction, TransportPPLQueryRequest, TransportPPLQueryResponse, or PPLQueryTask (the classes other plugins load) reference a type from org.opensearch.sql.opensearch through a superclass, interface, field, method, or constructor. With the old PPLQueryTask restored, it fails and names ProgressTrackingTask and QueryProgressTracker.

Verification

Check Before (main) After
Load PPLQueryTask from a classloader with the plugin jar, core, and OpenSearch, but not the opensearch module (the alerting setup) NoClassDefFoundError: ProgressTrackingTask loads
javap PPLQueryTask extends CancellableTask implements ProgressTrackingTask extends CancellableTask
ThinJarClassesTest fails passes
AsyncPPLProgressIT (progress still reported mid-query) 6 / 6 6 / 6
AsyncPPLQueryLifecycleIT — 25 / 25
:opensearch:check, :opensearch-sql-plugin:check — pass

End-to-end reproduction

The steps from #5923 were run on a single node: the 3.10.0-SNAPSHOT darwin distribution, plus job-scheduler, SQL, and alerting from staging build 12327 (sql 760eead1e, alerting c17572ecb).

Step Staging plugins SQL from this PR; alerting's bundled opensearch-sql-thin/core/ppl/protocol rebuilt from it the way alerting builds them
Plain PPL stats count() [[1]] [[1]]
Create ppl_monitor no response; node exits with fatal error ... NoClassDefFoundError: .../ProgressTrackingTask created
_execute the monitor (node down) triggered: true, trigger ppl_query_results: [{"cnt":1}] (same as 3.9.0)
Enabled monitor on its 1-minute schedule (node down) runs, raises an ACTIVE alert with no error
Node after the run down up; no fatal error or NoClassDefFoundError in the logs

Alerting needs a rebuild against the new SQL snapshot to pick up the fixed thin jar; no alerting code change is needed.

Related Issues

Resolves #5923

Check List

  • New functionality includes testing.
  • New functionality has been documented. N/A
  • New PPL command checklist all confirmed. N/A
  • 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.

opensearch-project#5910 made PPLQueryTask implement ProgressTrackingTask from the
opensearch module. Plugins such as alerting load PPLQueryTask with this
plugin's classes plus core, ppl, and protocol, but not the opensearch
module, so creating the task threw NoClassDefFoundError and crashed the
node.

Revert PPLQueryTask, drop ProgressTrackingTask, and keep each async
query's tracker in a weak map keyed by its task. Add a test that the
classes other plugins load reference no opensearch module types.

Resolves opensearch-project#5923

Signed-off-by: Kai Huang <[email protected]>
@github-actions

github-actions Bot commented Nov 2, 2026

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

Memory Leak

The static TRACKERS WeakHashMap uses tasks as keys. If a task is stored in a long-lived collection elsewhere or referenced by a thread that outlives the query, the WeakHashMap entry persists indefinitely. This can accumulate trackers in memory, especially under high query load or when tasks are inadvertently retained.

private static final Map<CancellableTask, QueryProgressTracker> TRACKERS =
    Collections.synchronizedMap(new WeakHashMap<>());
Race Condition

attach and current access TRACKERS without external synchronization. If attach runs concurrently with current on the same task, current may return empty even after attach completes, because Collections.synchronizedMap only synchronizes individual operations, not the sequence of put followed by get across threads.

public static QueryProgressTracker attach(CancellableTask task) {
  QueryProgressTracker tracker = new QueryProgressTracker();
  TRACKERS.put(task, tracker);
  return tracker;
}

public static Optional<QueryProgressTracker> current() {
  CancellableTask task = OpenSearchQueryManager.getCancellableTask();
  return task == null ? Optional.empty() : Optional.ofNullable(TRACKERS.get(task));
}

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Prevent duplicate tracker attachments

The attach method doesn't handle the case where a tracker is already attached to the
task. This could lead to silently overwriting existing trackers and losing progress
data. Add a check to prevent duplicate attachments or document the expected
behavior.

opensearch/src/main/java/org/opensearch/sql/opensearch/executor/progress/QueryProgressTracker.java [30-34]

 public static QueryProgressTracker attach(CancellableTask task) {
   QueryProgressTracker tracker = new QueryProgressTracker();
-  TRACKERS.put(task, tracker);
-  return tracker;
+  QueryProgressTracker existing = TRACKERS.putIfAbsent(task, tracker);
+  return existing != null ? existing : tracker;
 }
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly identifies that attach could overwrite existing trackers. Using putIfAbsent is a reasonable improvement to prevent data loss, though the impact depends on whether duplicate attachments are expected in practice.

Low
Possible issue
Fix potential race condition

Using WeakHashMap with synchronizedMap can lead to race conditions during garbage
collection. The weak references may be cleared between checking for existence and
retrieving values. Consider using ConcurrentHashMap with manual cleanup or a
dedicated cache library for thread-safe weak reference handling.

opensearch/src/main/java/org/opensearch/sql/opensearch/executor/progress/QueryProgressTracker.java [24-25]

 private static final Map<CancellableTask, QueryProgressTracker> TRACKERS =
-    Collections.synchronizedMap(new WeakHashMap<>());
+    new ConcurrentHashMap<>();
Suggestion importance[1-10]: 3

__

Why: While the concern about WeakHashMap with synchronizedMap is valid in theory, the suggested ConcurrentHashMap change removes the weak reference behavior entirely, which may be intentional for automatic cleanup. The suggestion doesn't preserve the original design intent and may introduce memory leaks.

Low

@ahkcs ahkcs added the bugFix label Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.52%. Comparing base (07b80d7) to head (f163dc0).

❌ Your project check has failed because the head coverage (75.52%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5924   +/-   ##
=========================================
  Coverage     75.52%   75.52%           
- Complexity    10440    10442    +2     
=========================================
  Files           969      969           
  Lines         41314    41318    +4     
  Branches       4711     4712    +1     
=========================================
+ Hits          31201    31205    +4     
  Misses         8788     8788           
  Partials       1325     1325           
Flag Coverage Δ
sql-engine 75.52% <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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] PPL alerting monitors crash the node on 3.10.0: NoClassDefFoundError ProgressTrackingTask (regression from #5910)

3 participants