Skip to content

fix(task): preserve SQL task execution ownership - #32331

Merged
XuPeng-SH merged 24 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/sql-task-ownership-32279
Nov 11, 2026
Merged

XuPeng-SH merged 24 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/sql-task-ownership-32279

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #32279
Fixes #32280
Fixes #32281

Part of #32278.

What this PR does / why we need it:

A SQL task that was still executing could lose exclusion after 24 hours. Delayed repair could then change a later run, while separate commits for an async firing and its run result could leave inconsistent metadata.

  • Bind admission, retries and completion to the exact firing, run, runner and epoch. Preserve exclusion across DROP/recreation, atomically publish run/firing outcomes, and reconcile uncertain commits before an executor retries SQL.
  • Keep known outcomes in bounded, service-owned metadata receipts; recovery publishes metadata without replaying business SQL. A runner stopped before an executor wrapper claims a firing leaves that firing available for recovery instead of marking it failed.
  • Keep the parent admission guard, but group same-parent firings within a fetched batch and reconsider held work through bounded hints and fair scans. Re-enter fair scanning when a local LIMIT prefix or a post-LIMIT decorator can hide work. The raw scan reads lightweight headers and rechecks possible matches through the existing decorated query path. Validate normal results against runner and status, deduplicate at enqueue, and retain recovery and deadline causes when a fetch is interrupted.
  • Add runner_cn to SHOW TASK RUNS and ALTER TASK ... RESET RUNS <run_id> FORCE for explicitly reconciled unknown runs. Keep SQL task catalog upgrades under the existing pending 4.0.7 owner.

The design describes ownership, bounded recovery, scheduling and limitations. The original implementation predates the local design review; the subsequent cancellation and fetch corrections were designed before implementation.

Scheduler and ALTER: SUSPEND and SET SCHEDULE advance the invalidation sequence atomically from the persisted task counters. A scheduled firing committed after the definition was read no longer causes an unnecessary ALTER conflict; the original task identity and schedule generation still guard against replacement and competing definition changes.

Compatibility and recovery: Stop all old services, including partitioned CNs/TNs, before upgrading. SHOW TASK RUNS adds a column; custom Go TaskService and TaskStorage implementations must implement the new methods, provide canonical unfiltered scan headers, and preserve uncertain metadata-commit outcomes. In-memory receipts are not crash-durable: process loss or an extended outage can leave a RUNNING barrier needing operator reconciliation. FORCE does not stop an executor or undo effects; isolate the old executor and reconcile effects before using it. Manual execution retains the existing synchronous client-disconnect and request-deadline behavior; zero task timeout remains unlimited across statements.

Validation:

  • Go 1.27.1, linux/amd64, verified CPU native libraries: full taskservice normal and race tests, with 10 race repetitions of same-parent bursts, a long SQL body and overlapping firing, late allocation behind a post-LIMIT decorator, and the wake budget. Frontend, transaction client, scheduler, parser and bootstrap owner packages and the released-catalog upgrade fixture passed race checks on the rebased main; directly affected CN, logservice and TN consumers were rechecked after the fetch API change. Incremental gofmt, vet, pinned molint and configured golangci-lint passed.
  • A real two-CN race test exercised exact ownership, DROP/recreation, retry and FORCE, with injected pre-commit failure and an error returned after a real metadata COMMIT. The latter simulates a lost acknowledgement at the wrapper boundary, not a network disconnect. A separate client-disconnect control completed an admitted task once.
  • On the previous candidate (6cae8ff), a real v4.2.8 binary created a task and successful history, stopped cleanly, and that candidate upgraded the same data to 4.0.7; the final follow-up only changes timeout diagnostics. History survived, one explicit execution succeeded, and restart did not replay it. A current-engine released-catalog fixture separately covers retained RUNNING history, partial DDL and idempotence; the old-binary fixture only contained SUCCESS history.
  • The task SQL BVT ran twice against the same isolated instance: 155/155 statements passed per run, with cleanup checked between runs.
  • The previous CI head failed during Go, Java or CMake setup with HTTP 504, timeout or TLS errors; coverage aggregation lacked the resulting profile. CI for the new head is queued/in progress.

Local performance and limits: On a disk-backed single-CN fixture, current main / this PR / this PR / main each ran 100 manual calls and collected 30 scheduled SUCCESS publications, with ~50 QPS unrelated SQL. Manual p95 was 29.54 / 28.27 / 28.27 / 30.81 ms (throughput 30.92 / 19.01 / 41.03 / 26.04 per second). Scheduled time from scheduled_at to visible SUCCESS p95 was 3.315 / 2.573 / 7.677 / 4.173 s; SUCCESS throughput was 0.76 / 0.89 / 0.85 / 0.76 per second. Unrelated SELECT p95 was 1.295 / 1.927 / 1.566 / 1.288 ms. Trigger counters were 36 / 31 / 33 / 39 with 30 SUCCESS runs per leg. Retained firing-state snapshots cannot establish exact skipped totals after completed rows are cleaned up. One PR leg had a higher tail than both controls, with at least two observations at or above its p95; scheduled_at is second-granularity and host variation is substantial, so this does not establish production parity or a stable latency improvement.

An independent 30-success diagnostic run had 4.48 s scheduled e2e p95. Its observed delay was mostly before recorded start; it cannot establish the cause of the 7.677 s sample or distinguish scheduler allocation from runner admission. The earlier pre-fix 12-sample candidate trace showed repeated same-parent guard contention and 15–16 s tails; that specific tail did not recur in these runs.

With an injected first-query failure and 512 rows containing 8 targets, the sparse fallback used 33 decorated queries versus 825 in the earlier pre-correction run on the previous main revision. A dense post-LIMIT-filtered case still needed 538 queries. At an intentionally aggressive 10 ms fetch interval, one-second untrusted short/prefix/full wrapper workloads produced 59/63/104 decorated queries and 100/101/101 raw page reads. The database plan remains a table scan with a top-N sort: 32 bounds returned headers per page, not physical scan work. Default runner polling is 10 s, and the built-in holder classifies its built-in storage as trusted.

Latest CI fix validation: After rebasing onto main 553e16f52b, the two-CN ALTER regression passed under -race and with taskservice/frontend coverage instrumentation; the previously failing cancellation subtest also passed five separate selections. Parser regeneration and package tests, incremental vet, golangci-lint and molint passed. The prior CI cancellation test incorrectly treated a canceled client as proof of server rollback; it now asserts prompt cancellation and the independent writer rollback without claiming a final ALTER outcome. A canceled or disconnected ALTER may still commit, so its outcome must be reconciled before retry. A real v4.2.8 stopped-upgrade test remains historical validation on 6cae8ff and was not repeated after this rebase. New GitHub CI is pending.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 9251ada65dccf6d4ff7cd63a52d4305dbe8c41ff

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 9251ada65dccf6d4ff7cd63a52d4305dbe8c41ff

Assessment: request_changes

Exact-owner consolidation is justified, but the upgrade design violates established catalog-release and protocol contracts. Two P2 design corrections remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P2 pkg/bootstrap/versions/v4_0_8/upgrade.go:34: Introduce the ownership migration while 4.0.7 remains the pending, unreleased catalog target.
    Impact: The extra 4.0.8 route adds durable upgrade state and compatibility machinery for an unsupported unreleased source.
    Evidence: The pre-existing docs/design/20261028-catalog-upgrade-407.md:7-9 explicitly requires consolidating pending migrations into 4.0.7 and forbids unreleased successors. Pinned v4.2.8@10d204b8763f19b2b37ba2147d1d4c1a7828d6d4 ends at catalog 4.0.6/5. This handler instead requires 4.0.7 and is registered in bootstrap/upgrade.go:65. Preserve published migration effects, move these three migrations into the pending 4.0.7 owner, and align upgrade fixtures with supported released sources.

  • P2 pkg/defines/const.go:173: Add MORPCVersion135 solely for SQL-task ownership and require it before migration.
    Impact: This introduces a per-feature global protocol generation and cluster-wide discovery barrier outside the shutdown-only deployment contract. It cannot fence a partitioned old executor.
    Evidence: The unchanged upgrade-compatibility.md:50-80 prohibits new per-feature protocol bumps and capability gates. No framing or handshake change is present. v4_0_8/upgrade.go:39 and :54 add the requirement and live GetProtocolVersion check. Remove the PR-owned 135 bump and checks; retain schema validation, stopped-writer isolation and unrelated existing gates.

Validation:

  • Reviewed the complete design, mapped all 75 files, and assessed both discussion entries and four linked issues.

  • Verified unchanged policy authority, pinned released catalog inputs and the migration/protocol consumers.

  • Static source/evidence audit passed; source unchanged. Receipt: checks/1793956113223710910-2.json. Records: validation-ledger.json.

Limitations:

  • Dependent implementation, generated-parser and runtime review stopped at the mandatory design gate; no local Go or SQL execution.

  • Author runtime reports were not independently reproduced; five current-head CI checks remained unfinished.

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: e737c558a08c2a815b74cb4ab5d6309f65542f3a

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: e737c558a08c2a815b74cb4ab5d6309f65542f3a

Assessment: approve

The design coherently reuses TaskStorage transactions and runner ownership, with bounded metadata-only recovery that avoids SQL replay. The ALTER race and prior review concerns are resolved. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all 93 changed paths, 26 discussion items and four linked issues.

  • All 368 taskservice root tests passed normally and with race detection; concurrent-trigger ALTER passed 100 race repetitions.

  • Eighteen frontend/client/error tests passed with race detection. The new frontend ALTER test passed normally and 100 race repetitions.

  • Two-CN ALTER, original account cleanup, public ownership/FORCE/retry and staged released-schema upgrade/restart checks passed with race detection.

  • Parser regeneration matched exactly. Parser/AST checks, released-DDL comparison, formatting and discussion coverage passed.

  • Commands, source fingerprints, exits and retained logs are reconciled in validation-ledger.json. Source remained unchanged.

Limitations:

  • Five frozen CI checks remain in progress; skipped upgrade checks are not passes.

  • Full distributed BVT, predecessor-binary execution and performance results rely on qualified supplied reports; historical raw logs were unavailable.

  • Process loss or unknown business commits can retain RUNNING metadata; operator isolation and explicit FORCE remain the intended recovery contract.

Observe deferred completion and refetch through the registered runner. Preserve real-store batch deletion coverage with unschedulable stale siblings and assert no SQL effects or run history.
@XuPeng-SH

XuPeng-SH commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: bde2fd688aa33c5c5b9e02355cb006293d958386

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: bde2fd688aa33c5c5b9e02355cb006293d958386

Assessment: approve

No actionable findings remain. Exact-owner transactions and bounded metadata recovery coherently reuse existing storage and runner responsibilities. The corrected ALTER test preserves valid transaction oracles without assuming cancellation proves rollback. Prior concerns remain resolved.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Qualified prior complete review 5853730870 against current inputs: 89 of 93 feature paths are identical; independently reviewed the test/documentation continuation and unchanged task grammar.

  • Isolation preflight and byte-identical parser regeneration passed; receipts: checks/1794378010105344011-2.json and checks/1794378104667144247-2.json.

  • Frozen-source, formatting, discussion and evidence audit passed; receipt: checks/1794378750857420683-2.json. All 28 discussion keys are assessed, and source remains unchanged.

  • Retained review-plan.md, discussion-assessment.json, closure-review.md and validation-ledger.json.

Limitations:

  • No fresh local application, race, cluster, BVT or benchmark runs. Matching prior-review and current-author runtime reports were reused; their raw execution logs were unavailable.

  • Four current-head CI checks remain in progress; skipped upgrade checks are not passes.

  • Unknown business outcomes or process loss may retain RUNNING ownership until operator reconciliation; FORCE requires isolating the old executor.

This branch was successfully deployed

No deployments
ci — f8612a72 Deployed Nov 11, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change kind/bug Something isn't working kind/enhancement kind/refactor Code refactor kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

4 participants