Skip to content

fix: release opaque aggregate spill state on reuse - #28925

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/issue-28853-opaque-spill
Sep 16, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/issue-28853-opaque-spill

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 15, 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:

issue #28853

What this PR does / why we need it:

Accounted opaque aggregate states (HLL, approximate percentile, and bitmap)
are independently allocated through the aggregate allocation account. During
spill reload, a reusable aggState can replace its physical vectors while
overwriting mobs entries. The old state, including entries beyond a smaller
incoming record, was therefore left owned by the account and caused
allocation account still owns memory at terminal cleanup.

This change releases every previous opaque state before a reusable spill record
is decoded, clears all slots, and retains the existing full cleanup path for
zero-row, non-reuse, and decode-error exits. The release scan is bounded by one
aggregate work unit and does not add work to resident or non-opaque aggregates.

Regression coverage exercises same-size replacement, replacement with a
smaller record, nil/empty rows, truncated decode failure, and zero-row reset for
HLL, approximate percentile, and bitmap states. The group operator test also
compares resident and forced-spill results across the supported aggregate
families and requires actual reloads for the spill run.

Test plan

  • mo-cgo-test -v -count=1 -timeout=180s -run '^TestAccountedOpaqueSpillStateReplacementReleasesPreviousState$' ./pkg/sql/colexec/aggexec
  • mo-cgo-test -v -count=1 -timeout=180s -run '^TestAccountedSupportedAggregateFamiliesResidentAndSpillMatch$' ./pkg/sql/colexec/group
  • mo-cgo-test -count=1 -timeout=300s ./pkg/sql/colexec/aggexec
  • mo-cgo-test -count=1 -timeout=300s ./pkg/sql/colexec/group
  • The same focused tests and owning packages with -race
  • Incremental gofmt, go vet, golangci-lint --new-from-rev, and git diff --check

The failed checks in run
34938291815 are not caused by this change: the first Ubuntu UT failed while
starting the shared embedded cluster before reaching its SQL assertion, the
following failures were admission-cascade errors, and coverage failed during
the Java 8 setup download before a profile was produced. These are tracked by
#28763/#27822 and are not papered over in this PR with sleeps, retries, skipped
tests, or timeout inflation.

@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

Copy link
Copy Markdown
Contributor Author

Rebased the feature commit cleanly onto current main (1d7d425f6cd955d670cbd04b5b49ab7b682206d) and pushed as a0dfd5d13b48f181964c5e71043cc0fcdb15b962. The stable patch-id is unchanged.

The red checks in run 34938291815 were investigated at the exact old head:

  • Ubuntu UT first failed in TestHashBuildSharedBudgetRecoverySQL while the shared embedded cluster was still starting, after a 58.755s admission wait; it never reached the SQL/spill assertion. The next tests failed the same in-process admission gate (another complete test cluster is already active). The runner showed oom=0/oom_kill=0.
  • UT Coverage timed out downloading the Java 8 Adopt toolchain before producing a coverage profile; the aggregate coverage job then had no producer artifact.

These signatures are base/CI lifecycle and setup failures already tracked by
#28763/#27822, not regressions in this PR. The rebased PR-specific focused
tests and owning packages pass in normal and race modes; no sleep, retry,
skip, timeout inflation, or test weakening was added to hide the infrastructure
failure.

@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 结果(当前 head 74bf487):

未发现 production ownership 路径的 confirmed correctness defect;replacement/reuse、double-free/UAF、error/cancel/retry、growth/accounting 路径均通过审查。

P2:partial-decode cleanup 测试覆盖不足。pkg/sql/colexec/aggexec/allocation_account_test.go:789-794 的 first[:len(first)-1] 只截断 8-byte trailer,两个 opaque state 已在失败前完成 decode,无法检测 partial opaque allocation/decoding 过程中的泄漏。请保留 trailer case,并对三个 family 增加截断第二个 opaque payload 的测试;断言 allocation account 回到 baseline、group count 为零、后续 decode 成功且 terminal cleanup 完整释放。

Exact-head CI 通过;本地 focused test 因 CGo prerequisite/provenance check 在编译前失败,未运行。

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

在 exact head 74bf487 上完成 deep review,未发现阻塞问题。重点核对了 reusable spill decode 前的旧 opaque owner 释放、同尺寸/缩小/空记录替换、decode error 的外层 ae.Free() 回收、mobs 指针清零防止 stale result/double free,以及 HLL/approx-percentile/bitmap 在 group spill/reload 下的 allocation-account 闭环。focused aggexec/group 回归在 CGO + 本地 thirdparties 环境下普通模式和 -race 均通过;当前 head 与 current main 的 merge-tree 也无冲突。

@mergify

mergify Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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

Force deep review 结果(当前 head 74bf487):

P2:此前 partial-decode 测试缺口仍未修复。pkg/sql/colexec/aggexec/allocation_account_test.go:789-797 只截断最后 8-byte trailer;两个 opaque payload 在失败前都已完成 decode,因此无法检测 payload 中途失败时的泄漏。

请保留 trailer case,并针对 HLL、approximate percentile、bitmap 三类,在第二个 payload 内部截断且发生 allocation 后失败;断言 explicit Free 前 allocation account 已回到 baseline、group count 为零、后续 decode 成功,最终 cleanup 完整释放。现有 decoder tests 不能证明 replacement/failure/reuse 的组合契约。

审查到的 ownership/accounting、shrinking/nil replacement、retry/cancel/pooling、double-free/UAF/leak/OOM 和 concurrency 路径未发现额外 confirmed production defect。Exact-head required CI 通过;本轮未运行本地测试。

@XuPeng-SH
XuPeng-SH merged commit 66b1672 into matrixorigin:main Sep 16, 2026
14 of 18 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/issue-28853-opaque-spill branch September 16, 2026 06:53
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#28853

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

Accounted opaque aggregate states (HLL, approximate percentile, and
bitmap)
are independently allocated through the aggregate allocation account.
During
spill reload, a reusable `aggState` can replace its physical vectors
while
overwriting `mobs` entries. The old state, including entries beyond a
smaller
incoming record, was therefore left owned by the account and caused
`allocation account still owns memory` at terminal cleanup.

This change releases every previous opaque state before a reusable spill
record
is decoded, clears all slots, and retains the existing full cleanup path
for
zero-row, non-reuse, and decode-error exits. The release scan is bounded
by one
aggregate work unit and does not add work to resident or non-opaque
aggregates.

Regression coverage exercises same-size replacement, replacement with a
smaller record, nil/empty rows, truncated decode failure, and zero-row
reset for
HLL, approximate percentile, and bitmap states. The group operator test
also
compares resident and forced-spill results across the supported
aggregate
families and requires actual reloads for the spill run.

## Test plan

- `mo-cgo-test -v -count=1 -timeout=180s -run
'^TestAccountedOpaqueSpillStateReplacementReleasesPreviousState$'
./pkg/sql/colexec/aggexec`
- `mo-cgo-test -v -count=1 -timeout=180s -run
'^TestAccountedSupportedAggregateFamiliesResidentAndSpillMatch$'
./pkg/sql/colexec/group`
- `mo-cgo-test -count=1 -timeout=300s ./pkg/sql/colexec/aggexec`
- `mo-cgo-test -count=1 -timeout=300s ./pkg/sql/colexec/group`
- The same focused tests and owning packages with `-race`
- Incremental `gofmt`, `go vet`, `golangci-lint --new-from-rev`, and
`git diff --check`

The failed checks in run
`34938291815` are not caused by this change: the first Ubuntu UT failed
while
starting the shared embedded cluster before reaching its SQL assertion,
the
following failures were admission-cascade errors, and coverage failed
during
the Java 8 setup download before a profile was produced. These are
tracked by
matrixorigin#28763/matrixorigin#27822 and are not papered over in this PR with sleeps, retries,
skipped
tests, or timeout inflation.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue matrixorigin#28853

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

Accounted opaque aggregate states (HLL, approximate percentile, and
bitmap)
are independently allocated through the aggregate allocation account.
During
spill reload, a reusable `aggState` can replace its physical vectors
while
overwriting `mobs` entries. The old state, including entries beyond a
smaller
incoming record, was therefore left owned by the account and caused
`allocation account still owns memory` at terminal cleanup.

This change releases every previous opaque state before a reusable spill
record
is decoded, clears all slots, and retains the existing full cleanup path
for
zero-row, non-reuse, and decode-error exits. The release scan is bounded
by one
aggregate work unit and does not add work to resident or non-opaque
aggregates.

Regression coverage exercises same-size replacement, replacement with a
smaller record, nil/empty rows, truncated decode failure, and zero-row
reset for
HLL, approximate percentile, and bitmap states. The group operator test
also
compares resident and forced-spill results across the supported
aggregate
families and requires actual reloads for the spill run.

## Test plan

- `mo-cgo-test -v -count=1 -timeout=180s -run
'^TestAccountedOpaqueSpillStateReplacementReleasesPreviousState$'
./pkg/sql/colexec/aggexec`
- `mo-cgo-test -v -count=1 -timeout=180s -run
'^TestAccountedSupportedAggregateFamiliesResidentAndSpillMatch$'
./pkg/sql/colexec/group`
- `mo-cgo-test -count=1 -timeout=300s ./pkg/sql/colexec/aggexec`
- `mo-cgo-test -count=1 -timeout=300s ./pkg/sql/colexec/group`
- The same focused tests and owning packages with `-race`
- Incremental `gofmt`, `go vet`, `golangci-lint --new-from-rev`, and
`git diff --check`

The failed checks in run
`34938291815` are not caused by this change: the first Ubuntu UT failed
while
starting the shared embedded cluster before reaching its SQL assertion,
the
following failures were admission-cascade errors, and coverage failed
during
the Java 8 setup download before a profile was produced. These are
tracked by
matrixorigin#28763/matrixorigin#27822 and are not papered over in this PR with sleeps, retries,
skipped
tests, or timeout inflation.

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