Skip to content

feat: stream local scans to Sirius sidecar - #27599

Closed
aunjgr wants to merge 36 commits into
matrixorigin:mainfrom
aunjgr:feature/27586-stream-input
Closed

aunjgr wants to merge 36 commits into
matrixorigin:mainfrom
aunjgr:feature/27586-stream-input

Conversation

@aunjgr

@aunjgr aunjgr commented Aug 25, 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 #27586

What this PR does / why we need it:

Streams eligible local MatrixOne scans to Sirius as MatrixOne-native batches and returns MatrixOne-native result batches. Explicit /*+ SIDECAR STREAM */ keeps snapshot visibility, filtering, and projection in the ordinary MO reader; it never silently substitutes direct TAE or native execution.

  • Preserves reader back-pressure through the native output pipeline. Each input retains at most 128 frames and 64 MiB of payload until consumed acknowledgements or terminal cleanup; it does not accumulate the table on the wire.
  • Keeps one sidecar prefetch slot. Sirius batches at most 128 frames into one source representation bounded to 64 MiB of expanded data, using the existing pinned host pool.
  • Acknowledges a frame after Sirius owns its copy, and retains the source claim and reservation through H2D completion or terminal cleanup.
  • Supports gpu_stream=2 with independent pipelines running concurrently. Tasks within one physical pipeline remain serialized, including PARTITION; the earlier same-pipeline concurrency claim is superseded.
  • Handles cancellation, result-EOF retirement, and transport failures without retaining acknowledged/abandoned frames. Keeps process-wide admission and fail-stop GPU recovery.
  • Matches the capability document across all three repositories, retaining design version 1, wire protocol 4, and codec version 1.
  • Merges current MatrixOne main and uses its existing runPipelineAttempt wrapper so streamed producers preserve materialized-source cleanup on success, error, and panic.

Design and delivery identity

Design version 1, review iteration 7. Review iterations do not increment the version. Iteration 6's approval does not substitute for fresh review of iteration 7; production enablement remains pending that review and the acceptance evidence in sections 14–16.

  • MatrixOne head: 747ace3ec0e8021eecb31b24ed9077c9318964b7; includes authoritative main 4fdb9e91615f9fc37703039ae28a47849206d1d6.
  • Sirius #12: 902af81f4f906a2672bb3c75b36438bb79da6ce2.
  • Sidecar #20: 73889951c15f4346f7aa38b0600f07a8ef76c49b, pinned to that Sirius commit.

Merge Sirius #12 first, then update sidecar #20 to the upstream merged Sirius commit before merging it. These PRs must use the matching capability contract.

Validation

Post-main-merge MatrixOne validation:

  • sidecarflight normal and race suites passed.
  • substrait package passed.
  • Focused Sirius stream/read/runtime and pipeline-attempt cleanup tests passed.
  • Full pkg/sql/compile normal (3.826s) and race (5.339s) suites passed.
  • Exact-head CI is pending; older SCA/CI results are not claimed for this head.

Recorded integrated validation before the later main merge:

  • Sirius source/Substrait tests: 314 assertions in 23 cases passed, CUDA memcheck 0 errors.
  • Sidecar stream tests: 93 assertions in 10 cases passed.
  • Real nullable persisted/tail/tombstone query matches native MatrixOne output.
  • All 22 SF10 queries passed with true GPU_MO_SCAN, gpu_stream=2: 34.158730s total. Direct GPU_TAE_SCAN control: 15.501565s. Q9: 3.255576s versus 0.798354s.
  • These are single-run client wall times, not medians or a fresh benchmark of the merged head. Total ratio is 2.20x and Q9 is 4.08x; the design's 2x performance target remains unmet.
  • GPU builds, tests, and runs used the host Pixi toolchain, without rebuilding containers.

Full 22-query table, source revisions, profiling, and remaining work. Earlier benchmark comments are preserved as historical records; they are not substituted for this explicit stream/control comparison.

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

@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Aug 25, 2026
@mergify mergify Bot added the kind/feature label Aug 25, 2026

@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] Keep the streamed schema aligned with the native MO vector type

The new StreamRead schema path calls namedStructFromTypes, which reuses substraitType. That helper maps T_uint32 to Substrait I64 for the existing result-decoding path:

func namedStructFromTypes(typesIn []planpb.Type) (*spb.NamedStruct, []string, error) {
if len(typesIn) == 0 {
return nil, nil, moerr.NewInternalErrorNoCtx("substrait: streamed read has no columns")
}
names := make([]string, len(typesIn))
fields := make([]*spb.Type, len(typesIn))
for i := range typesIn {
names[i] = "col_" + strconv.Itoa(i)
field, err := substraitType(&typesIn[i])
if err != nil {
return nil, nil, err
}
fields[i] = field
}
and
case types.T_uint32:
// Substrait has no unsigned integer primitive. Sirius/DuckDB EXTRACT
// returns a signed i64; the Flight decoder restores MO's uint32 result.
return &spb.Type{Kind: &spb.Type_I64_{I64: &spb.Type_I64{Nullability: n}}}, nil
. The local stream producer does not perform that conversion; it sends the original batch unchanged:
root.setRootOperator(output.NewArgument().WithFunc(func(bat *batch.Batch, _ *perfcounter.CounterSet) error {
if bat == nil {
return nativeInput.Finish(c.proc.Ctx)
}
return nativeInput.Send(c.proc.Ctx, bat, c.proc.Mp())
}).WithShouldStop(nativeInput.NotNeeded))
. The exact sidecar dependency only accepts MO_T_int64 for an I64 field and rejects the batch otherwise: https://github.com/matrixorigin/mo-sirius-sidecar/blob/454bb96b36351da377a35c598ea0386177f74911/mo-sidecar/src/stream_input.cpp#L87-L100 and https://github.com/matrixorigin/mo-sirius-sidecar/blob/454bb96b36351da377a35c598ea0386177f74911/mo-sidecar/src/stream_input.cpp#L146-L156.

This makes a reachable hinted query over an INT UNSIGNED column pass export and Prepare, become externally visible, and then deterministically fail on its first DoPut batch; stream mode cannot fall back at that point. I reproduced it on af20802: a T_uint32 table scan is admitted and its StreamSchema is I64 while the producer type remains T_uint32.

Please separate output-transport type restoration from native-input schema mapping. Either reject T_uint32 before Prepare, convert the producer vector to int64 with null/const/split coverage, or define and implement an explicit uint32 wire mapping on both sides. Add a cross-boundary regression using an actual T_uint32 native batch so the result-only uint32 coverage cannot mask this mismatch.

@aunjgr

aunjgr commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — confirmed. The review is correct: substraitType is the semantic result contract, where T_uint32 -> I64 is intentional for result restoration, but it cannot define physical native-read compatibility.

Fixed in 8869b4f94e:

  • added an explicit nativeInputType allow-list used by both TAE and StreamRead schema construction;
  • T_uint32 now returns NotEligible during export, before transaction access or Flight Prepare;
  • kept semantic T_uint32 -> I64 result mapping unchanged, so EXTRACT result restoration and TPCH types remain supported;
  • fail closed for physically mismatched Decimal64/Decimal128 precision combinations as the adjacent form of the same invariant;
  • added a cross-boundary regression that creates a real T_uint32 vector, round-trips it through the MO native batch codec, proves the wire remains T_uint32, and verifies stream compilation rejects it before visibility.

Validation after merging newest main:

  • exact Go 1.26.4 build and vet pass for pkg/sql/plan/substrait and pkg/sql/compile;
  • focused uint32/native-input regressions pass;
  • full affected package tests pass (excluding only the three parquet cases already reproduced identically on clean newest main);
  • official changed-code coverage parser: 285/362 = 78.73% (gate >75%).

Please take another look.

Retain at most 128 frames and 64 MiB of payload per input, preserve native reader backpressure, and drain or release retained frames on terminal outcomes. Align capability identity with the pooled Sirius source and record SF10 correctness, timings, dependency commits, and the remaining performance gap.
Route streamed producers through the shared initializer owner so materialized source generations close on all terminal paths. Record the new Sirius and sidecar PR pins while keeping pre-merge SF10 measurements distinct from publication validation.

This branch had an error being deployed

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants