Skip to content

fix(vector): preserve Area on admission failure for 4.2-dev - #28369

Merged
mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
VioletQwQ-0:backport-area-ownership-4.2-dev-20260908
Sep 8, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:4.2-devfrom
VioletQwQ-0:backport-area-ownership-4.2-dev-20260908

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

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 #27968. Partial backport of #27999; not an automatic issue-closure request.

What this PR does / why we need it:

Backport only the Area ownership fix from upstream commit 17c161a31b47a22e71ca222839143f66717ac365 to 4.2-dev. A rejected growArea2 does not release the old allocation. Receive its result into a temporary slice and publish v.area only on success, preserving the owner for normal cleanup.

No budget/admission policy, HashJoin cleanup mechanism, public API, MergeTop error classification, or compiler rewrite is changed.

Review fixes

  • Separate the retained Area slice (ownership/last-resort cleanup) from bytes.Clone snapshots (old bytes and logical row values). Assert row counts and appended values. Explicitly preserve the pre-existing UnionOne control's length-on-error behavior; this PR does not promise atomic append for that API.
  • Check production account/live-allocation and HashJoin budget usage before any test-only orphan reclamation. Zero-length/non-zero-capacity reused Areas retain ownership.
  • Widen the ordinary large-LIMIT fixture above the 23-byte inline threshold. It is explicitly success-path coverage, not evidence of budget-denial cleanup or an unbackported compiler rewrite.
  • Add test/distributed/isolated/area_admission/hashjoin_area.sql/.result and instructions. On a dedicated single-CN service with the public processLimitationSize=8388608, the same HashJoin query first sees 8,192 64-byte strings, then 8,192 2,048-byte strings. Check its physical HashJoin plan before adding the large batch (EXPLAIN PHYPLAN executes), reject the later growth, then check COUNT on the original connection and a new session. This configuration-specific fixture is deliberately outside the default BVT cases and must be run separately in QA.

Validation

Base: 588295fdabe01fbee49f48107dff98dcc26b6178.
Reviewed head: c7b726705276fca696afa3ce4e9a74f0eca94e77.

  • Same final Vector/HashJoin targeted regressions, -count=10: original product hunk restored to base => FAIL (exit 1); repaired => PASS. Failure is real production cleanup residue, not test double-free.
  • Two complete packages with controlled mo-cgo-test -v -count=1 -timeout=120s: PASS.
  • Targeted -race -count=10 -timeout=240s: PASS.
  • go list, go build, go vet for both packages, formatting and git diff --check: PASS.
  • Official mo-tester comparison mode, isolated SQL, identical fixture/config (autoReconnect=false): unpatched => exit 1, 11/15 successful with one mismatch and three admission-related abnormal results; repaired => exit 0, 15/15. Red SQL records used=524288, owner=1, site=103, live-allocations=1, followed by suspended new-session admission. Green returns the ordinary budget error without an invariant suffix, and both COUNT queries return 16384.
  • Official mo-tester comparison mode, widened normal large-LIMIT case: exit 0, 19/19.
  • Exact-content semantic preflight: PASS. Product executables differ only by the Area ownership hunk (test/doc-only follow-up changes do not enter the service binary).

The previous head's CI passed; that is not a claim about this new head's CI. Current-head CI and maintainer review remain independent gates. Ready for review is not merge approval.

QA required: yes

Reason: production memory ownership and admission recovery require deployment validation. Run the isolated 8 MiB regression separately, then verify actual deployed SHA and fresh-session admission before restarting the FULLTEXT2 campaign. Local tests do not prove shared-dev recovery or complete FULLTEXT2 acceptance. No shared dev objects were changed for this validation.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 8, 2026
@mergify
mergify Bot requested a review from XuPeng-SH September 8, 2026 03:29
@mergify mergify Bot added the kind/bug Something isn't working label Sep 8, 2026
@VioletQwQ-0 VioletQwQ-0 added the size/S Denotes a PR that changes [10,99] lines label Sep 8, 2026
@VioletQwQ-0 VioletQwQ-0 removed the size/S Denotes a PR that changes [10,99] lines label Sep 8, 2026
@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head c7b7267 against 4.2-dev base/merge-base 588295f: APPROVE for the scoped Area-ownership backport.

Read every changed hunk across all eight files and traced unionBatchContiguousVarlenRange -> growArea2/growOwned -> MPool.Grow/reAllocWithDetailK -> Vector.Free, plus HashJoin Call/emptyProbe -> Reset/Free -> result-batch cleanup. The sole production hunk exactly matches upstream 17c161a. Allocation failure leaves the old allocation live; retaining v.area until growth succeeds preserves its destruction owner. Successful growth frees the old allocation before returning the replacement, which is then published once. Existing rows/length are untouched at this failure boundary because descriptor copying and length advancement occur afterward. Zero-length/nonzero-capacity Areas remain freeable by capacity and pointer.

The tests distinguish ownership aliases from cloned byte/value snapshots, cover success and denial with existing/reused Area plus selected/Append/UnionOne controls, and explicitly avoid promising atomic UnionOne append. The HashJoin fixture exercises real budget admission, result reuse and normal terminal cleanup. Both fixtures inspect account/live-allocation/budget state and subsequent admission before any test-only orphan reclamation, so cleanup cannot turn the original production leak into a passing oracle.

Q1: the vector remains the effective Area owner on failure, and HashJoin terminal cleanup reaches that owner. Q2: no new wait, lock, goroutine or cancellation protocol is introduced. Q3: no budget/admission policy is weakened or new retained state added; failed growth no longer strands accounted capacity. The successful hot path keeps the same allocation/copy work. This ordinary focused ownership fix does not require a new feature design; it changes no public/wire/catalog/storage format, tenant boundary or compiler algorithm.

Validation checked: current-head MatrixOne ALL CI 34195497999 succeeds (the earlier cancelled run is superseded), git diff --check passes, and its actual multi-CN pessimistic BVT log records merge_top_large_limit.sql 19/19 successful in 0.403s. The new 8 MiB isolated HashJoin admission fixture is correctly outside default CI and explicitly requires a disposable single-CN service and no JDBC auto-reconnect; its author-reported red/green and focused normal/race runs are not claimed as my own executions. The normal wide-varlen BVT is success-path coverage, not evidence of denial recovery or the omitted compiler rewrite.

No verified blocker found. Deployment QA should still execute the isolated admission/recovery case and verify the deployed SHA/fresh-session admission before resuming FULLTEXT2. This approval does not close the broader campaign or claim the other #27999 changes were backported.

@mergify mergify Bot added the queued label Sep 8, 2026
@mergify

mergify Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-08 07:29 UTC · Rule: release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-08 07:30 UTC · at 027194e3ac2a41226059116ccb61d1432410edde · squash

This pull request spent 15 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit 027194e into matrixorigin:4.2-dev Sep 8, 2026
39 of 46 checks passed
@mergify mergify Bot removed the queued label Sep 8, 2026
XuPeng-SH added a commit that referenced this pull request Oct 20, 2026
Keep the owned varlen area until Grow2 succeeds so allocation rejection
cannot orphan the previous native buffer. Preserve the successful copy
path and allocation policy.

Cover populated and reused-empty destinations, ordinary cleanup and
retry after releasing memory pressure. The real MergeOrder execution
failure probe now drains native memory after Reset/Free.

Port the ownership correction already present in 4.2-dev via #28369.
XuPeng-SH added a commit that referenced this pull request Nov 4, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to #27968. Cherry-picks the Area ownership fix from #28369
(`027194e3ac2a`) to the 4.2.1 hotfix branch.

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

When bulk appending variable-length Vector data, an allocation or budget
rejection can return a nil Area while the previous Area is still
allocated. Assigning that result directly to the Vector loses the only
cleanup reference. HashJoin can then finish with a nonzero allocation
account and suspend later account admission on the same CN.

Keep the existing Area until growth succeeds. The conflict was resolved
in the 4.2.1 branch's existing `UnionBatch` fast path; allocation
policy, error classification, and successful copy behavior are
unchanged. The original PR's tests and SQL fixtures are included. A
test-only follow-up replaces unsafe pointer inspection with guarded
slice access while retaining the zero-length/nonzero-capacity ownership
check.

Validation on the 4.2.1 base `d8286add2798`, macOS arm64 and Go 1.26.4:

- Before the fix, Vector and real HashJoin admission tests reproduced a
4096-byte live allocation and suspended next admission. With the fix,
both pass with zero live bytes and usable next admission;
successful-growth controls pass.
- Full Vector and HashJoin packages passed normally and with race; final
adapted regression tests passed normally and with race.
- With an isolated single-CN 8 MiB budget, the same HashJoin
SQL/physical plan reproduced a 524288-byte account invariant and
suspended admission on the base. The fixed candidate returned the
ordinary budget error and both existing and new connections returned the
expected 16384-row count.
- The picked default mo-tester case passed 19/19 twice on the same
isolated instance with teardown checked. The picked 8 MiB isolated
SQL/result passed 15/15 in mo-tester comparison mode with teardown
checked.
- Incremental formatting, vet, golangci-lint and repository error checks
passed. Molint has no findings in the changed files; its output still
includes one pre-existing `checkunsafe` diagnostic in
`pkg/container/vector/functionTool_test.go`.

The reported customer incident has not yet been tied to this exact SQL
path. GitHub CI and validation on the deployed image are pending.

---------

Co-authored-by: 和光同尘 <[email protected]>
@VioletQwQ-0
VioletQwQ-0 deleted the backport-area-ownership-4.2-dev-20260908 branch December 1, 2026 03:47

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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants