Skip to content

[4.2-dev] fix(window): retire inherited buffers at prepared reset - #31127

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/issue31089-42
Oct 25, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/issue31089-42

Conversation

@XuPeng-SH

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 #31089.

What this PR does / why we need it:

Release Window-owned inherited account buffers at prepared Reset on 4.2-dev. This narrowly adapts main's existing cleanup policy without backporting its accounting migration or changing release's window result representation.

Cause and invariant

Window can copy HashJoin output while inheriting its allocation account. Prepared execution ends through Reset, so clearing logical lengths is insufficient: all backing owned by the ending account must be released before account terminal completion. Ordinary execution additionally calls Free and can hide this lifetime defect.

Regression coverage

  • Three-row self JOIN feeding an unpartitioned cumulative SUM, with equivalent literal and uniform-partition controls.
  • Reuse the same binary prepared handle with changed parameters, empty results, and a subsequent nonempty execution; verify connection usability afterward.
  • Operator coverage checks two fresh account generations, current allocation selections, terminal used/live-allocation zero before Free, cancellation after buffering, direct Free, partial aggregation failure, and unaccounted buffer reuse.
  • Compact SQL PREPARE BVT covers ROWS, default RANGE, changed parameters, DEALLOCATE and database teardown.

Production change and cost

Reuse the existing allocation-selection authority to detect inherited account backing. Release owned input and expression copies, nil freed slots before reuse, and detach borrowed result-wrapper references without cleaning their payload twice. Preserve the legacy aggregate-result cleanup and retain reusable unaccounted buffers.

The change adds a vector-slot scan at Reset and retires account-bound backing at its required terminal boundary. It adds no per-row evaluation, copying, I/O, goroutines, retries or new accounting state. Accounted prepared executions allocate fresh backing for each account generation; unaccounted buffer reuse is unchanged. No disk, catalog, wire or configuration format changes.

Validation

  • Matching native artifacts and branch toolchains (main: Go 1.27.1; 4.2-dev: Go 1.26.4).
  • On the rebased head, the original 206-row fixture succeeds in all three execution modes: 202 result rows, identical SHA-256. The reduced binary-prepared regression also passes.
  • Window normal UT and allocation/error/cancellation race coverage pass. Release also passes the full owning Window package under race; the binary-prepared public regression passes under race on each branch.
  • Standard mo-tester comparison passes twice on the same test-owned embedded instance: 22/22 SQL statements, zero failures/ignored statements per run. Independent connections verify database teardown after each run. This is the new window case, not the full BVT suite.
  • gofmt, go vet, molint and incremental golangci-lint v2.14 pass for the changed packages and their public-test consumer.

The final rebase preserves the reviewed Window/lifecycle and regression files byte-for-byte. Operator race and SQL BVT evidence is reused; original/reduced prepared acceptance and static checks were rerun on the rebased heads. GitHub CI is pending.

The full affected-package golangci scan reports four baseline warnings (three prealloc, one sqlclosecheck) in issue_26121_test.go and issue_29399_test.go. Both files are byte-identical to the target base. The incremental scan uses --new-from-rev with --whole-files, checks all changed files, and passes; full affected-package vet and molint pass.

One local attempt timed out during tester/shared-cluster initialization before regression SQL execution under host I/O and swap pressure. The recorded bounded retry passed; production code, fixture policy and timeout budgets were not relaxed.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner October 25, 2026 15:22
@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 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 48b3174d8bd52c619ebb0ce92a46edae73da05cb

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: 48b3174d8bd52c619ebb0ce92a46edae73da05cb

Assessment: approve

Reviewed the complete six-file delta and cleanup callers. Window correctly releases account-bound copies at Reset, detaches borrowed references, and preserves unaccounted buffer reuse. The design retains existing ownership and accounting authorities. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Reconciled commands, source fingerprints, exit receipts and logs in /home/xupeng/.local/state/mo-bot/jobs/0b5c8715f62181d48fadd199/attempt-1/receipt-audit.json. Isolation preflight and native builds from matching source inputs passed.

  • Focused regressions passed. Restoring only the base cleanup implementation reproduced retained-account failures after cancellation and aggregation errors.

  • All 77 top-level Window tests passed under race detection; both focused regressions passed 100 race repetitions each.

  • Binary-prepared integration passed normally, under race detection, and across two race repetitions, covering changed parameters, empty/nonempty reuse and connection usability.

  • The committed SQL fixture passed 22/22 statements twice through the embedded server's MySQL interface, including golden results and independent teardown verification.

  • Vet, formatting, diff and native-provenance checks passed. Source remained unchanged. Added work is confined to Reset-time vector cleanup; no per-row work was added.

Limitations:

  • Frozen CI was pending. The author's original 206-row fixture and broader validation claims lacked retained receipts and were not counted as verified.

  • SQL fixture validation used a diagnostic Go overlay, not standard mo-tester. No broad repository suite or performance benchmark was run.

  • The linked issue body was absent from frozen evidence; its stated contract was assessed through the PR description, source and regression fixtures.

@XuPeng-SH
XuPeng-SH merged commit 86a45d3 into matrixorigin:4.2-dev Oct 25, 2026
47 of 51 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue31089-42 branch October 25, 2026 17:06
XuPeng-SH added a commit that referenced this pull request Nov 4, 2026
…#32112)

## 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 #31089. Backports the Window lifecycle fix from #31127 to the
4.2.1 hotfix branch.

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

A prepared JOIN followed by a Window can leave account-owned input and
expression buffers alive after execution. Window Reset clears their
logical data but retains their backing, so allocation-account
finalization reports an invariant failure and suspends admission for
subsequent account-owning queries on the same CN.

Release the Window-owned buffers belonging to an allocation account at
Reset, detach the result wrapper's borrowed references, and clear freed
expression slots. Continue reusing unaccounted buffers. The change scans
Window's buffered vector slots at Reset; it does not add per-row work or
change account admission policy.

On base `87866e6d2822`, a three-row prepared JOIN with an unpartitioned
cumulative SUM reproduced `allocation account invariant failure` (48
bytes, four allocations); a subsequent JOIN failed with `allocation
account admission is suspended`. A direct Window/registry control
reproduced the same transition and showed that freeing Window's retained
buffers releases the suspension. The user's incident has not yet been
correlated with this specific query shape.

Validation on macOS arm64, Go 1.26.4, with native libraries built from
this hotfix source:

- Full Window package normal and race tests.
- Public prepared SQL regression normal and race: literal and prepared
JOIN/window queries, repeated and empty executions, result equality, and
new connection authentication.
- Window account regression: partitioned and unpartitioned execution,
cancellation, direct Free, two generations, and unaccounted buffer
reuse.
- Incremental formatting, vet, repository error checks, molint and
golangci-lint for the affected packages.

GitHub CI is pending. The standalone customer workload and Linux runtime
have not been tested in this local run.

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

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.

2 participants