Skip to content

test: make process fixture resource ownership explicit - #29629

Merged
XuPeng-SH merged 6 commits into
mainfrom
codex/quality-29627-process-fixtures-20261005
Oct 5, 2026
Merged

XuPeng-SH merged 6 commits into
mainfrom
codex/quality-29627-process-fixtures-20261005

Conversation

@XuPeng-SH

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

Fixes #29630. Refs #29249 and #29627. This is the constructor ownership and immediate consumer stage of #29627; the issue remains open for the nil-fixture/planner/remaining-owner migration.

What this PR does / why we need it:

Process fixtures previously registered a default pool before applying options, leaving an unreachable registered pool when the caller supplied its own. File-service options similarly constructed and discarded three unnecessary services and could close an earlier supplied dependency. Partial construction could retain pool registrations even with zero byte usage.

Resolve options before acquiring defaults, preserve explicit nil and last-option semantics, and borrow supplied pools/services/clients. A single constructor now owns default resources for the actual TB lifetime, captures the acquired resources independently of later process-field replacements, and unwinds partial acquisition on panic or Goexit. A nil TB keeps explicit manual ownership without allocating duplicate-cleanup callback state.

Reuse testing cleanup, existing Process.Free, and bounded OnceFunc guards only when both registered cleanup and rollback can reach the same resource. Keep runtime-owned auto-increment services and production Process.Free ownership unchanged.

Remove 87 immediately adjacent duplicate Process.Free cleanup registrations across 36 files, with exact constructor/TB/process binding checks and retained cleanup ordering. Remove redundant default file-service construction/close paths, close caller-owned dependencies immediately at their acquiring owners, and restore the S3 object-size limit and profile global. No data, error, NULL, metadata, or type assertions are deleted.

Validation

  • Latest main: ce2a22a; conflict-free rebase preserved all edited source bytes.
  • Owning testutil normal/race UT passed, covering real test lifetimes, borrowed and replaced dependencies, explicit nil, repeated options, manual lifetime, panic/Goexit rollback and late caller-data release.
  • 119 affected tests across 15 packages passed normally and with race; zero skips and nonempty selections verified.
  • Actual partial-acquisition service/descriptor probe passed all four panic/Goexit cases before registered cleanup; omitting rollback Close was rejected by every case.
  • Incremental SCA for the final 19-package closure: vet passed, configured lint reported zero issues.
  • Scoped molint comparison: 31 findings reproduced at the qualifying baseline, zero introduced.
  • Four alternating benchmark pairs include construction and destruction: local fixture median time +2.57%, bytes +4.92%; manual memory fixture +3.92%, bytes +2.24%. Local measurement reuses empty directories and a TB callback collector, excluding TempDir creation/testing cleanup dispatch. This is bounded ownership bookkeeping, not a claim of SQL, CI-minute, whole-test CPU or RSS improvement.
  • SQL BVT was not run for these mapped ownership changes. Fixture lifetimes and parser rejected-AST recycling are covered by owning normal/race UT; SQL rejection/result contracts are preserved. No full BVT or CI-green claim is made.
  • Independent gpt-6.1-sol/xhigh implementation review and final evidence audit: APPROVE_DELIVERY.

Private designs, coverage maps, instrumentation, mutants and benchmark artifacts are not committed.

Memory-backed function fixture owners

Follow-up commit migrates all 36 nil-TB function fixture sites across 10 files to one package-local memory-backed owner. The supplied FileService is closed by its allocating helper; the existing NewProcess(TB) owner frees process state and deregisters its default MPool. No TempDir or disk-backed fixture is added. Existing explicit Free followed by byte-zero checks remains before pool deletion, and every value, NULL, selection, error, warning, type/metadata, and reuse assertion is retained.

Validation: 44 selected top-level UT and the same 44 under race passed, zero skips; incremental vet and configured golangci-lint passed. Molint reports only the two previously baseline-qualified warnings, with zero additions. Independent private QA verifies three complete lifetimes return MPool registrations to baseline, forbids TempDir, and checks late native/heap cleanup before deletion. Removing the TB lifetime binding produces the expected runtime registration-count failure. Actual gpt-6.1-sol/xhigh review inspected all changed hunks and approved code with no findings; required gates subsequently passed.

This follow-up changes tests +68/-79 (net -11), implementation/docs/BVT zero. No timing or CI-minute improvement is claimed for this stage. Full PR now has fixture implementation +103/-98 and tests +419/-199 (net +225 overall). Refs #29249 and #29627; planner/plugin/manual/supplied-pool and cluster ownership reconciliation remains ongoing, so #29627 stays open.

Compiler getter and expression ownership closure

Two expression fixtures keep their three disabled-cache MemoryFS services with immediate allocator cleanup and existing post-Free byte-zero oracles. Four vector compiler fixtures (CAGRA, IVFPQ, IVFFLAT, HNSW schema) receive stable, test-owned processes with explicit nil pool/FS; getters allocate nothing and preserve live runtime provenance gating. Fulltext2's unused getter returns nil. HNSW's zero-value view fixture stays nil, while its schema fixture injects the process required by provenance metadata assertions.

Full package validation caught an initial HNSW reverse-consumer omission; it was fixed before delivery, preserving every provenance column assertion. Final validation selected 139 top-level UT in six packages and the same 139 under race, all passed with zero skips. Incremental six-package vet/configured lint passed; molint emitted five byte-identical-source baseline-qualified warnings and no new findings. Independent private QA passes for all four vector fixture getters, proving repeated/copied identity, nil pool/FS and no pool registrations. Restoring old getter allocation is rejected by a runtime oracle. Actual gpt-6.1-sol/xhigh review approved all seven final revision-2 files with no unresolved findings; required gates passed afterward.

This follow-up adds 102/removes 92 test lines (net +10), no implementation/docs/BVT changes, no SQL or measured time claim. Full PR now: fixture implementation +103/-98, tests +521/-291, total net +235. Refs #29249 and #29627 remain open; ordinary planner/manual/supplied-pool and standalone cluster owners remain follow-ups.

Direct planner owners and successful-parse AST lifetime

Six directly allocated nil-TB planner fixtures now reuse a package-local memory-backed owner. Its allocator immediately owns FileService close, while NewProcess(TB) owns process cleanup and default pool deregistration. Existing decimal byte-zero, values, type/scale/NULL/error oracles, recursive-view rejection/reset, protocol gates and CHECK-constraint assertions are retained. AssertPlan now immediately defers Free after successful parsing, covering every later return and panic. This checkpoint does not yet complete mock-constructor injection, runtime reuse or rejected-parser AST ownership.

Validation: six affected top-level planner UT passed normally and under race, zero skips; all 21 tools UT passed normally and under race, zero skips. Incremental vet and configured lint passed for both packages; planner molint findings remain four baseline-qualified unchanged-source diagnostics, tools molint has no findings. Actual gpt-6.1-sol/xhigh five-file source review approved with no local blockers; its pending tools gates subsequently passed. No BVT/product-query or performance improvement claim is made for this bounded lifecycle checkpoint.

Checkpoint: implementation +1/-0, tests +18/-10, docs/BVT zero. Cumulative PR: implementation +104/-98, tests +539/-301, net +244. The larger planner ownership class continues in this same PR; #29627 and #29249 remain open. Private QA also reproduced caller runtime replacement on parse rejection and omitted pooled-DDL release on multiple-statement rejection; those fixes and their migration validation remain pending.

Runtime reuse and parser rejection owner (fixes #29630)

AssertPlan now reuses the existing runtime instead of replacing it on every call, preserving runtime/service identity and protocol/executor globals. ParseOneWithSQLMode now frees every parsed statement before rejecting a non-single statement count; error/validation/success ownership remains unchanged. The parser is the cleanup owner on rejection, since callers receive no AST. This prevents lost pooled-DDL recycling; no SQL-result, throughput or RSS improvement is claimed.

Two owning packages passed all 206 top-level UT normally and under race, with identical nonempty selections and zero skips. Incremental vet/configured lint passed with zero issues; molint has no findings. The public runtime regression covers repeated success and rejected SQL and preserves shared-service/global identity. Restoring runtime replacement is rejected at a runtime identity assertion. A deterministic private pooled-DDL reset probe fails on the byte-identical main source and passes with the rejection Free loop; removing the loop reproduces the failure without GC/sleep/sync.Pool reuse assumptions. The public count regression retains empty/multiple rejection and nearest single-DDL success with caller cleanup. Actual gpt-6.1-sol/xhigh reviewed all four final files and approved without code blockers; all validation gates passed.

Checkpoint commit d6b921d: implementation +3/-2, tests +55/-0, docs/BVT zero. Cumulative PR: implementation +107/-100, tests +594/-301, net +300. Parser owning UT cover rejection behavior; no SQL BVT or full CI green claim. Larger constructor injection, pure fulltext getter, supplied-pool/manual/cluster reconciliation and their cost gates remain pending in this same PR; #29627 and #29249 remain open.

@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 requested a review from cpegeric as a code owner October 5, 2026 15:16

@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 d6b921d304ef: no blocking findings for this increment.

The ownership split is sound: the test fixture closes resources it allocates, supplied dependencies remain borrowed, and production Process.Free keeps its existing responsibility. The parser releases ASTs at the rejection boundary where callers receive no statement. I also checked rollback on panic/Goexit, replaced process fields, borrowed dependencies, and cleanup ordering.

Validation: current-head UT, SCA, shared build, coverage, and active BVT checks passed. Five fixture lifecycle tests passed under race. A differential parser probe confirmed rejected DDL nodes are reset on this head and remain populated on base; 1,904 existing valid SQL samples also passed the multi-statement rejection challenge.

This review covers the declared stage. #29627 remains open for the planner mock and other fixture owners explicitly deferred by the PR; approval here does not claim repository-wide closure of those follow-ups.

@XuPeng-SH
XuPeng-SH merged commit a267382 into main Oct 5, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/quality-29627-process-fixtures-20261005 branch October 5, 2026 18:21
XuPeng-SH added a commit that referenced this pull request Oct 6, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes #29636.
Fixes #29637.

Refs #29249 and #29627. Continues merged #29629 as one complete planner
fixture ownership migration. #29627 remains open for standalone-cluster,
supplied-pool, alias and remaining-owner reconciliation; this PR does
not complete the 100,000-line cleanup goal.

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

### One explicit owner, with existing construction and cleanup

Four mock compiler/optimizer constructors now borrow an explicit
process. `GetProcess` is a pure lookup and preserves override
precedence, including nil. Context copies retain the injected process
and executor identities. The holder, `Once` and global constructor mutex
are retired; scoped executor selection uses the existing context and
exact process identity without invoking a getter or publishing a global
executor.

Migrate all 2,218 constructor calls and propagate actual caller TBs
through the existing helper graph (23 named helper signatures and 316
helper calls). Callers reuse the existing `testutil.NewProcess` owner.
Planner fixtures use MEMORY file services with explicit caller cleanup.
Proved metadata-only consumers pass nil; supplied-process overrides and
independent parent/child compile sessions remain intact. Manual
`AssertPlan` releases its process, FS and pool on return. Fulltext binds
its resolver once to the final wrapper and still observes later wrapper
state changes.

### Preserve isolation and bound fixture retention

Reuse the existing runtime storage and a scoped test helper to restore
both prior value and prior absence for hints, protocol versions,
runtime-filter limits and SQL executors. Register restoration before
mutation, preserve later writes through LIFO cleanup, and retire
replaced restorers and runtime resets. No parallel mutation is
introduced.

Keep fresh mutable contexts but attach their resources to actual child
scenarios: fulltext/HAVING, deterministic UPDATE builds, serialization,
prepared-value rows and BOOL compatibility controls. Fixed-config
benchmarks share one process per benchmark while retaining fresh
catalogs per iteration; the existing statement runner releases each
successful AST immediately. No scenario counts or
result/type/error/layout assertions are weakened.

Retire discarded mock statistics construction, `Schema.outcnt`, the
write-only context PK cache and its writes, and the unused
`PrimaryKeyDef.Cols` calculation. `Schema.pks` and the used metadata
remain. Remove a 58-line inactive protocol-test comment; normalized
active Go syntax is identical, and existing protocol/error/fuzz-seed
tests remain.

### Verified counterexamples

- **#29636:** composite primary-key `Names` was pre-sized and then
appended, producing leading empty names through public `Resolve`. Fill
the existing slice by index. The regression uses literal
single/composite key names, including nonadjacent key columns; it does
not compute expectations with the implementation.
- **#29637:** five external-scan UTs inherited host CPU capacity but
asserted three scopes or a spare-capacity footer path. Configure the
existing logical `Compile.ncpu` explicitly. The clean main probe
reproduces all five failures with `GOMAXPROCS=2`; repaired fixtures
preserve file uniqueness, row-group coverage, empty-file exclusion and
schema-mismatch rejection. Production scheduling and host CPU limits are
unchanged.

Reconcile incoming main NTILE and binary/unary test consumers with the
same owner instead of restoring obsolete nil/default fixture paths.

### Retire unreachable export coverage without losing its error contract

Remove the export merge test whose constant-true guard always skipped
execution, together with its exclusive setup and lock helpers. Preserve
missing-file coverage in the existing ETL-reader fixture: assert a nil
reader and the exact `ErrFileNotFound` category. Existing active
CSV/TAE, merge, filter and discard scenarios remain.

The complete export package passes (53 test events, zero skips), and
focused reader normal/race runs each pass five test events. A production
overlay that swallows the file-open error is rejected by the new
assertion. Formatting, vet, incremental configured lint and molint pass.
Actual **gpt-6.1-sol / xhigh** separately reviewed this checkpoint:
APPROVE, no unresolved blockers. This removes 90 net lines; it makes no
runtime-speed claim because the old test never ran.

### Validation and independent QA

Based on fetched main `614ab46453638324a7997ac3ecc6813e5c810309`, Go
1.26.4. Heavy jobs ran serially with `GOMAXPROCS=2`, `GOMEMLIMIT=2GiB`,
package/test parallelism one, offline modules and the repository CGo
wrapper.

- All nine owning packages ran completely, uncached: **10,037 top-level
PASS**. Three inherited skips (one frontend test and two planner
subtests) receive no pass credit.
- Complete planner and compile race runs: **3,498 / 1,387 PASS**,
respectively. Planner has the same two inherited skipped subtests;
compile has none. Eight affected frontend/compiler/unary/binary race
selections also pass, with zero skips.
- Four individual getter/executor/resolver race selections each reach
100 repetitions within the recorded 30-second budget and cap: **400
PASS**, zero skips. Their unchanged semantic inputs were checked after
rebase.
- Incremental formatting, vet, configured lint and molint cover the nine
changed packages; all pass, configured lint reports zero issues and
molint reports no findings. The preceding full 28-package PR closure
also passed before the latest main integration; it is recorded
separately, not substituted for final checks.
- Independent lifecycle probes check native/heap bytes, registry
removal, child teardown and borrowed-resource survival. Omitting TB
cleanup is rejected by the public registry oracle. Benchmark retention
probes pass, and restoring per-iteration acquisition is rejected.
Restoring runtime replacement is rejected by the existing identity
regression.
- Actual **gpt-6.1-sol / xhigh** reviewed the complete change map,
ownership design and QA evidence, then reviewed only the converged
source corrections and new-main integration. All source blockers and
mandatory validation gates are closed. No review documents are
committed.

Four controlled fixture-construction-plus-cleanup benchmark shapes
satisfy the <=5% time/allocated-byte regression budget. Default fixture
shapes improve about **9.7–9.9% in time** and **6.1% in allocated
bytes**; the metadata-only and eight-context shapes also pass. These are
local fixture costs, not production query, total CI CPU/RSS or TPCC
claims. The hot-path inputs remain unchanged after rebase, so that
evidence is reused.

Implementation **+62/-157**; tests **+3,090/-3,205**; docs/BVT zero;
**net -210 lines** across 256 files. Most constructor edits are API
migration, not large-deletion credit. Product SQL behavior is unchanged,
so this stage requires no SQL BVT; no full-CI-green claim is made.
XuPeng-SH added a commit that referenced this pull request Oct 8, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [x] 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](https://github.com/matrixorigin/matrixone/actions/runs/37747442955/job/113247689957).
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.

This branch was previously deployed

1 inactive deployment
ci — 9ed2c3ff Deployed Oct 5, 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/enhancement 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.

[Bug]: ParseOne does not release parsed statements when rejecting multiple statements

2 participants