Skip to content

fix: reduce streaming export spool payload residency - #31409

Merged
XuPeng-SH merged 20 commits into
matrixorigin:mainfrom
ck89119:issue-30575-main
Oct 30, 2026
Merged

XuPeng-SH merged 20 commits into
matrixorigin:mainfrom
ck89119:issue-30575-main

Conversation

@ck89119

@ck89119 ck89119 commented Oct 27, 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:

Related to #30575. This PR does not claim closure of the original production report.

What this PR does / why we need it:

  • Accept exact-capacity spool buffers without weakening allocation-provenance checks.

  • Materialize full, non-appendable reads into private query-owned varlen payloads before publication, then retain those immutable payloads through the existing spool lease path instead of copying the whole area again. Descriptors and mutable metadata remain independent; the last reference frees the original allocation without capturing a reusable source Vector.

  • Preserve cache isolation, destination allocation accounts/modes, COW and partial-failure cleanup. Retire empty owned scratch before admitting a new private payload. Selected-row, TopN and appendable/MVCC materialization keep their existing path; DOP and pipeline/wire/storage protocols are unchanged.

  • Preserve overlapping Vector/raw/JSON/array inputs before COW or growth; admit writable backing before payload writes. Opaque writers/encoders keep original inputs alive until their synchronous callback completes, with admission before user code and no replacement backing committed on failure. Fixed and varlen aliases are rejected before issuing a selected-batch preflight proof.

  • Sort and compact already-private varlen descriptors directly, retaining the readonly payload lease; the no-pool path does not clear length and then call fallible append/COW.

Reviewed design: v1, exact pre-implementation revision. SHA-256: 4916aed9d16864307c78f14456b3dc0f668259d1aee350e20c45bef6181d581e. The developer approved this direction before ownership implementation; the archive preserves the reviewed document verbatim.

Validation

  • SCA follow-up 7da8dd0bea (base 21991b3827): removed the forbidden unsafe import from the new regression test without weakening backing-address assertions or adding check exceptions. CI-configured molint source 35bd4d9a4055 reproduced the checkunsafe failure before the fix and passed afterward; vector UT/vet/race, the 90-scenario regression race ×100 and incremental golangci-lint passed locally. Post-push CI was not monitored.
  • Ownership/sort validation at 2cc731ffc2 (base 7597f979e7): formally rebuilt native dependencies after the target Makefile change and verified provenance; full UT, race and vet=all passed for eleven owning/consumer packages, including readutil, partitionprune and ivfflat, on Darwin/arm64 with Go 1.27.1. Incremental golangci-lint: 0 issues. The latest 90-scenario sort/compaction regression passed race ×100, preserving payload/descriptor/lease identity and allocation counts. Changed executable-line coverage: 100% for the latest fix, 89.87% for the complete PR. Earlier source/COW/preflight/admission regression cases remain in the owning-package suites.
  • Earlier frozen revision (861a2c4cb6 plus this patch): eight owning/consumer packages passed full UT/race on Darwin and Linux arm64; a small persisted TEXT/vector SQL smoke passed two independent same-instance mo-tester comparisons (14/14 each).
  • On that frozen revision, official mo-dump 1.0.0 exported 262144 rows containing 4 GiB of independent random text and nonzero 768-dimensional vectors. Two DOP=2 A/B rounds reduced aggregate mpool peak from 1430.4 to 562.1 MiB and 1426.7 to 570.3 MiB (about 60%). All six exports, including the DOP=1 control, passed ID/content-hash/vector verification. Spool in-use allocations returned to zero after export. These are aggregate allocator observations, not isolated query-only or RSS measurements, and were not rerun on the current head.

Limits / review focus

  • The original v4.1.4 Linux x86_64, two-CN/24-producer environment was unavailable. Linux arm64 component tests and local single-CN experiments are not equivalent to that topology.
  • No universal speedup or low-DOP non-regression claim: the DOP=1 control had no spool and measured 192.0 to 204.9 MiB aggregate peak, with elapsed time 27.52 to 29.59 seconds. RSS and warm/cold timing varied. Latest source-safety checks added no allocations in the owned controls, but sampled 2048-row bulk-append CPU medians increased about 6–10%; opaque callback growth/COW can require an additional admitted working copy.
  • Please focus review on snapshot/COW semantics, source lifetimes, preflight/publication, allocation provenance and final-reference cleanup. Local tests do not establish current CI status or original-production acceptance.

@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 size/XXL Denotes a PR that changes 2000+ lines and removed size/XL Denotes a PR that changes [1000, 1999] lines labels Oct 28, 2026
@XuPeng-SH

XuPeng-SH commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 7535e32dff23423c693d5df9192f3a480463fe80

Review discussion changed before publication; a fresh contextual review is queued.

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

Reviewed the complete 21-file diff at head 7535e32dff23423c693d5df9192f3a480463fe80 against dispatched base 9e29011e7313a57962adc00963baa659d1e81e37, including full-read routing, cache isolation, spool snapshots, allocation provenance, source staging and final-reference cleanup. Scope remains the spool-residency change related to #30575; this review does not establish closure of the original production report.

The previous Copy/UnionBatch descriptor invalidation and Window-source findings are addressed by the current source-preservation/COW ordering and covered by passing targeted tests. No current P0/P1 finding was confirmed.

[P2] Preserve the allocation-free sort/compact path for leased varlen results — pkg/container/vector/vector.go:10296–10297.

InplaceSortAndCompact() still restores compacted descriptors with appendList(v, newCol, nil, nil) after setting v.length = 0 (vector.go:12001–12006, 12320–12322). For a vector with a leased area, the new alias guard invokes withClonedBytes with a nil mpool, which returns an error. The sorter ignores that error and leaves an empty vector marked sorted. The new COW check in extendWithBitmaps also requires a pool, so simply bypassing this alias guard would not restore this caller's contract.

Exact-head reproducer, using ordinary TEXT values without provenance sidecars:

  1. Append [b×64, a×64, a×64] to an off-heap source and populate an empty destination with CopyWithReadonlyArea.
  2. Call destination.InplaceSortAndCompact().
  3. Expected: two sorted rows [a×64, b×64]. Actual: Length() == 0, GetSorted() == true, with no returned error.

The previous owned UnionBatch materialization returns the expected two rows. A manually installed area lease also works with the baseline vector implementation loaded through a read-only Go overlay. Both controls finish with zero mpool balance. This is introduced by the changed append/COW behavior and is exposed by the new leased full-read representation. Keep descriptor compaction compatible with this no-pool API, or provide an explicit fallible materialization boundary before clearing length; add duplicate-value leased TEXT/array coverage. This is P2 because the inspected production sort/compact callers currently construct owned or deserialized vectors; this review did not establish a SQL path passing a leased scan result directly to this method.

Validation on the dispatched head:

  • Passed targeted normal tests in vector, pSpool, objectio, objectio/ioutil, and blockio, covering the new readonly mutations, writer/encoder failures, Window sources, cache isolation, queued snapshots and block routing.
  • Passed targeted -race tests for readonly mutation/snapshot cases in vector and retained reader payloads in pSpool.
  • Executed the additional sort reproducer and owned/baseline controls above. Source files remain unchanged. Diff whitespace and Loom PR artifact checks passed.
  • Built the required CGo libraries locally. The broader make cgo invocation was stopped during an unrelated ONNX Runtime download after a network timeout; it is not reported as a successful full native build. No cluster/BVT, production-topology export or current-head performance benchmark was run locally.
  • Dispatch CI: all 29 checks completed (13 success, 14 skipped, 2 neutral); CI Required succeeded. GitHub reports mergeable, behind main.

Read the previous reviews, both supplied inline threads and PR conversation. The previous reviews contained P1 findings, with no prior P2/P3 author-reply disposition to apply. The remaining P2 above is newly reported, so the event is COMMENT (one P2; no P0/P1/P3).

Comment thread pkg/container/vector/vector.go Resolved
@XuPeng-SH

XuPeng-SH commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 7da8dd0bea535834a5316184ddfab1c19206aacd

Review discussion changed before publication; a fresh contextual review is queued.

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

Reviewed the complete 23-file diff at head 7da8dd0bea535834a5316184ddfab1c19206aacd against base 21991b38274208798e67e14d4b2dfc4743048572. No current findings were confirmed. APPROVE.

The previous descriptor invalidation and Window-source findings remain addressed: overlapping sources are preserved before COW, and materialization precedes descriptor references and capacity admission. The last review's sort/compact issue is also addressed: varlen compaction publishes the existing descriptor prefix through SetLength, retaining the payload lease without a fallible no-pool append. Added regression coverage checks duplicate and unique TEXT/array values, retained snapshots, backing identity and allocation counts.

All previous reviews, three inline threads and the supplied PR conversation were checked. No explicit author replies to those findings appear in the supplied data; repair commits were not counted as replies. The findings are resolved in the current code, so none remain subject to the outstanding minor-finding reply rule.

Validation: read the full diff and relevant read/cache/spool, mutation, allocation-account and terminal-cleanup call chains. Local git diff --check and the Loom PR artifact check passed; source remains unchanged. Reused the exact-head CI results and inspected the UT job's checkout, race-mode invocation and successful step status. Individual new regression names were not visible in that job log, so no independent case-level execution claim is made. Local package/race tests and cluster/performance runs were skipped because source inspection disclosed no remaining uncertainty requiring another execution; author-reported local results were not treated as newly executed reviewer tests.

Dispatch CI is complete but not all 29 checks are successful: 13 success, 14 skipped and 2 neutral; none failed or pending. CI Required succeeded, as did UT, SCA and the enabled proxy/pessimistic multi-CN BVT checks. This scoped review does not establish closure of the original production report in issue #30575 or reproduce its two-CN x86 export measurements.

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

Approved for this scoped optimization. I checked the private reader materialization, retained payload ownership, copy-on-write and alias handling, allocation provenance, partial-failure cleanup, and the relevant spool/Vector/storage tests. I found no blocking issue. Passing CI and the documented author validation were reused; I did not reproduce the original 24-producer production environment, so this approval does not claim that issue 30575 is fully resolved or that all workloads improve.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 7da8dd0bea535834a5316184ddfab1c19206aacd

Review completed. Read the assessment.

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

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

Commit: 7da8dd0bea535834a5316184ddfab1c19206aacd

Assessment: approve

Reviewed the complete 23-file delta and ownership consumers. The earlier descriptor, Window-alias and sort/compact defects are resolved. No actionable findings remain; the scoped residency-versus-copy-cost tradeoff is acceptable.

Model: gpt-6-astra / xhigh

Session: 01a1869d-999c-7481-b340-ae4a63e8cee4 · slot 1 · generation 2

Validation:

  • Source audit passed: frozen head/base, unchanged checkout, matching patch, diff whitespace, all 17 discussion dispositions and preserved SQL/result oracles. Receipt: checks/1793329872185117086-2.json; log: source-validation-final.log.

  • Reused supplied exact-head CI and prior review evidence: 13 successful checks, 14 skipped, 2 neutral; prior review records UT/race execution inspection.

  • Saved review-plan.md, discussion-assessment.json, review-notes.md and validation-evidence.json; reconciled both audit receipts and retained logs.

Limitations:

  • No Go tests or SQL BVT were run locally in this attempt; raw CI logs and the external design document were not bundled.

  • Original two-CN DOP24 production behavior was not reproduced. Approval does not establish incident closure or universal performance improvement.

@mergify

mergify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

5 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Fri 30 Oct, 03:14 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 03:19 · 2979ce8

Reason

Pull request #31409 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

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

dequeued kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants