Skip to content

feat: add Sirius Substrait read admission - #26737

Merged
mergify[bot] merged 54 commits into
matrixorigin:mainfrom
aunjgr:agent/26156-26157-substrait-read
Aug 11, 2026
Merged

mergify[bot] merged 54 commits into
matrixorigin:mainfrom
aunjgr:agent/26156-26157-substrait-read

Conversation

@aunjgr

@aunjgr aunjgr commented Aug 5, 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:

issue #26156, #26157

What this PR does / why we need it:

This is PR 2 of the revised #26154 Sirius offload split. It combines the logical Substrait export contract with snapshot-safe TAE read admission so the next PR can focus on execution and result transport without reopening storage correctness.

The change:

  • exports a deliberately narrow Sirius v1 Substrait subset for read, filter, project, aggregate, sort, and fetch;
  • rejects unsupported operators, types, overloads, literal mismatches, unsafe column ordinals, historical scans, and non-persistent tables before storage access;
  • admits only read-only snapshots whose visible state is fully represented by persisted TAE objects, with no in-memory tail or tombstones;
  • defines deterministic TaeRead and resolver protobuf wire contracts without exposing object locations in the plan;
  • persists resolver leases in shared file service storage and replays GC protection before admission or resolver startup;
  • treats capability expiry as resolver revocation only, retains and replays GC pins fail-closed until the execution owner confirms Finish or cancel-and-join, and durably revokes before terminal unprotection;
  • exposes an exact mTLS-only resolver route and an opt-in compile cutpoint for the following execution PR;
  • makes TAE sync protection registration and terminal release idempotent for replay; and
  • declares the upstream Substrait Go module's Apache-2.0 license for SCA because its module zip contains SPDX headers but omits the repository-level license file.

Validation:

  • focused tests for pkg/sql/plan/substrait, pkg/vm/engine/disttae/sidecar, and pkg/vm/engine/tae/db/gc/v3;
  • compile build for pkg/sql/compile;
  • race tests for the complete Substrait and TAE GC packages;
  • 100 repetitions of resolver/release/replay concurrency tests;
  • repository license header and dependency checks; and
  • git diff --check.

@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 →

@aunjgr aunjgr 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.

Addressed both blockers in 3b713e8 after merging current upstream/main with 40452d6.

  1. FileServiceLeaseJournal no longer creates or trusts a process-local admission mutex. Its constructor now requires a JournalAdmissionCoordinator whose contract serializes the named namespace across CN/process boundaries, honors cancellation, and fences callback ownership. StoreIfCapacity holds that coordinator across the live-record scan and the complete batch publication; Load uses the same boundary. The regression now creates independent journal A/B/C instances over one backing prefix and uses an explicit barrier: B reaches the shared coordinator while A owns the scan+publish critical section, exactly one maximum=1 write succeeds, and C replays exactly one live lease. There is no unsafe local default for later runtime wiring to accidentally use.

  2. DATE and TIMESTAMP are now rejected as typed EligibilityType declines for both scanned columns and literals, and both are removed from the capability document. The regressions use MatrixOne DATE/TIMESTAMP values at 1970-01-01 and cover the public Export path for scans and projected literals. This avoids claiming equivalence until the Unix-epoch/range/session-timezone contract is implemented end-to-end.

Validation after the final edit: go list/build/vet pass for all six owning packages; controlled normal and race package tests pass for substrait, compile, disttae/sidecar, disttae/logtailreplay, tae/db/gc/v3, and disttae; the deterministic capacity regression passes -race -count=100; make err-check and git diff --check pass.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep re-reviewed exact head 3b713e81845ffc86f237dfd5504a2fe24fa33759, including the latest response and the full exporter → admission/journal/resolver → disttae snapshot → TAE GC lifecycle. DATE/TIMESTAMP now fail closed correctly, but two blockers remain.

  1. P1 — the distributed capacity invariant is still only an interface contract, not an implementation (pkg/sql/plan/substrait/journal.go:54-103, substrait_test.go:610-667,1212-1258). The production tree contains no JournalAdmissionCoordinator implementation and no production NewFileServiceLeaseJournal wiring at all. The regression gives all three journals the same testJournalAdmission, whose exclusion is still one process-local contextMutex; constructing separate journal objects does not test independent CN/process coordinators over shared storage. Thus the previous cross-CN maximum=1 counterexample has been moved behind a caller-supplied interface but is not actually closed by this PR. Please provide and exercise the real fenced cluster-wide coordinator (including ownership loss/cancellation), or keep persistent multi-CN admission out of the claimed usable contract until that implementation lands.

  2. P1 — expected size ineligibility is surfaced as an operational query failure instead of native fallback (pkg/sql/plan/substrait/admission.go:869-877). A table whose snapshot is valid but whose manifest exceeds the advertised 64-MiB offload bound is simply not eligible for Sirius; it is not corrupt state. Current Admit returns moerr.NewInternalError for that case, and it also string-wraps every provider error, destroying any typed EligibilityError. A public-path counterexample using an otherwise valid candidate and a MaxManifestBytes+1 snapshot yields IsNotEligible(err) == false with schema or manifest mismatch. Once the optimizer calls this cut point, a query that MatrixOne can execute natively will fail instead of falling back. Classify side-effect-free size/capability declines before lease publication as EligibilitySnapshot and preserve typed provider declines through Admit; add the public compile/admission fallback regression.

Normal tests pass for substrait, compile, disttae/sidecar, logtailreplay, and TAE GC; the critical journal/resolve/protection tests also pass under -race -count=10. These tests do not cover the missing production coordinator or the size-classification counterexample above. Required CI is green and git diff --check passes.

@aunjgr

aunjgr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH Thanks for the re-review. Both blockers are addressed in 9b0db02 after merging current upstream/main (no rebase).

  1. The persistent journal now has a production coordinator backed by MatrixOne lockservice, and the public NewFileServiceLeaseJournal constructor requires that LockService. Its exclusive callback is fenced for caller cancellation, service shutdown, and lock-table bind ownership loss; bind transfer and shutdown cancel and join the callback before proceeding. The capacity regression now starts two real independent CN lock services and separate journal instances over one FileService namespace, deterministically observes CN B waiting on CN A distributed ownership, permits exactly one maximum=1 publication, and replays exactly one live lease from a third journal. Separate lockservice regressions cover cross-service serialization, bind-loss cancel/join, caller cancellation, and panic cleanup. During self-review I also moved this coordinator off the existing table-dump synthetic lock ID.

  2. Provider EligibilityError values now pass through Admit unchanged. Deterministic manifest/schema size bounds return EligibilitySnapshot before lease registration/publication, including provider-side manifest-builder overflow. Empty or mismatched snapshot data remains an operational corruption error. Regressions assert MaxManifestBytes+1 is eligible for native fallback and publishes zero protection state.

Fresh validation on the pushed tree: all affected normal and race package suites pass; the real two-CN journal test passes under -race -count=100; all four exclusive-lock lifecycle tests pass separately under -race -count=100; go list/build/vet pass for lockservice, substrait, sidecar, and compile; make err-check and git diff --check pass.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep re-review — REQUEST_CHANGES

Reviewed exact head 9b0db025d5157c6c77bcd7b75dc9fcfd17f30910 against merge-base b84a6627060539173f9ee243e8523792a3ad2200, including all existing review threads and the latest author response.

  1. P1 — a remote lock-table owner can orphan-unlock the new exclusive callback while it is still running (pkg/lockservice/service.go:314-398, pkg/lockservice/service_remote.go:631-653, pkg/lockservice/service.go:2175-2220)

    RunExclusiveLock records callback ownership only on the originating service's synthetic activeTxn. When the synthetic lock is remote, the lock-table owner checks the holder through CheckActiveTxn; that handler reports only frontend TxnIterFunc transactions and unknown-commit resolver ownership, so the random callback txn is reported inactive. The waiter orphan path then obtains an allocator fence and unlocks the holder without canceling or joining its callback.

    A deterministic two-CN counterexample pre-binds the synthetic table to CN B, blocks a RunExclusiveLock callback started from CN A, then starts the same-row callback on CN B. The log reports found orphan remote txn, and CN B enters while CN A is still blocked. The existing serialization and journal-capacity tests miss this because CN A creates the binding and is also the first holder; isValidRemoteTxn returns true immediately when CreatedOn == owner serviceID.

    This reopens the original capacity race: two journal callbacks can both scan the same live count and publish, so maximum=1 can again yield two durable live leases and make replacement replay fail. Please make exclusive-callback ownership participate in the remote active/orphan protocol, and require orphan cleanup to cancel and join the callback before releasing its lock. Add the pre-bound-remote-owner regression, not only the local-owner topology.

  2. P2 — a native-valid UINT64 LIMIT outside Substrait's signed range is not classified for fallback (pkg/sql/plan/substrait/export.go:459-478,1052-1081)

    The real binder accepts SELECT a FROM select_test.bind_select LIMIT 18446744073709551615 and produces Literal_U64Val(math.MaxUint64). nonnegativeIntLiteral returns an internal error above MaxInt64, and fetch wraps it as another internal error, so Export returns IsNotEligible(err) == false. Once the cut point is enabled, this MatrixOne-valid query fails instead of falling back even though the only issue is an unsupported Substrait fetch bound. Return a typed eligibility decline for representability/capability limits and add the real-bound public-path regression.

Validation: controlled CGo full package tests pass for lockservice, substrait, compile, disttae/sidecar, disttae/logtailreplay, and TAE GC; focused disttae tests pass; the journal/authority race targets pass under -race -count=10. Both counterexamples above fail deterministically on the exact head. CI is green but does not cover either topology/value boundary.

@iamlinjunhong iamlinjunhong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review of exact head 9b0db025d5157c6c77bcd7b75dc9fcfd17f30910 against merge-base b84a6627060539173f9ee243e8523792a3ad2200.

One blocking P1 finding is recorded inline.

Lifecycle audit summary:

Check Result
Q1: one effective cleanup/ownership owner Failed across remote lock-table-owner failover: old and new callbacks can both mutate the journal namespace.
Q2: every wait terminates Local caller cancellation, service close, bind-change join, and panic cleanup are covered; the failover gap occurs before the old client observes cancellation.
Q3: every accumulation is bounded Lease maps, replay batches, resolver payloads, and protection counts have explicit bounds.

I read the full PR conversation, all reviews, and all review threads; the prior findings are resolved on the current head. This is iamlinjunhong’s first review. All 31 checks are complete and successful, and git diff --check passes.

@aunjgr

aunjgr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH please re-review current head dbabde0489.

Your two blockers on 3b713e8184 were addressed in 9b0db025d5: the production journal now uses MatrixOne lockservice for fenced cross-CN admission, and typed provider/size eligibility declines pass through before lease publication. I also merged current main; that merge is disjoint from the Sirius/lockservice files.

Fresh validation on the merged head: all affected normal suites pass; the four exclusive-lock lifecycle tests and cross-manager journal-capacity test pass under -race -count=100; full lockservice and Substrait race suites, build, vet, SCA, and diff checks pass.

@aunjgr

aunjgr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the latest XuPeng-SH review in 06998de and 61f27ce after merging current main at 25d41df.

  1. Remote exclusive callbacks now participate in the authoritative CheckActiveTxn protocol from before Lock can publish a remote holder through callback completion and unlock. The exact lock-table owner generation is synchronously renewed before external code and periodically until the callback returns. Allocator renewal and timeout invalidation serialize through the owner keepalive generation, so owner failure validation cannot rebind while the remote callback remains active. Ownership loss cancels and joins the callback; ordinary activeTxn entries remain non-authoritative. The deterministic two-CN regression pre-binds to CN B, starts from CN A, invokes the actual owner orphan path, races stale generation invalidation, verifies the remote holder remains, and proves B enters only after A returns.

  2. Binder-produced U64 LIMIT or OFFSET values above MaxInt64 now return a typed EligibilityExpression decline without being converted to an internal error. The public-path regression binds LIMIT 18446744073709551615, verifies the MaxUint64 literal shape, and requires IsNotEligible.

Validation on the merged head: complete normal and race packages pass for lockservice and substrait; focused race regressions pass with count=20; go vet and make err-check pass; coverage is 87.6% for lockservice and 84.6% for substrait; git diff --check passes.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 blocker: allocator timeout invalidation can still transfer this exclusive callback before the old callback is joined. The generation check only makes a stale validation lose after a successful renewal. If disableTableBindsAtGeneration wins with the current generation (lock_table_allocator.go:448-460), the next requester is immediately published as owner (lines 630-643); the old origin learns about the loss only on its next renewal (service.go:447-450), so its callback can still be inside the FileService capacity scan/write (journal.go:115-137).\n\nI reproduced this on the exact current head with a three-CN counterexample: pre-bind the table to B, start the callback from A, sample the current generation after the admission renewal, let invalidation of that generation succeed, then acquire from C. C enters the same exclusive row before A is allowed to return. The race test reproduces under -race -count=5; A can even return nil when it finishes before its next renewal. The new TestRunExclusiveLockFencesRemoteOwnerOrphanAndRebind snapshots the generation before admission renewal and only proves the opposite ordering, where stale invalidation loses.\n\nBecause the journal writes carry no allocator epoch/CAS, a completed old write cannot be retracted. Please fence the durable store (or make failover handoff wait for old callback completion) and add a regression where current-generation invalidation wins and the successor still cannot enter/publish until the old callback is joined.

@aunjgr

aunjgr commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH Thanks — the current-generation counterexample is valid. I addressed it at head b915ff7fa0 by withdrawing the unsafe production contract rather than adding another timing/renewal fence.

  • Deleted the lockservice-backed journal coordinator and removed the exported NewFileServiceLeaseJournal production constructor.
  • Reverted all RunExclusiveLock/exclusive-activity/allocator-renewal changes introduced by this PR; pkg/lockservice now has zero diff from current upstream main.
  • Made the FileService journal type, constructor, and coordinator seam package-internal. It remains exercised as a storage/lifecycle foundation, but cannot be wired as a claimed multi-CN production admission implementation.
  • Documented the missing requirement explicitly: production wiring must wait for a durable coordinator whose ownership transfer is atomic with FileService publication. A lock-table generation alone cannot retract or fence a completed old write.

The push hook merged current main (no rebase). That merge brought #26902’s corrected MOD nullability contract; I aligned the semantic-registry regression so nullable MOD remains admitted and a forged non-null result is rejected.

Validation on the exact final head: focused Substrait regressions pass; full pkg/sql/plan/substrait passes normally and under -race; the restored lockservice active-transaction regression passes; make err-check and git diff --check pass. All review conversations are resolved; this review was submitted as a review body, so GitHub provides no separate inline thread to resolve.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep-reviewed exact head b915ff7fa0bc3d579a91a301e957e45544c4b566.

The prior current-generation invalidation blocker is resolved by withdrawing the unsafe production contract: the lockservice-backed coordinator and public FileService journal constructor are gone, pkg/lockservice has no remaining PR diff against current main, and the FileService journal/coordinator seam is package-internal with an explicit durable-handoff requirement. Consequently the unfenceable multi-CN write path from the previous counterexample is no longer reachable through a claimed production API.

I also rechecked the resulting journal/replay/revocation invariants and the main-merge nullability adjustment. The complete pkg/sql/plan/substrait suite passes on this exact head, including capacity serialization, authority/release linearization, replay bounds, rollback, resolver authorization, and eligibility regressions. All live CI checks are terminal and green.

@iamlinjunhong iamlinjunhong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review of exact head b915ff7fa0bc3d579a91a301e957e45544c4b566 against merge-base 494d77c8443b51694e0cbac7fc0a03b9a7f887eb.

The previous P1 on journal_coordinator.go was explicitly answered by the author and is resolved on this head: the production coordinator and all PR lockservice changes were withdrawn. One new blocking P1 is recorded inline; no additional P0/P2/P3 findings were confirmed.

Lifecycle check Result
Q1: one effective cleanup/ownership owner Failed: absolute expiry can remove the object pin before sidecar execution reaches Finish.
Q2: every wait terminates Resolver byte admission, audit, HTTP shutdown, and lease cleanup have bounded cancellation/timeout paths; no hang was confirmed.
Q3: every accumulation is bounded Lease count, manifest/schema size, replay batches, resolver in-flight bytes, and object enumeration are bounded.

All 31 checks are complete with accepted conclusions, and git diff --check passes.

@iamlinjunhong iamlinjunhong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep re-review of exact head d83ae49e46bb1bf1f054afa602ec329b8a2f878c against merge-base 75d61d06bfaa2c3a7f86bab5ccf461df42acf20f.

The previous P1 was explicitly answered by the author and is resolved on this head: expiry now revokes resolver access only; expired unreleased leases remain protected, survive replay, and retain capacity until the terminal execution owner has stopped/joined readers and calls Release. This preserves the fail-closed storage contract for the next execution PR without reintroducing premature unpinning.

No current P0, P1, P2, or P3 findings were confirmed. I rechecked the full exporter → admission/journal/resolver → disttae snapshot → TAE GC call chain, failure cleanup, replay, concurrency bounds, compatibility gates, tests, PR conversation, reviews, and review threads. All 31 checks have accepted conclusions (18 pass, 13 skipped), and git diff --check passes.

@mergify

mergify Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-11 13:13 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-11 13:56 UTC · at df7e76919e6c3c10653234d983c4ef6dab74ab0e · squash

This pull request spent 43 minutes 14 seconds in the queue, including 42 minutes 35 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

This branch was previously deployed

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

Labels

kind/api-change kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants