Skip to content

fix: bound CN spill runs by materialized bytes - #32188

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/32146-main-cn-spill
Nov 5, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/32146-main-cn-spill

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 4, 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 #32146

What this PR does / why we need it:

CN spill could admit a row-count block much larger than its byte target before serialization, increasing compression scratch and memory use. Bound ordinary CN data and tombstone runs by a conservative materialized-byte charge before copying. Close each run on a row boundary, keep a single oversized row intact, and preserve the existing object/block format and result handoff.

The rebase integrates the transaction workspace's existing admission, publication and asynchronous cleanup ownership: source entries remain until their replacement is recorded, transaction-bound failures hand names to the workspace, and unbound writers retain their own retry responsibility. Batched cleanup confirms each name if a file service reports a missing member; writer rebinding replaces both the old capacity hook and cleanup owner. Preserve generic sinker behavior on sort failures and propagate impossible compression scratch allocations as errors.

Investigation of the coverage CI failure in TestPKCheckReconnectRollsBackAndFreshTxnSucceeds identified a separate, pre-existing reconnect race: the receiver can signal the connector before it is ready to receive, so the connector's nonblocking resume can be lost. A cancellation-aware per-resume acknowledgement now makes the connector wait until the receiver has resumed. A controlled execution of the old code reproduced the lost wakeup and CI's matching log signature; the CI trace alone cannot prove the exact scheduling interleaving.

A later UT failure exposed another pre-existing sequence retry bug: an expiry decision could select a stalled sequence while the compiler returned the current pending error for a different sequence. Preserve the selected identity and its cause through arbitration and subsequent allocations, while retaining cancellation, publication and no-prober fallback behavior. The probe now uses the query context so cancellation of a finished pipeline alone cannot abort the decision.

Validation against main@9e67b078, Go 1.27.1 and source-matched native libraries:

  • Affected objectio, objectio/ioutil, colexec, deletion, insert, multi_update, disttae and TAE logtail packages passed normal and race runs. The CI-named reconnect test passed under race and separately under partial disttae coverage. Focused race repetitions covered early resume, cancellation, sibling drains, shared-pool teardown and workspace ownership. Incremental gofmt, vet, molint and golangci-lint passed for the affected package/consumer closure.
  • Sequence retry regressions passed on normal and race builds of pkg/sql/compile, pkg/sql/plan/function and pkg/vm/process. The CI-named test passed 100 normal and 100 race repetitions with a virtual clock; controlled tests for the arbitration and stamped-terminal paths fail on the unmodified base and pass with the fix. Existing sequence SQL cases passed 98/98 checks on a single-CN service (result metadata ignored).
  • Real file-service tests cover sorted and unsorted runs, multi-object/tombstone handoff, errors and cancellation, failed deletion/retry, multi-writer drain, workspace rebind, and retained earlier transaction statements. A source-built one-CN/one-TN service ran the checked-in SQL case twice with 34/34 passing, including INSERT/UPDATE/DELETE, object counts and rollback.
  • On a single host with an in-memory FileService, two 96 MiB values at the normal 128 MiB target changed from one object to two and the process mpool's off-heap peak from 403,177,472 to 201,850,880 bytes. A 136 MiB single row remains one object and can exceed the target. In repeated writes of that row, the local benchmark measured approximately 74–75 ms/op on the base and 90–91 ms/op on the candidate while the writer's retained process-mpool allocation after Reset fell from about 286 MB to zero. These are controlled low-entropy results, not a process-wide or production memory bound.
  • More objects have a cost: with a deliberately reduced 512 KiB target, a single-CN SQL workload inserting and updating 2 MiB per table produced one object per table after insert on the base and five on the candidate; its six-sample median increased from approximately 91 ms to 228 ms. This stress test does not represent the default threshold or real object storage. With the normal 128 MiB target and a forced workspace flush to exercise the writer, the same single-CN workload produced one object per table on both versions; over four ABBA service processes with eight iterations each, base/candidate mean was 106.6/109.9 ms and median 100.8/111.8 ms, with overlapping 91.2–131.2/86.6–129.8 ms ranges. This noisy local workload is not a guarantee for real storage or production SQL.

The merge was checked against the then-current main; CI for the updated head is still pending. A FileService that ignores cancellation can delay in-flight work, a final unbound cleanup failure can leave orphaned objects if its retry owner is dropped, and existing shared compression arenas may retain scratch across reuse until the arena is discarded or idle-reaped. The tests do not establish crash recovery or multi-CN behavior.

Rebased onto main at 781ebc03d905d646c38a1699488cb80e3288ecb1. The upstream stamped sequence identity handling is retained, along with the PR's compiler expiry arbitration; the equivalent upstream regression replaces the duplicate test extension. On the rebased source, the function, compiler and process packages passed race tests, the affected sequence controls passed in normal mode, and incremental gofmt, vet, molint and golangci passed for the 10 changed Go packages.

One initial local compiler race run on a small /tmp tmpfs failed a group spill budget check; the full package passed when rerun with its temporary files on the larger root filesystem. The isolated test passed on either filesystem, so the trigger for that particular spill was not established. New-head CI must run separately.

@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/XXL Denotes a PR that changes 2000+ lines label Nov 4, 2026
@mergify mergify Bot added kind/bug Something isn't working kind/enhancement kind/documentation Improvements or additions to documentation kind/test-ci kind/refactor Code refactor labels Nov 4, 2026
@XuPeng-SH
XuPeng-SH force-pushed the codex/32146-main-cn-spill branch from 5c9963a to d7f1230 Compare November 4, 2026 22:25
@XuPeng-SH

XuPeng-SH commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: d7f12309d30aeed1b11281d993df27b791ec3cd9

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: d7f12309d30aeed1b11281d993df27b791ec3cd9

Assessment: approve

The byte budget, block layout, cleanup ownership and reconnect handshake are coherent. Added accounting reuses existing vector, sinker and workspace capabilities; no actionable defects remain.

Model: gpt-6.1-sol / max

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

Validation:

  • Isolation preflight and native build from frozen inputs passed.

  • 46 focused tests and 1,291 tests across seven complete race suites passed.

  • Twelve concurrency tests each passed 100 race repetitions. Reconnect integration passed normally and twice with race detection and scoped coverage.

  • Independent base/head writer controls confirmed the budget in four modes. Isolated SQL validation passed 34 statements and 14 expected result sets.

  • go vet, formatting and whitespace checks passed. Claims reconcile with 28 receipts and retained logs in review-validation.json.

Limitations:

  • Captured CI was still running.

  • Author-reported performance and peak-memory benchmarks were not independently repeated.

  • The logical budget permits a single oversized row and excludes total pipeline, arena and process memory.

  • Validation used one CN. Cancellation requires FileService cooperation; terminal unbound cleanup failure may leave orphaned objects.

@XuPeng-SH

XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: cfd32c6aabb8ec8b28d41bdf097cde7044bb8f8c

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: cfd32c6aabb8ec8b28d41bdf097cde7044bb8f8c

Assessment: approve

No actionable findings. Byte accounting and cleanup state preserve block layout and publication ownership while reusing existing sinker, pool and workspace mechanisms. Reconnect and sequence error selection are coherent.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all 35 changed files, linked issue #32146 and all 13 discussion entries.

  • Compared prior reviewed revisions and reused applicable spill/reconnect package, race, SQL and performance reports for unchanged paths.

  • Preflight, Go 1.27.1 bootstrap, frozen-input native build, formatting and source-integrity checks passed.

  • Five sequence regressions passed normally and under race; each also passed 100 individual race repetitions.

  • All 14 local receipts and retained logs reconcile in validation-ledger.json.

Limitations:

  • Captured current-head CI remained pending. Full package, SQL and workload runs were reused from supplied reports rather than independently repeated.

  • The soft budget permits an oversized row and excludes total pipeline, arena and process memory. Cancellation requires filesystem cooperation; dropping a failed unbound cleanup owner can orphan objects.

  • Existing SQL evidence covers one CN; crash recovery and multi-CN behavior are not established.

This branch was successfully deployed

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

Labels

kind/bug Something isn't working kind/documentation Improvements or additions to documentation kind/enhancement kind/refactor Code refactor kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bound oversized CN spill blocks and memory for large variable-length updates

5 participants