Skip to content

test: own inline process pools for test lifetime - #29678

Merged
XuPeng-SH merged 5 commits into
mainfrom
codex/quality-29249-owned-pools-20261008
Oct 8, 2026
Merged

XuPeng-SH merged 5 commits into
mainfrom
codex/quality-29249-owned-pools-20261008

Conversation

@XuPeng-SH

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

Refs #29249
Refs #29627

What this PR does / why we need it:

Tests that pass a fresh pool to NewProcessWithMPool leave its registration in globalPools after the process is freed. NewProcessWithMPool deliberately borrows supplied pools, so this PR adds a thin NewProcessWithOwnedMPool wrapper for exclusive test-lifetime ownership. Pool deletion is registered before process/file-service construction, giving caller cleanup -> process -> file service -> pool deletion. The existing constructor and failure cleanup paths are reused.

The migration follows the actual resource lifetime. Shared pools across child tests, repeated loops and the IVF load closure have one enclosing cleanup; their processes keep borrowing. Thus the first child cannot remove a pool that the next child still uses, and repeated constructors cannot register repeated pool deletion. Seventeen multiline inline fresh-pool calls in spillutil also use the owned helper. No production runtime behavior changes.

The supplied-pool fixture test checks exclusive ownership and on/off-heap caller cleanup. The existing borrowed fixture covers two sequential children and final parent deletion. Five real consumer tests assert that shared pools remain registered through child and process/file-service cleanup, then disappear at enclosing cleanup. The three redundant manual pool deletions in mergetop/order are removed. Shared and explicitly caller-managed pool lifetimes remain borrowed; nil testing.TB retains caller cleanup responsibility.

Validation

Current follow-up validation uses Go 1.27.1 on Linux/amd64, GOAMD64=v3, GOEXPERIMENT=simd and the repository CGo test wrapper with a complete native build:

  • Full normal and race UT for ./pkg/testutil, ./pkg/vm/engine/readutil, ./pkg/vectorindex/ivfflat, ./pkg/sql/colexec/spillutil: -p 1 -count=1, timeouts 180s/240s. All four packages passed in both modes; all 26 required top-level fixture/consumer/spillutil tests executed.
  • Six changed lifecycle tests each ran separately under race with -count=100; all passed. Counts were bounded from measured race durations with the repository's 30s budget/cap protocol.
  • Counterexample control: an external Go test overlay restored only the five erroneous owned constructors while preserving the new regression assertions. All five corresponding consumer tests failed; fixed code passed. The overlay is not part of this PR.
  • AST audit over tracked Go files: zero remaining borrowed calls with an inline fresh-pool argument. Source ownership audit: each of the five shared pools has one enclosing deletion owner and borrowing constructors inside its children/loops/closure.
  • Formatting checked across all 136 intended Go files; go vet, the pinned MatrixOne molint, and golangci-lint 2.14.0 passed on the four updated packages. Diff-based lint included the complete intended PR patch, including the follow-up changes; zero introduced issues.
  • Prior-head CI UT, SCA, coverage, shared build and BVT passed and are retained evidence for unchanged migration/helper content. CI for head d68e0b8b66 has completed successfully, including Ubuntu UT, Linux/arm64 SCA, coverage, shared build, PROXY/PESSIMISTIC BVT and CI Required. Skipped jobs are not execution evidence.

The change releases test pool registrations and removes redundant shared-pool teardown. No production performance improvement or whole-suite speedup is claimed. The earlier default-pool-before-WithMPool constructor defect was fixed in #29629; its existing borrowed-dependency coverage is retained.

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

@aunjgr aunjgr 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 076ea57ddefe60baee4b13b679e01746c40a08c4. The new helper registers pool deletion before process/file-service cleanup, which gives the intended cleanup order. Most of the migration is mechanical, but two migrated call sites transfer a shared parent pool to each child test.

[P2] Keep shared pools borrowed in pkg/vm/engine/readutil/filter_test.go:4552 and :4602. TestConstructBasePKFilter_InvalidRangeFlagNotValid allocates m at line 4529, outside t.Run, and both child tests call NewProcessWithOwnedMPool with that same pool. TestCompileFilterExpr_PrefixSortedSeekOps does the same with the pool at line 4586. The first child cleanup calls DeleteMPool(m), removes its global registration, and the next sibling then allocates through that already-deleted pool. Normal MPool currently permits this, so passing CI does not detect the ownership error; its later live allocations no longer have their pool registration. This contradicts the stated migration rule that shared pools remain borrowed.

Keep the borrowed helper in these children and delete the pool once at parent cleanup, or allocate a distinct pool inside each child. Audit other captured pool variables across subtest boundaries and extend the ownership regression to cover a parent-owned pool surviving two children. This finding is based on the actual cleanup and allocation paths; no local test run is claimed.

@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 076ea57ddefe60baee4b13b679e01746c40a08c4 against merge-base f20f5ca147c44b012343d0f48dfcd84b6a5986a1. Freshly fetched main is bab4b3286a0dd5683a9b291763817722233e586c. Reviewed personally, no subagents.

Not approvable yet: one P2 ownership defect affecting two migrated call sites. This independently reproduces and confirms aunjgr's existing Request Changes; that concern is not resolved on this head. Since the authenticated reviewer is also the author, this is a COMMENT, not an approval.

Design and scope

The direction is appropriate: retain the borrowed constructor, reuse its existing process/file-service lifecycle, and add a thin explicit ownership wrapper. Its registration order gives caller cleanup -> process cleanup -> file-service cleanup -> pool deletion. No duplicate state machine, storage, synchronization mechanism, or execution path is needed.

The complete 136-file change map contains 1,035 constructor migrations, one 11-line helper, one 25-line regression test and three removed manual pool deletions. Source normalization confirms 132 files are exclusively constructor-name substitutions; the other four files were inspected separately. AST origin/scope checks cover 758 inline fresh-pool migrations and 277 identifier-based migrations, including captured identifiers. The two child-owned/parent-created pools below violate the intended migration rule. A third captured pool in TestIvfflatEmptyGeneration uses the parent testing lifetime rather than a child lifetime; it does not reproduce the premature sibling invalidation, so it is not reported as another runtime defect.

No production kernel behavior or document changed. This is ordinary fixture maintenance, not a feature needing a new design framework. Runtime SQL performance, persisted data compatibility and mixed-version operation are not affected by this delta. The resource benefit is releasing global pool registrations after tests; the PR does not establish a whole-suite speedup. No GPU execution is claimed for build-tagged consumers.

Independent white-box challenge

Check Result
Unmodified two readutil tests Both PASS (0.920s), showing their original assertions miss this contract
Same tests with only a pool-registration assertion added at each child entry Both FAIL in the second child (0.938s)
Same assertions, children borrowing and one parent cleanup Both PASS (0.837s); no filter/SQL behavior changed
Independent shared-parent/two-child allocation matrix Borrowed control PASS; owned variant FAIL: second child has liveBytes=16, registeredPools=0
Existing TestProcessFixture* tests PASS (1.606s), including borrowed, nil/manual lifetime and construction-failure coverage
New owned-helper regression under race Measured T=0.03s; B=30s gives capped N=100; all 100 repetitions PASS in one process (2.291s package wall time)
Full pkg/testutil Normal PASS (1.807s); race PASS (2.158s)

Go 1.27.0, darwin/arm64, repository CGo wrapper and a complete test-worktree native build. Readutil selection: ^(TestConstructBasePKFilter_InvalidRangeFlagNotValid|TestCompileFilterExpr_PrefixSortedSeekOps)$. Witnesses and counterfactual controls were review-only, then removed from the isolated source worktree; no PR implementation was modified or pushed. Logs/patches remain under /tmp/mo-review-29678-J2YI1G/.

Q1 fails at the child cleanup ownership boundary. Q2 adds no wait and reuses existing fixture teardown. Q3 is improved for genuinely fresh pools but the confirmed sites remove the registration while the shared resource remains in use. This is a test-fixture lifecycle/observability defect, not evidence of a production SQL regression or a demonstrated memory double-free.

Please fix the two sites together and retain one focused parent/child ownership regression. The existing test checks exclusive ownership cleanup, but not the adjacent shared-parent boundary; adding more equivalent exclusive-owner cases would not close this gap. CI success does not supersede the deterministic registration witness.

Comment thread pkg/vm/engine/readutil/filter_test.go Outdated
})

proc := testutil.NewProcessWithMPool(t, "", m)
proc := testutil.NewProcessWithOwnedMPool(t, "", m)

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.

[P2] Do not transfer a shared parent pool to each child test.

Here m is allocated at line 4529 outside t.Run; the first child registers and executes DeleteMPool(m), removing it from globalPools before the next sibling. The same defect exists at line 4602 (pool allocated at 4586).

This is now experimentally confirmed, not just a possible ownership concern: adding require.NotEqual(t, "[]", mpool.ReportMemUsage(parentTag)) at child entry makes both real tests fail on their second child. An independent allocation witness shows the second child still successfully allocates 16 bytes while its registered pool count is zero. The original tests pass because normal MPool allocation does not reject an already-unregistered pool.

Keep NewProcessWithMPool in these children and register one DeleteMPool on the parent, or allocate a fresh pool inside each child. The borrowed-parent control passes both unchanged functional assertions and the new registration assertion. This confirms the existing review finding remains unresolved.

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.

Fixed in d68e0b8b66. Both tests now register one deletion on the parent and use NewProcessWithMPool in each child. Registration is checked at child entry, after each child returns, after dependent teardown, and after final parent deletion. The borrowed fixture also covers two sequential children.

Normal and race runs of all four affected packages pass. An external overlay restoring the five incorrect owned constructors makes all five real consumer regressions fail; the fixed code passes. Current-head UT, SCA, coverage, build, BVT and CI Required are green. The latest review confirms this finding is closed in code.

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

Codex automated review

Loaded the existing discussion first: @aunjgr's CHANGES_REQUESTED on the shared parent pool at pkg/vm/engine/readutil/filter_test.go:4552 and :4602, plus the author's own confirming COMMENT review. Both remain unresolved on 076ea57. I do not re-raise them.

Independent verification of the rest of the change (AST scans over all 1,035 owned-helper call sites in the repo, plus mpool/testing semantics read from source):

  • Helper ordering is correct. NewProcessWithOwnedMPool registers DeleteMPool before newProcess registers releaseFS and releaseProcess, so LIFO teardown is process -> file service -> pool, and the cleanup is already registered if the constructor Goexits. mpSet=true also prevents the !cfg.mpSet fallback in newProcess from deleting the pool a second time.
  • Argument origins are clean. 758 sites pass inline mpool.MustNewZero()/MustNewZeroNoFixed(), 277 pass a local identifier. No owned call receives a function parameter, a package-level var, or a non-mpool. expression; no function combines an owned call with a manual DeleteMPool; no identifier is passed to both the owned and the borrowed helper in the same function.
  • The t argument always matches the lexically enclosing Run/closure parameter, so no cleanup is registered on the wrong lifetime.
  • The two removed mpool.DeleteMPool(proc.Mp()) defers in mergetop/order are a strict improvement: they used to destroy the pool before the fixture's own releaseProcess/releaseFS cleanups ran.
  • No owned pool in the diff is NoLock (MustNew* and the limited pools are all NoFixed), so destroy() never reaches deallocateAllPtrs(); the ten functions that register a t.Cleanup before an owned call only restore runtime globals, mpool.CapLimit, or remove a temp file/tar and a vector-index cache key, none of which touch the pool.

Two new issues, both non-blocking: three sites call the owned helper repeatedly with one captured pool, which registers DeleteMPool once per repetition and inverts the documented teardown order for all but the last repetition; and 17 inline fresh pools in pkg/sql/colexec/spillutil were skipped by the migration because their calls are formatted across multiple lines, so the leak this PR exists to remove persists in two files it edits. Neither causes a test failure or memory-safety problem today, hence COMMENT rather than REQUEST_CHANGES.

P2 - Repeated owned-helper calls with one captured pool register DeleteMPool per repetition and tear processes down after pool destruction (pkg/vm/engine/readutil/filter_test.go:4199)

NewProcessWithOwnedMPool registers t.Cleanup(func(){ mpool.DeleteMPool(mp) }) once per call, then newProcess registers releaseFS and releaseProcess. Because testing.T cleanups run LIFO, the documented order (process -> file service -> pool) only holds when the helper is called once per t for a pool that is not reused. Three migrated sites call it repeatedly with one pool captured from an outer scope, so the registration sequence on a single t is [D1,F1,P1, D2,F2,P2, ...] and teardown runs P_N,F_N,D_N, P_{N-1},F_{N-1},D_{N-1}, ... — every earlier repetition's process and file service are released after the pool is already destroyed, and DeleteMPool executes N times for one pool.

  • filter_test.go:4199 TestCompileFilterExpr_PrefixInRangeAllFlags: m := mpool.MustNew(t.Name()) at :4179, for _, tc := range flags at :4191 over 4 entries -> 4 registrations.
  • filter_test.go:4502 TestCompileFilterExpr_InRange: m at :4492, loop at :4494 over 4 entries -> 4 registrations.
  • pkg/vectorindex/ivfflat/search_test.go:193 TestIvfflatEmptyGeneration: mp at :190, load closure invoked at :225 and :232 -> 2 registrations.

Today the effect is contained: all three pools come from MustNew*, i.e. NoFixed without NoLock, so MPool.destroy() leaves mp.ptrs intact and the post-destruction proc.Free() still resolves its headers; process.Free() (pkg/vm/process/process2.go:289) only releases from proc.Mp() via setPrepareParams, which these tests never populate. The observable symptoms are N DeleteMPool calls for one pool, N-1 process/file-service cleanups after destruction, and repeated mp error: logs from destroy() while earlier repetitions' memory is still live.

It is still a defect in the contract this PR exists to establish, and the PR description's audit claim ("no function passes the same pool identifier to owned helper more than once") counts syntactic call sites, which a for or closure body defeats at runtime. The hazard becomes a hard failure the moment such a shared pool is NoLock: destroy() then calls deallocateAllPtrs() (pkg/common/mpool/mpool.go:569) and any later freePtr on a remaining block panics with "invalid ptr, double free" (pkg/common/mpool/mpool.go:1298).

Fix: hoist one t.Cleanup(func(){ mpool.DeleteMPool(m) }) next to the pool declaration and keep NewProcessWithMPool inside the loop/closure, or create a fresh pool inside each repetition.

This is distinct from the already-reported sibling-subtest sites at :4552/:4602 and is not a re-raise of them; search_test.go:193 was mentioned in the author's self-review only regarding sibling invalidation, not duplicate registration or teardown order.

P2 - 17 inline fresh pools in pkg/sql/colexec/spillutil were skipped by the migration and still leak their globalPools registration (pkg/sql/colexec/spillutil/accounted_writer_test.go:32)

The PR's stated rule is that fresh pools created by the test itself migrate to the owned helper and only shared or caller-managed pools stay borrowed. Seventeen call sites that match the rule exactly are still on NewProcessWithMPool, all in pkg/sql/colexec/spillutil and all formatted across multiple lines:

  • accounted_writer_test.go:32, :65, :120, :148 — mpool.MustNew("accounted-writer-{lifecycle,fallback,short-write,cancel}")
  • allocation_account_test.go:150, :221, :261, :291, :376, :439, :550, :607, :647, :696, :749, :801, :924 — mpool.MustNew("spill-...")

In each case the pool is constructed inline at the call, is never bound to a variable, is reachable only through proc.Mp(), and is not shared with any other process. rg DeleteMPool pkg/sql/colexec/spillutil returns nothing, so every one of them leaves a permanent globalPools entry plus its ptrs map behind after the test — precisely the leak this PR was opened to remove.

Both files are edited by this PR (accounted_writer_test.go:215 and :230, allocation_account_test.go:499 and :863 were migrated), and the only difference between the migrated and the skipped calls is formatting: the migrated ones are single-line mpool.MustNewZero(), the skipped ones are multi-line mpool.MustNew("<tag>"). A whole-repo AST scan for NewProcessWithMPool whose third argument is any call expression returns exactly these 17, so this is the complete residual set and no other borrowed call anywhere takes an inline fresh pool.

The validation audit listed in the PR description cannot detect this: all three of its checks constrain owned-helper calls, not borrowed ones.

Non-blocking — behavior at these sites is unchanged from main and no test fails — but the migration is incomplete and its stated invariant does not hold. Fix: switch these 17 calls to NewProcessWithOwnedMPool (the multi-line formatting needs no change).

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

PR #29678 deep review
#29678

Decision: REQUEST_CHANGES.
Reviewed head: 076ea57.
One confirmed P2 blocker and two non-blocking P3 cleanup/completeness findings remain. All three groups were already raised in comments and remain present in the latest source. The single inline thread is unresolved and not outdated. Review performed personally, without subagents; no source changes. This review is submitted as COMMENT because the authenticated reviewer is also the PR author; the substantive recommendation remains REQUEST_CHANGES. The existing inline blocker is referenced rather than duplicated.

  1. [P2, blocking] A parent-created pool is destroyed by the first child test.

pkg/vm/engine/readutil/filter_test.go:4552 and :4602
TestConstructBasePKFilter_InvalidRangeFlagNotValid creates m at :4529, outside t.Run; TestCompileFilterExpr_PrefixSortedSeekOps does the same at :4586. Both children call NewProcessWithOwnedMPool with the same parent pool. The first child's cleanup executes DeleteMPool, removes the globalPools entry, and the second child continues using the unregistered pool. No later path restores the registration.

This is a demonstrated fixture lifetime/observability failure. A previously published exact-head experiment added only a pool-registration assertion at child entry: both real tests failed in their second child. The borrowed-child/one-parent-cleanup control passed. An independent allocation witness recorded liveBytes=16 with registeredPools=0 in the second child. The unchanged original tests passed because normal MPool allocation permits use after removal from globalPools.

Fix both sites by registering one DeleteMPool cleanup next to the parent's pool creation and retaining NewProcessWithMPool in each child, or allocate a distinct pool in each child. Preserve a focused shared-parent/two-child regression. This is not evidence of a production SQL regression or an actual double-free.

Existing discussion:
#29678 (comment)

  1. [P3, non-blocking] Repeated calls transfer ownership of the same pool repeatedly.

pkg/vm/engine/readutil/filter_test.go:4199 and :4502
pkg/vectorindex/ivfflat/search_test.go:193

The two filter tests create m outside a four-iteration loop; TestIvfflatEmptyGeneration captures mp in a load closure called twice. A single syntactic call therefore registers pool deletion four, four, and two times respectively. Cleanup registrations [D1,F1,P1,D2,F2,P2] run as P2,F2,D2,P1,F1,D1: earlier processes/file services are cleaned after the shared pool's first deletion. The helper's documented ordering holds for one exclusive ownership transfer, not these repeated transfers.

The observed source-level consequences are redundant DeleteMPool calls and an ownership/cleanup ordering violation. These current pools are ordinary NoFixed pools, and the affected processes do not populate prepared parameters; no actual memory-safety failure or failing functional assertion is established. This is deliberately calibrated below the existing comment's P2 label, rather than treating a hypothetical future NoLock conversion as a current failure. Repeated error logs are not claimed as a new measured result.

Fix these three consumers with one cleanup on their enclosing owner and borrowed constructors inside the loop/closure, or create a fresh pool per invocation. Do not add a pool-deduplication registry, extra synchronization, or a second lifecycle implementation to the helper. The PR body's syntactic uniqueness audit does not establish runtime uniqueness through loops or invoked closures.

  1. [P3, non-blocking] Seventeen inline fresh-pool calls in already-edited files remain borrowed.

pkg/sql/colexec/spillutil/accounted_writer_test.go:32, :65, :120, :148
pkg/sql/colexec/spillutil/allocation_account_test.go:150, :221, :261, :291, :376, :439, :550, :607, :647, :696, :749, :801, :924

Each call supplies an inline mpool.MustNew("tag") across multiple lines. The pool has no external owner, Process.Free does not delete it, and there is no DeleteMPool anywhere in spillutil. Consequently globalPools retains these pool objects after their tests complete. Both files are part of this PR and other fresh pools in them were migrated, so formatting has left the intended lifecycle fix incomplete.

This is retained behavior from the base, not a newly introduced regression or demonstrated suite OOM. Switch these 17 calls to NewProcessWithOwnedMPool. The validation search must also inspect remaining borrowed calls, rather than only checking migrated owned calls. Source searches in this review independently confirm the 17 sites and absence of deletion; the prior exact-head AST audit identifies the same residual set.

Design and engineering assessment

The helper design is appropriate. NewProcessWithMPool remains the borrowed API; the new 11-line wrapper delegates to the same newProcess implementation and registers pool cleanup before process/file-service construction. With one exclusive pool, LIFO yields caller cleanup -> process -> file service -> pool. mpSet=true prevents constructor rollback from independently deleting the supplied pool; construction failure still has the test-owned cleanup registered. Nil testing.TB retains explicit caller ownership as documented. No parallel state machine, storage, new execution path, or production kernel ownership policy was added.

The common cause of the findings is migration classification: locally created does not mean exclusively owned by the current child or by every repeated constructor call. Correct the consumer ownership boundaries; the thin helper does not need redesign. The three removed manual DeleteMPool calls correctly eliminate an earlier duplicate cleanup path. There is no justification for making all supplied pools owned or adding a universal lifetime manager.

Implementation, tests, documentation assessed separately

Implementation: one non-test file, pkg/testutil/util_new.go, +11/-0.
Tests: 135 files, +1060/-1038. These contain 1035 constructor substitutions, one 25-line new fixture regression, and three removed manual pool deletions. Source normalization establishes that 132 files contain only constructor-name substitutions; the four files with additional changes were inspected separately. Although textually mechanical, the substitutions change ownership semantics and were assessed as one lifecycle closure.
Documentation: no tracked documentation changes. The PR body claims shared pools stay borrowed and runtime uniqueness was audited; the actual shared/repeated consumers contradict these claims. Its Ubuntu UT-pending statement is also stale now that CI has completed; refreshing it is a delivery follow-up, not a separate blocker.

The new test has a distinct purpose from the existing default-owned/borrowed fixture tests: it checks supplied-pool ownership, on/off-heap caller cleanup, and eventual removal from globalPools. Its setup/data volume is modest. It covers exclusive ownership, but cannot detect the migrated shared-parent boundary. Add a small parent/two-child scenario and verify the corrected loop/closure consumers; do not copy an ownership test into each of 1035 callers or grow a heavyweight fixture matrix. A bidirectional migration audit is more useful than extra equivalent exclusive-owner cases.

Unhappy-path / QA audit

Layer/closure Q1 creation and destruction owner Q2 waits and termination Q3 retained state
Exclusive owned helper -> newProcess -> testing cleanup One pool cleanup; existing process/FS cleanup reused, constructor failure covered by pre-registered pool cleanup No new goroutine, lock, wait, timer, retry, or callback dependency cycle Pool registration removed at test termination
Shared parent -> child tests -> DeleteMPool FAIL: destruction occurs before parent resource lifetime ends Sequential children return through existing testing lifecycle; no new hang demonstrated Registration removed while later live allocations still use the pool
Parent pool -> repeated loop/closure constructors FAIL: multiple destruction registrations; earlier dependencies outlive first pool deletion No added wait; normal teardown is finite Redundant cleanup work is bounded by four/four/two invocations
Seventeen borrowed inline pools -> Process.Free FAIL: no effective pool deletion owner No added wait globalPools retains pool metadata until process termination; repeated tests accumulate registrations

Failure/Goexit paths were traced through the existing newProcess/NewFS rollback and testing cleanup rather than inventing a second rollback mechanism. No new cancellation, reset-generation, distributed, persistent-format, security, tenant, or upgrade contract changes exist in this delta. GPU-tagged consumers change the same fixture ownership but no GPU execution result is claimed.

Performance assessment

No production query hot path changes. Correct ownership adds one test-lifetime cleanup registration and the intended DeleteMPool operation per fresh pool, exchanging bounded cleanup work for removing retained registrations. Existing pool teardown scans only hinted on-heap pointer shards; this PR introduces no additional hot-path scan or new synchronization mechanism. Repeated cleanup in finding 2 is unnecessary work and should be removed at the owner. No whole-suite speedup, production throughput improvement, or measured benchmark claim is made.

Evidence and limits

Current PR CI: Ubuntu/x86 UT, Linux/arm64 SCA, coverage, shared build, PROXY BVT, PESSIMISTIC BVT and CI Required completed successfully. Skipped jobs do not count as validation.
UT: https://github.com/matrixorigin/matrixone/actions/runs/37705550539/job/113079454961
SCA: https://github.com/matrixorigin/matrixone/actions/runs/37705550539/job/113079454971
Required: https://github.com/matrixorigin/matrixone/actions/runs/37705550539/job/113100585257

Reused published exact-head review evidence: the two unmodified readutil tests pass; registration assertions fail in second children; the borrowed-parent control passes; the 16-byte/zero-registration witness demonstrates the lifecycle consequence. Published pkg/testutil fixture tests, full package normal/race runs, and 100 repetitions of the owned-helper race test pass on Go 1.27.0 darwin/arm64 with the repository CGo wrapper/native build. These results are explicitly reused, not newly executed here. Original /tmp logs are not locally present in this review environment; the public review records terminal results and causal output. This review independently reread the implicated source, verified all extra handwritten changes, normalized the complete change map, checked current CI/comments and resolution state, and confirmed the residual fresh-pool calls. No fresh local Go/GPU/performance test execution is claimed.

Required next step: fix the two shared-child consumers, clean up the three repeated transfers, finish the seventeen omitted fresh-pool migrations, and retain concise behavior-based regression evidence. Update the ownership audit/documentation to match the runtime contract. The demonstrated P2 remains the merge blocker; the other two findings are non-blocking completeness/quality improvements, not expanded production incident claims.

@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 MatrixOne PR #29678
#29678

Decision: APPROVE / no confirmed code blocker.
Reviewed head: d68e0b8.
All three existing comment finding groups are fixed in code. The single GitHub inline thread remains unresolved but is now outdated; that UI state is distinct from the verified source disposition. No new implementation or test defect was established in this review. One non-blocking PR-description update remains: its updated-head CI-pending statement is stale because the current required checks have completed successfully.

Review performed personally, without subagents or another model invocation. No source edits or thread-resolution mutation. Submitted as COMMENT because the authenticated reviewer is also the PR author; the substantive recommendation is APPROVE. This pass reuses evidence for identical source rather than rerunning completed tests.

Existing comment closure

  1. Shared parent pool destroyed by first child: FIXED.
    TestConstructBasePKFilter_InvalidRangeFlagNotValid, filter_test.go:4540;
    TestCompileFilterExpr_PrefixSortedSeekOps, filter_test.go:4587.
    Both pools have one enclosing deletion callback; children call NewProcessWithMPool. Assertions verify registration at child entry and after each child returns. The pool remains present through dependent teardown and is absent after its enclosing deletion.

  2. Repeated ownership transfers in loops/closure: FIXED.
    TestCompileFilterExpr_PrefixInRangeAllFlags, filter_test.go:4160;
    TestCompileFilterExpr_InRange, filter_test.go:4469;
    TestIvfflatEmptyGeneration, ivfflat/search_test.go:189.
    Each shared pool has one outer cleanup; repeated constructors borrow it. Presence witnesses run after all index/process/file-service teardown but before pool deletion. Earlier absence witnesses run last. No pool registry, callback-deduplication mechanism, synchronization layer, or second lifecycle executor was added.

  3. Seventeen omitted inline fresh pools in spillutil: FIXED.
    accounted_writer_test.go: four; allocation_account_test.go: thirteen.
    Each now calls NewProcessWithOwnedMPool. Neither file retains a NewProcessWithMPool call. The exact-content AST receipt reports owned_calls=1048, borrowed_calls=53, borrowed_inline=0. The seventeen tests execute and pass in normal and race modes.

The original inline discussion is now outdated, not resolved:
#29678 (comment)
All four published reviews still refer to old head 076ea57; there are no additional current-head code comments to reconcile. The Qodo issue comment is service/quota information rather than a code finding.

Design and ownership assessment

The first owners remain the supplied-pool owner and testing.TB lifetime, with newProcess owning its default process/file services. The 11-line owned wrapper delegates to the existing borrowed constructor. It registers deletion before construction; mpSet=true prevents the constructor rollback from independently deleting a supplied pool. The borrowed helper preserves sharing and caller-managed ownership; nil testing.TB preserves manual cleanup. NewProcess/NewFS retain their existing partial-construction rollback and once-guarded cleanup.

This closes the general boundary between exclusive and shared pools at the consumers. The wrapper does not attempt to infer sharing or remember which pointer has been registered. That avoids extra state and preserves the original ownership contract. The three replaced manual DeleteMPool defers were removed, eliminating the old overlapping deletion path.

The real cleanup order is dependent/index cleanup -> process/FS cleanup -> shared-pool presence witness -> the sole pool deletion -> absence witness. Child process cleanup precedes enclosing parent cleanup through testing's lifecycle. FailNow/Goexit still executes registered cleanup; constructor failure retains the pre-registered owner and existing rollback for partially acquired process/FS resources. No new cancellation, wait, retry, background resource, restart generation, or persistent-format contract was introduced.

Q / layer Result Evidence boundary
Q1: exclusive supplied pool -> owned wrapper -> testing cleanup PASS: one owner, process/FS precede deletion, failure owner registered before construction Helper/rollback source plus existing owned/failure fixture tests
Q1: parent pool -> child/loop/closure borrowers -> outer cleanup PASS: one deletion per source owner and borrowers remain registered until teardown Five real consumer regressions and counterexample controls
Q2: waits/control termination No new wait edge; existing process/FS cleanup retained No added goroutine, lock, channel, timer, RPC or retry path
Q3: globalPools registration retention PASS for the migrated exclusive pools; recycling at owner termination Owned fixture removal oracle and zero remaining inline borrowed calls

Registration endpoints do not alone count destructor calls. Cardinality is supported by the source audit showing one deletion owner; runtime witnesses support lifetime ordering. Adding fixture-wide callback counts would measure incidental process/FS implementation details without directly measuring pool destruction. The prior design adjustment declining those counters remains appropriate.

Implementation, test, and documentation increments

The complete PR is 136 files, +1132/-1060. Implementation is one non-test fixture file, +11/-0. Test files are 135 files, +1121/-1060. Source normalization accounts for 130 constructor-only files; the six additional-change files are util_new.go, process_fixture_test.go, readutil/filter_test.go, ivfflat/search_test.go, and the manual-delete removals in mergetop/order. Constructor substitutions change ownership and were reviewed under the lifecycle closure even though their text edits are mechanical.

The follow-up commit changes five test files, +71/-32. It corrects twenty-two calls, adds five outer owners, extends an existing borrowed fixture by one child, and checks the real consumer lifetimes. It does not add heavyweight data, duplicate services, sleeps, test hooks, a framework, or production mechanisms. The five teardown witness sequences repeat a small, explicit testing protocol at their actual ownership boundaries; hiding those owners behind a general lifetime abstraction would increase coupling without clear benefit.

Test quality has a discriminating control: restoring only the five erroneous constructor substitutions in an external overlay makes precisely all five consumer regressions fail their registration assertions, while fixed code passes. Thus the tests detect the migrated defect rather than merely asserting the new helper's implementation. Existing filter/index result assertions, nil/manual/borrowed/failure fixture scenarios, and spillutil behavior remain covered. No new SQL behavior warrants a new BVT fixture.

No tracked document was added or changed. The PR body now describes ownership and validation accurately except for the time-sensitive CI-pending sentence, which should be refreshed or replaced with a link to current Checks. This is non-blocking metadata cleanup, not a reason to add another code or test change.

Performance and remaining scope

Production query paths are unchanged. Each exclusive test pool gains intended deletion work, while shared pools lose redundant deletion callbacks. Added assertions are bounded to the five small real scenarios and one additional borrowed child. The current teardown uses the existing hinted on-heap ownership scan; no new allocation hot-path scan or synchronization was introduced. No production throughput or whole-suite speedup is asserted.

Seven ownership-warning scenarios in untouched tests were reproduced on original PR head 076ea57 with the same environment and original-source overlay. Their allocation cleanup debt is separate from this follow-up; no new warning at the twenty-two corrected consumers was established. The accepted scope is fixture pool registration lifetime, not a claim that every existing test allocation leak or theoretical future NoLock hazard is solved.

Evidence reused and current CI

The committed follow-up diff SHA256 is 5f2b80bf6c56e530e2f2298a4b1ac6e38d21a98bf820395f807f69aa859b6956; the complete intended diff SHA256 is 2cae31fe925b1aec09646519ef9b55907618e48a5d1186ca5ae1e06ac71b8b4f. Both hashes and all five source fingerprints match the previously reviewed and validated content. The source tree is clean.

Reused evidence under /home/xupeng/.codex/issue-to-pr/matrixone/pr29678/:

  • E8/E11: full normal and race runs of testutil, readutil, ivfflat and spillutil; all four packages and all twenty-six required top-level tests passed.
  • E9: formatting all 136 intended Go files, scoped vet/molint and patch-based golangci-lint 2.14.0; all passed, zero introduced findings.
  • E10: five real consumer counterexamples fail under bad-constructor overlay; fixed code passes.
  • E12: seven original-head warning controls.
  • E13: six exact lifecycle tests, each with 100 named race passes in a single process.
    Mode: Go 1.27.1 Linux/amd64, GOAMD64=v3, GOEXPERIMENT=simd, repository wrapper and complete stamped native build. These are retained executions, not new runs in this pass. Design/final model artifacts at design.txt and final-review.txt were explicitly gpt-6.1-sol/xhigh; they remain valid for the same source.

Current head CI has completed successfully: Ubuntu UT, Linux/arm64 SCA, coverage, shared build, PROXY BVT, PESSIMISTIC BVT, Connector/J, CodeQL and CI Required. Skipped Darwin/GPU/upgrade jobs are not execution evidence.
UT: https://github.com/matrixorigin/matrixone/actions/runs/37747442955/job/113212272581
SCA: https://github.com/matrixorigin/matrixone/actions/runs/37747442955/job/113212272530
Required: https://github.com/matrixorigin/matrixone/actions/runs/37747442955/job/113247689957

No additional test run was required: no changed source or unresolved counterexample invalidated the existing evidence. Recommendation: approve the code; refresh the stale CI sentence and complete ordinary reviewer-thread housekeeping.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Addressed the earlier reviews in d68e0b8b66:

  • Shared-parent finding: both child-test sites now borrow their pool; one enclosing parent cleanup deletes it. Child-entry, post-child and terminal-cleanup registration checks protect the lifetime.
  • Repeated-transfer and missing-migration findings: the two loops and IVF load closure now borrow from one outer owner. All seventeen spillutil inline fresh pools use the owned helper; the tracked-source AST audit reports zero remaining inline borrowed constructors.
  • Latest review follow-up: the PR description now reflects successful current-head CI rather than pending CI.

Validation: full normal/race UT and incremental vet/molint/lint for the four affected packages pass; all twenty-six required tests execute. Six lifecycle regressions each pass 100 bounded race repetitions. Restoring only the five bad constructor substitutions in an external overlay makes precisely all five consumer regressions fail. No additional pool registry/state machine or production change was added.

Current-head UT, SCA, coverage, shared build, PROXY/PESSIMISTIC BVT and CI Required pass. The latest review recommends APPROVE with no code blocker. The outdated inline thread is left open for reviewer confirmation.

@XuPeng-SH
XuPeng-SH merged commit 48f8178 into main Oct 8, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/quality-29249-owned-pools-20261008 branch October 8, 2026 10:14
cpegeric added a commit to cpegeric/matrixone that referenced this pull request Oct 8, 2026
Follows matrixorigin#29678: a test process built on a pool the test creates and never
frees uses NewProcessWithOwnedMPool, so the pool is deleted with the test.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

This branch was previously deployed

1 inactive deployment
ci — 7a92edcb Deployed Oct 8, 2026 by XuPeng-SH
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/refactor Code refactor kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants