Skip to content

[FEATURE] Add PPL asynchronous query API - #7

Open
penghuo wants to merge 28 commits into
mainfrom
feat/asyncquery-api
Open

penghuo wants to merge 28 commits into
mainfrom
feat/asyncquery-api

Conversation

@penghuo

@penghuo penghuo commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Description

This is the first API implementation PR for asynchronous PPL queries, tracked by opensearch-project/sql#5765 and opensearch-project/sql#5796.

It keeps synchronous POST /_plugins/_ppl backward compatible and adds:

  • Async submit with wait_for_completion_timeout and keep_alive.
  • GET for the complete current snapshot and optional lease renewal.
  • DELETE for cancellation and cleanup.
  • Opaque job IDs, owner-node routing, FGAC reauthorization, expiration, and capacity limits.

This PR is final-result-only. It does not expose progress, partial results, paging, or delta delivery. Results remain limited by plugins.query.size_limit. Retained-result byte accounting is follow-up opensearch-project/sql#5804.

A failure before the submit wait expires returns the same HTTP error as synchronous PPL and retains no job. A retained failure is returned by GET as 200 with status: FAILED and the query error.

Lifecycle/execution contract

public interface AsyncQueryExecution extends AutoCloseable {
    Optional<QueryResponse> currentResult();
    CompletionStage<Void> completion();
    void close();
}

PPLAsyncQueryService depends only on this contract. A successful final result must be visible through currentResult() before completion() completes normally.

sequenceDiagram
    participant C as Client
    participant T as TransportPPLQueryAction
    participant L as PPLAsyncQueryService
    participant J as PPLAsyncQueryJob
    participant E as AsyncQueryExecution

    C->>T: POST query
    T->>L: start
    L->>J: create RUNNING job
    L->>E: start and attach
    alt completion before wait deadline
        E-->>L: completion
        L->>J: complete or fail
        L->>E: currentResult on success
        L-->>C: final result or HTTP error; no ID
        L->>E: close
    else wait deadline first
        L->>J: retain
        L-->>C: RUNNING with opaque ID
        C->>L: owner-routed, authorized GET
        L->>E: currentResult
        L-->>C: complete current snapshot
    end
Loading

Core classes

Class Responsibility
AsyncQueryExecution Lifecycle/execution ownership boundary.
DefaultAsyncQueryExecution Final-only execution adapter.
PPLAsyncQueryService Registry, policy, task ownership, and side effects.
PPLAsyncQueryJob Synchronized state machine for one query.
PPLAsyncQueryUser Captures callers and compares them with the stored job owner.
TransportPPLAsyncQueryRoutingAction Owner-node GET/DELETE routing.

Result materialization occurs outside the job lock and GET dispatches it to the SQL worker pool. plugins.ppl.enabled=false rejects submit, GET, and DELETE. plugins.ppl.query.timeout still limits execution; keep_alive controls retention only.

Validation

Added lifecycle, authorization, request-validation, failure-metric, lease, and targeted REST integration tests. New ITs were run with -DignorePrometheus.

Related Issues

  • Implements opensearch-project/sql#5796.
  • Part of opensearch-project/sql#5765.
  • Follow-up: opensearch-project/sql#5804.

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has Javadoc added.
  • Commits are signed per the DCO using --signoff.
  • API specification companion PR.
  • Public documentation issue/PR.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@penghuo
penghuo requested a review from dai-chen as a code owner September 22, 2026 15:37
Comment thread docs/user/ppl/interfaces/async-query.md Resolved
Comment thread docs/user/ppl/admin/settings.md Resolved
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
@penghuo

penghuo commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner Author

Addressed the follow-up review in 980a94a62 and 1fff6754d:

  1. Fast async failures now preserve synchronous HTTP status/message; retained failures preserve the useful error and record the failure metric once.
  2. Owner isolation uses the existing request identity integration: submit stores the caller, and GET/DELETE compare the current caller with that stored owner. A missing identity represents an unsecured caller; no separate Security plugin detection is added.
  3. Retained-result byte accounting is intentionally deferred to [PPL] Limit retained jobs and retained-result bytes for asynchronous queries opensearch-project/sql#5804.
  4. GET renews the lease only when keep_alive is supplied.
  5. GET result materialization/formatting runs on the SQL worker pool.
  6. Documentation now states that plugins.ppl.query.timeout limits execution while keep_alive controls retention only.
  7. plugins.ppl.enabled=false rejects POST, GET, and DELETE.
  8. Non-string lifecycle fields return HTTP 400.

Added focused unit and REST IT coverage. The new IT methods were run with -DignorePrometheus; Full IT was not run.

Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
@penghuo

penghuo commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

Follow-up simplification is in 808eec6fd:

  • plugins.ppl.enabled is checked at the transport boundary; start/get/delete no longer repeat it.
  • PPLAsyncQueryUser uses the principal presence directly and removes the separate securityEnabled state.
  • GET selects the SQL worker through HandledTransportAction instead of manually dispatching.
  • Direct failure handling no longer passes a nullable control parameter through applyTransition.
  • The unused defensive metric null check is removed.
  • PPLAsyncQueryService and PPLAsyncQueryJobId Javadocs now describe ownership, concurrency, POST race behavior, ID layout, routing, and authorization.

Validation: 36 focused unit tests and 4 focused REST ITs passed; ITs used -DignorePrometheus. Full IT was not run.

Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant