Skip to content

[Feature][PPL] Production hardening and validation for progressive query execution #5801

Open

Description

@penghuo

Parent: #5765

Goal

Turn the validated asynchronous and partial-result prototypes into a production-quality implementation with explicit module boundaries, bounded resource use, and complete regression coverage.

Scope

  • Keep ProgressiveQueryExecution as the only lifecycle-facing execution contract.
  • Remove PoC-only routing and physical-plan hooks in favor of explicit production integration seams.
  • Keep execution callback, Context, StateStore, and aggregation observer details out of the lifecycle layer.
  • Define memory limits and failure behavior for APPEND and REPLACE state.
  • Make partial-reduce cadence configurable and bounded.
  • Validate cleanup, owner-node loss, FGAC, cancellation, expiration, and shutdown.
  • Document supported partial-result shapes and progress semantics.

Acceptance criteria

  • No synchronous behavior or performance regression outside the accepted threshold.
  • All existing Calcite integration tests and YAML REST tests pass.
  • A REST matrix covers non-blocking rows, Composite aggregation, fully pushed aggregation, pushed aggregation with Calcite post-processing, blocking plans, and failure cases.
  • Every final async result is equivalent to the synchronous result.
  • First-data and final latency, memory usage, and aggregation reduce overhead are reported on a multi-shard large dataset.
  • Resource cleanup and lifecycle race tests show no leaked tasks, search contexts, statements, or StateStores.

Activity

  1. added
    enhancement
    PPL
    testing
    calcite
    on Sep 23, 2026
  2. penghuo commented on Oct 6, 2026

    @penghuo
    CollaboratorAuthor

    Enhancement: PENDING status + max-lifetime backstop for async PPL jobs

    Context from PR #5832: an async PPL submission with wait_for_completion_timeout=0 can leak a RUNNING job on the owner node if the engine never completes the runner's CompletableFuture. Retention is only armed on terminal transitions, so a stuck future never gets evicted.

    plugins.ppl.query.timeout (default 300s) catches the common case via Thread.interrupt() on the engine thread (confirmed in AsyncPPLQueryLifecycleIT.async_perNodeTimeoutDrivesJobToFailedWithSyncShapeError — timeout fires at the first interruptible blocking call, async GET reaches FAILED with the sync-shape error body).

    The interrupt is cooperative, so it does not cover:

    1. Worker-pool saturation. sql-worker pool full → task silently dropped or indefinitely queued → runner never starts → interrupt is never scheduled.
    2. CPU-bound sections without interrupt checks (Calcite planner passes, pure Java eval loops).
    3. Swallowed InterruptedException in third-party or legacy code.
    4. Lost completion signal — any dispatcher bug that drops onResponse / onFailure keeps the CompletableFuture pending forever.

    Proposed work

    1. Expose PENDING on GET (preferred over admission-control rejection).

    The lifecycle state machine already has PENDING as the state between construction and startRunner(), but today OpenSearchQueryJobService.submit calls startRunner() immediately after publishing, so clients never see it.

    Mirror Livy's waiting → running model: when the sql-worker pool can't accept the task yet, keep the job in PENDING and let the engine thread notify via a new onStarted callback on QueryRunner when it actually begins work. GET returns {"status":"PENDING"} until that happens, then {"status":"RUNNING"}.

    Why this is better than returning 429 and rejecting:

    • No work is dropped — the client always gets a durable job id and can keep polling.
    • Natural backpressure: pressure manifests as PENDING tail length, not failure.
    • Decouples admission from scheduling; the worker pool runs at full utilization.
    • Matches a well-known REST analytics protocol (Livy), so clients built against Livy semantics port cleanly.

    2. Submit-time max-lifetime timer (backstop).

    Schedule a hard timeout in QueryJobService.submit (not inside the runner body) on ThreadPool.Names.GENERIC using the plugins.ppl.query.timeout budget. Fire → move the job to FAILED with reason "query timed out after Xs" and let retention evict after keep_alive. Cancel on terminal transition. Covers hangs from any of (2)-(4) above and from (1) when PENDING outlives the budget.

    3. Observability.

    Metric for terminal transitions bucketed by trigger: cooperative interrupt vs. backstop timer vs. explicit cancel. Tells us whether the backstop is doing real work.

    Reproduction

    • Set the sql-worker pool to 1 slot; submit two long-running queries back-to-back with wait_for_completion_timeout=0. Without PENDING exposure, the second id returns RUNNING forever.

    Credit: this scenario and the "lifetime timer at submit" shape were raised by akhcs on PR #5832 review.

  3. penghuo commented on Oct 7, 2026

    @penghuo
    CollaboratorAuthor

    Track async PPL GET/DELETE transport compatibility during rolling upgrades as part of this production-hardening issue, deferred from #5846.

    CancelAsyncQueryActionRequest and GetAsyncQueryResultActionRequest read/write queryId with readOptionalString / writeOptionalString, without a wire-version gate. Older decoders read only the superclass fields. Frame-level probes reproduced unread trailing bytes for a new writer with an older reader, and EOF for an older writer with a new reader. Owner forwarding therefore needs a defined compatibility contract. GET serialization and the shared owner-routing helper were introduced in #5832; #5846 adds DELETE owner forwarding.

    OpenSearch version checks alone cannot distinguish different SQL plugin builds targeting the same OpenSearch version. The solution must account for that case through capability negotiation or an explicitly unsupported upgrade combination.

    Suggested acceptance criteria:

    • Define and document supported mixed-version and mixed-plugin-build behavior for async PPL GET/DELETE, including owner restart and loss of in-memory jobs.
    • Negotiate a compatible request format or reject unsupported owner forwarding clearly before sending an incompatible frame; do not silently lose the query ID.
    • Cover old-to-new and new-to-old serialization, complete frame consumption, owner forwarding, and unsupported combinations with regression tests.

    At the author's request, the proposed compatibility gates, old-owner rejection, compatibility tests, and upgrade documentation are being removed from the uncommitted #5846 follow-up. This concern is intentionally deferred to #5801; the cancellation/fallback fixes remain in #5846.

  4. penghuo commented on Oct 13, 2026

    @penghuo
    CollaboratorAuthor

    Related to #5849

  5. 2 remaining items

  6. penghuo commented on Oct 27, 2026

    @penghuo
    CollaboratorAuthor

    Async PPL GET waits behind queued queries on sql-worker

    GET /_plugins/_async_query/{id} for a PPL job runs on the sql-worker pool (RestAsyncQueryManagementAction schedules it with Scheduler.schedule, whose default pool is sql-worker). DELETE for PPL ids already runs on GENERIC.

    When sql-worker is busy with queries, a poll waits in the same queue behind them. On a 2-node cluster (sql-worker size 8, queue 1000) with about 1,100 async queries submitted at once, GET calls took more than 30 seconds to return. A client that polls with a short timeout sees its poll fail even though the job is fine.

    If the pool's queue is full, the rejection of the GET task is dropped inside ThreadPool.schedule, so the GET request gets no response at all. This is the same pattern as the query hand-off that dropped rejections.

    Suggested fix: run GET for PPL ids on GENERIC, as DELETE does. It only looks up the job and formats the stored result. Also submit it through the executor rather than ThreadPool.schedule, so a rejection reaches the client as an error.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    PPLasynccalciteenhancementtesting

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions