Skip to content

refactor(vector): remove allocation_account.go; accounting belongs to mpool - #33054

Merged
fengttt merged 7 commits into
matrixorigin:mainfrom
fengttt:vector-alloc-file-out
Nov 22, 2026
Merged

fengttt merged 7 commits into
matrixorigin:mainfrom
fengttt:vector-alloc-file-out

Conversation

@fengttt

@fengttt fengttt commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Remove pkg/container/vector/allocation_account.go and allocation_account_test.go. Memory accounting is mpool's responsibility; vector now allocates and grows through mpool directly.

mpool contract changes

  • Views always charge. Alloc, Grow and ReallocZero through an accounted view (WithAccount) are always off-heap and charged, regardless of the caller's offHeap argument. Previously an on-heap request through a view went to the Go heap uncharged, so vector had to force off-heap itself.
  • Nil pool. Alloc/Grow on a nil *MPool return an internal error instead of panicking.
  • Limit errors unchanged. mpool's size-limit errors stay plain moerr (moerr.IsMoErrCode does not unwrap). Vector's grow path returns ErrAllocationAllocatorLimit itself before calling mp.Grow, as the removed growOwned did.

vector changes

  • allocData / allocArea / allocOwned removed; callers use mp.Alloc(n, offHeap).
  • growData / growArea materialize a borrowed backing, then call mp.Grow.
  • allocationAccountInvalid replaced by plain moerr internal errors (these were vector invariant checks).
  • Bitmap capacity helpers drop their unused mp parameter; vector-only helpers (readSizeBytes, stream size validation, backing-storage checks, bitmap helpers) move to vector.go.
  • Test fixtures still used by 14 other vector test files move to mpool_view_fixtures_test.go.

Tests

The 42 tests in allocation_account_test.go are deleted. TestMPoolAccountedView is updated for the new charging rule. Passing locally: pkg/common/mpool, pkg/container/..., pkg/objectio/..., pkg/sql/colexec/..., pkg/sql/plan/..., pkg/sql/compile, pkg/sql/util/..., pkg/vm/engine/readutil, pkg/vm/engine/disttae, pkg/vm/engine/tae/blockio, pkg/vm/process, pkg/vectorindex/....

Append tests and appendList

  • appendList no longer falls back to a forward loop when the input overlaps the destination; it always uses copy (memmove). Previously an input taken from the vector's own unused capacity was smeared (every row became the first value), and a test asserted that. It is now appended as it was before the call.
  • The six append_*_test.go files become append_test.go and append_bench_test.go. Dropped: the short-mask panic test (pinned undefined partial state) and the element-width test. The pre-grow rollback test now fails on a capped mpool instead of an allocation-account view. TestConstNullCleanAndUnionBatch moves to unionbatch_fastpath_test.go.

🤖 Generated with Claude Code

… mpool

Delete pkg/container/vector/allocation_account.go and its test file.
Vector no longer makes accounting decisions; callers allocate and grow
through mpool directly.

mpool now owns the rules the vector helpers used to enforce:
- an accounted view charges every allocation (Alloc/Grow/ReallocZero are
  forced off-heap through a view, regardless of the caller's offHeap);
- Alloc/Grow on a nil pool return an error instead of panicking;
- size-limit and grow-overflow failures carry ErrAllocationAllocatorLimit.

The remaining vector-only helpers (bitmap capacity, borrowed-backing
materialization, stream size validation) move into vector.go. Shared test
fixtures used by other vector tests move to mpool_view_fixtures_test.go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 →

@mergify

mergify Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

appendList fell back to a forward loop when the input overlapped the
destination, only to reproduce the old smearing result (a test asserted
every row became the first value). copy is memmove, so always copy: an
overlapping input is now appended as it was before the call.

Tests:
- merge append_list_fastpath_test.go and append_varlen_pregrow_test.go
  into append_test.go; the aliased-input test now asserts the input values;
- drop the short-mask panic test (pinned undefined partial state) and the
  element-width test (copy does not depend on width);
- rename the guards test to TestAppendVarlenListSlowPath, since its cases
  never reach the pre-grow path, and run it on a plain mpool;
- fail the pre-grow rollback test on a capped mpool instead of an
  allocation-account view;
- move TestConstNullCleanAndUnionBatch to unionbatch_fastpath_test.go;
- merge the three append benchmarks into append_bench_test.go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Joining ErrAllocationAllocatorLimit onto mpool's size-limit errors broke
callers that check the moerr code: moerr.IsMoErrCode type-asserts and does
not unwrap, so TestWriteArena saw a non-ErrInternal error.

Restore mpool's errors as on main. Vector's grow path types the failure
itself, as the removed growOwned did: a size past GrowCapacity returns
ErrAllocationAllocatorLimit before calling mp.Grow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test cancelled its context with defer, which runs before t.Cleanup, and
derived it from t.Context(), which is cancelled before cleanups. The proxy
runs on that context, so it could drop its connections before the
db.Close cleanups ran; db.Close then failed with "bad connection"
(seen in the UT coverage run). Derive ctx from context.Background() and
cancel it in the first-registered cleanup, so it runs last.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XuPeng-SH

XuPeng-SH commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 821ac34bca2708534a137dc0741c2a66ddb0e09c

task canceled or execution/log limit exceeded

@fengttt
fengttt merged commit 22fb08a into matrixorigin:main Nov 22, 2026
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 22, 2026
Take matrixorigin#33054's file removals and consolidated append tests. The vector
helpers keep this branch's strict owner-pool form (checkMP); the per-site
allocData/allocArea/allocOwned wrappers collapse into one alloc, and
growOwned no longer classifies growth failures as allocation-account
errors. Port the merged tests to NewVec(typ, mp); drop output_lease_test.go
(the scan owns its output pool on this branch) and the resurrected
borrowed_helpers_test.go. Fix the SCA unsafe import in
mpool_contract_test.go and the typecheck-tagged NewVec call.

This branch was successfully deployed

No deployments
ci — fbb6df14 Deployed Nov 22, 2026 by fengttt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants