Skip to content

fix(objectio): bound pooled serialization buffers - #29432

Merged
XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29384-arena-retention
Sep 28, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-29384-arena-retention

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement

Which issue(s) this PR fixes:

Fixes #29384

What this PR does / why we need it:

Object writers reuse a Go-heap serialization buffer through WriteArena. A large column can grow it once, after which a busy arena keeps that capacity across smaller write cycles; the arena pool's idle timeout does not reclaim a continuously reused arena.

Bound retained serialBuf capacity at 16 MiB when an arena enters the pool. Within a long-lived merge or sinker, Reset keeps a large buffer while successive objects still need it, then releases it after a smaller cycle. Explicit arena destruction also drops the buffer. The writer now uses one exact vector marshal plan to size and encode each column, avoiding allocation based on Vector.Size()'s approximate memory accounting. The column format and chunked policy are unchanged.

Raise the large arena's off-heap data growth limit from 128 MiB to 200 MiB, as requested. This allows a large write cycle to reuse a larger arena on its next cycle but can retain up to 72 MiB more off-heap data per large arena. The existing Reset growth path can allocate after a completed cycle, including on final cleanup; a larger limit increases that allocation-pressure exposure. This PR does not change that lifecycle.

Add mo_mem_objectio_pooled_serial_bytes to measure Go-heap serialization capacity parked in both arena tiers. It measures pool ownership, not active writers or off-heap buffers.

The 16 MiB parking limit bounds pooled serialization capacity to the pool's existing slot count. Repeated writes larger than 16 MiB across separate arena leases may reallocate; repeated large objects within one lease keep their buffer. Cross-lease churn throughput was not measured. A short comparison benchmark (Apple M4, Go 1.26.4, 8192-row int64 vectors, 3 runs) measured constant-vector pre-sizing at 73,796 → 132 B/op and ~2.25 µs → 0.108 µs/op; ordinary-vector timing was within observed noise (~2.83 µs/op) with unchanged allocation bytes. These are isolated serialization-path measurements, not full flush/merge throughput claims.

Validation: targeted arena retention, pool gauge/reap/count-cap, exact serialization and chunked round-trip tests; pkg/objectio and pkg/util/metric/v2 suites; sinker reset/cancel consumer tests; focused pool tests under race (-count=100) and full pkg/objectio race suite; go vet and incremental golangci-lint for affected packages.

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

Deep review of fb3c223ce6b6e4969296016407150383ea91eb9b against main/merge-base b9013dc6bb058ec74935a62ac3a35f57d13c2f98. Reviewed directly, without subagents.

Decision: no blocking findings; approve-level recommendation, with a measured performance tradeoff below. This is a COMMENT because the authenticated account owns the PR; it is not a formal GitHub approval.

Design and correctness:

  • The retention policy is owned by the existing arena lifecycle. PutArena enforces the 16 MiB parked-capacity limit even without a preceding Reset; Reset uses the maximum serialized column size of the completed cycle to preserve repeated large writes within a lease and release a disproportionate prior peak. FreeBuffers also releases serialization scratch. One per-cycle integer is sufficient; no extra cache, worker, or policy branch is needed.
  • PrepareMarshalBinary plus MarshalTo uses the same validated encoding path as the original MarshalBinaryWithBuffer. Computing the exact size before Grow preserves the format and chunked-policy behavior, and avoids approximate sizing for constant/selected vectors. Error propagation remains intact.
  • Pool accounting follows the existing locked ownership transitions: successful admission adds capacity, checkout/expiry subtract it, rejected admission adds nothing. The gauge has no labels and measures parked Go-heap capacity only.
  • The requested 128 → 200 MiB tuning is a separate off-heap budget choice. The previously disclosed final Reset allocation/panic exposure remains, including the possibility of growing immediately before a full pool frees the arena. This review does not claim that lifecycle was fixed or that total process RSS is bounded by the new serial-buffer limit.

Unhappy-path audit:

Check Traced boundary Outcome
Q1 ownership flush/merge/sinker → arena → pool admission or destruction → expiry Serial scratch is private to the borrowed arena; returning/evicting releases the relevant ownership. No new dangling reference or duplicate destruction found.
Q2 termination Get/Put/reap mutex and gauge update Added operations have no I/O, callback, or wait on writer progress. Expired buffers are freed after unlocking.
Q3 bounds pooled serial capacity and active-cycle reuse Pooled capacity is at most 16 MiB × existing slot limits; an active arena drops an obsolete large peak after a smaller cycle. Active demand and off-heap compression scratch are outside this gauge/bound.

Independent QA and performance evidence:

  1. Added a temporary overlay-only probe driving actual object writers with 8192-row varchar vectors. Large → large retained the same serialization backing storage; large → small released it on Reset; a malformed subsequent vector returned an error and released the obsolete peak; direct destruction released a live large buffer. PASS. These checks do not manually assign serialPeak.
  2. Ran the full pkg/objectio suite under -race -count=1 with that probe included: PASS, 10.977s. The PR worktree remains unchanged.
  3. Verified CI run 36384302857 completed successfully at the reviewed commit, including UT, coverage, SCA and the enabled BVT jobs. Unchanged CI evidence is reused for the remaining paths.
  4. Compared the actual writer/compression path against main using Go overlays of the original writer/pool sources and tests; original production source blob hashes were checked against main. Apple M4, Go 1.26.4, 8192-row varchar vectors, 3 × 300 ms; medians below. Data construction and warmup were excluded. Both variants use the same native libraries and benchmark. The fixture repeats a deterministic payload and is compressible; this is not a storage-I/O or end-to-end workload benchmark.
Payload / arena use Main time/object PR time/object Main → PR Go bytes/object
8 MiB, retain lease 1.115 ms 1.113 ms ~205,722 → ~205,722
8 MiB, return/reborrow each object 1.108 ms 1.112 ms ~205,725 → ~205,722
18 MiB, retain lease 2.431 ms 2.438 ms ~205,723 → ~205,723
18 MiB, return/reborrow each object 2.434 ms 2.758 ms ~205,723 → ~19,285,435

Non-blocking performance note: the last case is about 13% slower and allocates an additional ~18.2 MiB per object. It confirms the documented fixed parking-cap tradeoff: recurring wide-column short-lived flush/task workloads can increase allocator/GC pressure, while repeated large writes within the same merge/sinker lease preserve reuse. This should accompany the small-vector optimization numbers; the PR should not be described as an across-the-board throughput improvement. No threshold increase or extra adaptive mechanism is justified by this single microbenchmark.

Non-blocking test-quality suggestion: incorporate the real-writer large → large → small/error transitions into the existing retention test, replacing manual serialPeak setup where possible. This protects the connection between the writer's peak accounting and arena policy without another large test fixture.

Comment closure: there were no existing review records or inline comments, and the only issue comment was the Qodo paused notice. There are no prior technical comments on this PR to mark resolved.

@XuPeng-SH
XuPeng-SH merged commit 5648ebc into matrixorigin:main Sep 28, 2026
27 checks passed
XuPeng-SH pushed a commit that referenced this pull request Nov 10, 2026
)

## What type of PR is this?

- [x] BUG
- [ ] API-change
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #29384 (4.2-dev backport; main fix #29432)

## What this PR does / why we need it:

A Merge writer can grow WriteArena.serialBuf on the Go heap and leave
that large capacity parked in the arena pool after the task finishes.
Limit pooled serialization capacity to 16 MiB per arena before
publication, retain large scratch only while an active write cycle needs
it, and clear it on FreeBuffers. Add a pooled-capacity gauge with
accounting ordered before lock-free publication. No wire-format changes
or off-heap arena-size tuning.

Regression coverage includes a real object writer and two sequential
MergeObjects tasks in one TAE engine. Before the fix the writer retained
16,785,408 bytes and the Merge test observed 19,079,168 pooled bytes;
both tests pass with this patch. Build and vet passed for objectio,
metric, TAE jobs and DB consumers. Full objectio/metric normal and race
suites passed. Focused race stress passed for the new tests
(49/68/100/13 runs).

TAE package race passed in 134 s with only Test_RWDB4 excluded. The
unfiltered package timed out at 600 s in Test_RWDB4; that test also
timed out at 120 s both on this branch and on a clean 4.2-dev baseline
at 9dd4d33. This baseline timeout is an existing validation gap, not
a passing full-suite claim.

The cap trades occasional reallocation for bounded parked Go-heap
retention. The gauge may briefly overcount an arena between accounting
and CAS publication, but settles after the transfer.
aptend pushed a commit to aptend/matrixone that referenced this pull request Nov 22, 2026
…rixorigin#32454)

- [x] BUG
- [ ] API-change
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

issue matrixorigin#29384 (4.2-dev backport; main fix matrixorigin#29432)

A Merge writer can grow WriteArena.serialBuf on the Go heap and leave
that large capacity parked in the arena pool after the task finishes.
Limit pooled serialization capacity to 16 MiB per arena before
publication, retain large scratch only while an active write cycle needs
it, and clear it on FreeBuffers. Add a pooled-capacity gauge with
accounting ordered before lock-free publication. No wire-format changes
or off-heap arena-size tuning.

Regression coverage includes a real object writer and two sequential
MergeObjects tasks in one TAE engine. Before the fix the writer retained
16,785,408 bytes and the Merge test observed 19,079,168 pooled bytes;
both tests pass with this patch. Build and vet passed for objectio,
metric, TAE jobs and DB consumers. Full objectio/metric normal and race
suites passed. Focused race stress passed for the new tests
(49/68/100/13 runs).

TAE package race passed in 134 s with only Test_RWDB4 excluded. The
unfiltered package timed out at 600 s in Test_RWDB4; that test also
timed out at 120 s both on this branch and on a clean 4.2-dev baseline
at 9dd4d33. This baseline timeout is an existing validation gap, not
a passing full-suite claim.

The cap trades occasional reallocation for bounded parked Go-heap
retention. The gauge may briefly overcount an arena between accounting
and CAS publication, but settles after the transfer.

(cherry picked from commit c8264f1)

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/bug Something isn't working kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Object writer serialization buffers can remain unbounded in arena pool

2 participants