Repository navigation
fix(ci): serialize embedded UT package execution - #29113
Conversation
…9116) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #28784 (disk-cache lifecycle/finalization UT flakiness). ## What this PR does / why we need it: `TestDiskCacheAsyncUpdateReturnsBeforePathAvailable` correctly observed asynchronous admission in [the Ubuntu race job](https://github.com/matrixorigin/matrixone/actions/runs/35446682379/job/105906726319), but then exhausted its five-second `Flush` context while finalizing a real disk write. The test was coupling an ordering/ownership contract to real `file.Sync` latency. The CI artifacts do not establish which syscall consumed the deadline, so this is a test-contract correction, not a claim to have proved a filesystem or production cache defect. - Reuse the existing blocked-file-sync hook to explicitly control finalization, without changing production durability behavior or increasing timeouts. - Preserve asynchronous return while the path is owned, caller-buffer cloning, callback data, and actual cache read/hit assertions. Also check that the callback has not run while finalization is blocked. - Register both release edges immediately so failed assertions cannot strand a test-owned gate before cache cleanup. - Remove an unbounded timeout-path channel join and bound the callback wait separately: `Flush` drains writes, not callbacks. ### Validation Local platform: Darwin arm64, Go 1.26.4, matching freshly built native libraries, `matrixone_test` tag. - Exact modified test: normal and race pass. Adaptive race repetition: 100/100 pass, no skips (single measured test elapsed rounded to 0s; 30-second budget capped at 100). - Owning `pkg/fileservice` package: normal pass, 24.046s; 848 passing test/subtest events, 11 existing skips. - Incremental `go vet`, golangci-lint 2.6.2 (0 issues), gofmt and diff checks pass. - Local normal-mode control: original test 0.02s, changed test below output time resolution. This is not a CI speedup estimate. ### Scope and remaining risk The same CI job also failed `TestIssue26640ClusterRestoreRebindsSubscriptionPrivileges` during `CREATE ACCOUNT`, before restore assertions, following HAKeeper/Raft timeouts. This PR does **not** claim to fix that independent failure. The existing, separately authored #29113 addresses embedded-package contention; its scheduling changes are not duplicated here. The unchanged restore case passes local normal mode (22.51s) and race mode (41.53s); isolated execution cannot establish loaded Linux CI stability. GPT-6 medium design approved the correction; a separate GPT-6 medium overall review accepted the final diff with zero blockers after reconciling all validation evidence. CI will run after publication; no CI pass is claimed and this task does not wait for it.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
APPROVE — reviewed exact head a8d399f. Per-invocation -p 1 serialization preserves package discovery, partition validation, cancellation/cleanup, failure propagation and reporting; no actionable P0–P2 findings. Exact-head CI confirmed nine embedded packages executed serially and passed. Remaining limits are per-invocation scope, no baseline throughput proof, Darwin skipped, and incomplete crash/restart evidence.
Merge Queue Status
This pull request spent 6 minutes 13 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #29113 has been dequeued Queue conditions are not satisfied:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
## What type of PR is this? - [x] Improvement - [x] Test and CI ## Which issue(s) this PR relates to Related to #28419 (UT producer cost). This does **not** claim to resolve that whole-job timeout. ## Systematic analysis and scope The successful race job [35491083784 / 106026038604](https://github.com/matrixorigin/matrixone/actions/runs/35491083784/job/106026038604) spent 68m27s inside the UT script: light 16m38s, HNSW 38s, exclusive issues 11m04s, embedded 27m16s, engine 4m47s, and the overlapping heavy/plan tail about 7m36s, plus preparation. These are stage wall times, including build/link, not pure test-body times. Package/test elapsed values must not be summed: embedded cluster admission is runner-wide and wait time is included in test elapsed. Local isolated race controls reinforce the need to separate attribution: `TestHashBuildSharedBudgetRecoverySQL` passed in 14.11s (11.90s service startup), and `TestSpeedupAbortAllTxn` in 15.37s (14.93s startup), versus CI elapsed 400.65s and 135.39s. This is a different platform/load and does **not** establish how much of the CI delta is queueing, startup, or resource contention. I did not shrink the spill fixture, remove restarts, raise concurrency, or reduce hang guards based on those totals. This PR removes proven sources of repeated work and oversized packet-fixture allocations inside tests. It does not change production code, test selection, race flags, coverage configuration, cache seeding, or scheduling defaults, and does not duplicate #29113's package-serialization change. Existing fixture reductions in #29141 remain intact. ## Changes and retained contracts | Case | Previous work | New functional work | Retained/strengthened oracle | | --- | --- | --- | --- | | `TestConcurrent` | 64 workers × 20,000 identical searches = 1,280,000 searches | 64 × 2 same-query searches + 64 × 100 varying-query searches = 6,528 | Same 100-vector native index, 64 search slots/workers; shared-query contention and context reuse; every worker visits all vectors; error, both result lengths, nearest key and zero distance checked | | `TestPartitionState_CollectObjectsBetweenInProgress` | 100,000 random draws from only 20 distinct timestamp windows | All 21 ordered windows, including the previously unreachable `(t6,t6]` | Original explicit boundary checks retained; expected complete inserted/deleted sets now detect missing/duplicate results, not only invalid returned objects | Native search workers start behind a readiness barrier and are all joined before index destruction. Worker failures use `Errorf` + return instead of `FailNow` from a worker. Cleanup is registered immediately after successful native allocation. The barrier establishes ready contenders, not a claim of deterministic simultaneous execution inside native code. Native C++ internals are not instrumented by Go's race detector. The long same-query workload remains available as `BenchmarkConcurrentSearch`: one operation is 64 searches; `-benchtime=20000x` retains the original 1,280,000 searches. Result diagnostics are constructed only on failure, instead of reflection-based assertions on every successful search. The UT is not a soak test; long-run interleaving/throughput coverage is explicitly moved to the benchmark rather than claimed equivalent to fewer iterations. ## Measured focused effect Same local checkout/toolchain/native dependencies, Darwin arm64 (Apple M4), Go 1.26.4, `-race -short -count=1`; test elapsed excludes compilation/linking and the package-level race exit delay: | Test | Base `c2a1d63ee08` | Candidate | | --- | ---: | ---: | | `TestConcurrent` | 8.02s | 0.01s | | `TestPartitionState_CollectObjectsBetweenInProgress` | 0.95s | 0.01s | Counts are deterministic: 99.49% fewer native searches in ordinary UT, and 99.979% fewer window queries with exhaustive rather than random coverage. Timings are single local observations, rounded by Go, not a statistical speedup guarantee. No whole-CI speedup or Linux runner before/after result is claimed for these two loop reductions. These two local reductions alone do **not** prove a large reduction in the 68-minute full suite. The retained race benchmark also passed at 20,000 operations × 64 searches: 67,139 ns/batch and 1,049 ns/search locally. Benchmark timing is not directly substituted for test-body timing. ## Validation All commands use `.agents/skills/mo-dev/scripts/mo-cgo-test` so CGo links against this worktree's built native dependencies: - `-race -short -count=1 -json -timeout=2m -run '^TestConcurrent$' ./pkg/vectorindex`: PASS; both named subtests selected. - `-race -short -count=100 -timeout=120s -run '^TestConcurrent$' ./pkg/vectorindex`: PASS, 2.151s package elapsed. Adaptive repetition cap 100, based on the 0.01s focused duration. - `-race -short -count=1 -timeout=3m -v -run '^TestPartitionState_CollectObjectsBetweenInProgress$' ./pkg/vm/engine/disttae/logtailreplay`: PASS; all 21 named windows selected. - `-race -run '^$' -bench '^BenchmarkConcurrentSearch$' -benchtime=20000x -count=1 -timeout=3m ./pkg/vectorindex`: PASS. - `-count=1 -timeout=8m ./pkg/vectorindex ./pkg/vm/engine/disttae/logtailreplay`: both full owning packages PASS, without `-short`. - `-race -count=1 -timeout=5m ./pkg/vectorindex ./pkg/vm/engine/disttae/logtailreplay`: both full owning packages PASS, without `-short`. - `gofmt`, `git diff --check`: PASS. `go test` includes its default vet checks. One initial replay timing command used a non-existent exact test name and selected zero tests; it is excluded from evidence and was replaced by the exact named run above. ## Review and boundaries Focused test-only maintenance: no production architecture/design gate triggered; no SQL/BVT change because neither production behavior nor a public SQL oracle changes. Resource review: one cleanup owner for the native index, release of the start barrier by the parent, worker joins before cleanup, fixed worker/fixture cardinalities; no new scheduler or long-lived global state. Independent GPT-6 medium review of the original two-file diff: **APPROVE, no concrete blockers**. It explicitly verified the shared-query scenario, benchmark batch normalization, native cleanup ordering, and exhaustive timestamp-window oracles. CI is not being waited on as requested. ## Follow-up: reduce frontend packet fixture memory traffic A read-only sample of race job [35496528538 / 106040456596](https://github.com/matrixorigin/matrixone/actions/runs/35496528538/job/106040456596), head `af8e0fe2a45009d4867db7e7456b4b9b2fdaa480`, found frontend.test at 4,233,448 KiB RSS on an 8-CPU/16-GiB runner. This is a hotspot observation, not attribution of the entire process footprint to these tests. Changes in `pkg/frontend/mysql_buffer_test.go`: - Read fixtures borrow immutable payloads through separate header/payload readers rather than repeatedly concatenating fake wire and expected output. ReadErr retains original payload sizes, both rounds, allocation-error/panic injection, and result/leak assertions. - Bad-network tests now fragment actual **reads** (1, 2, 3, 32-KiB limits). Previously fragmented writes were concatenated before reading and did not test short reads. Unfragmented reads still coalesce across packet boundaries. - Explicit matrix retains fixed-buffer boundaries, repeated logical packets, real 16-MiB continuation boundaries, short tails, and empty terminating packets. Five redundant 5-MiB packets become five fixed-buffer-plus-one packets; actual multi-16-MiB continuation cases remain. - Writer fixture wire is preallocated at its known size. Immutable row sources replace per-field/random/expected concatenation allocations; position markers distinguish aligned fields/blocks. Seven writer cases retain multirow batching, many-column and oversized-field paths, exact-max rows/fields, independent packet decoder, exact bytes, sequence and trailing-byte assertions. - Explicit per-test allocators and immediate Conn cleanup release owned buffers and assert allocator balance. No new parallelism, goroutine, production change, or protocol limit reduction. ### Focused resource evidence Same local Darwin arm64 / Go 1.26.4 native build, race binaries compiled through mo-cgo-test with `-race -tags matrixone_test`; baseline af8e0fe versus final frontend diff. Sequential runs, no other test/build running during measurement; five parents: TestMySQLProtocolRead, TestMySQLProtocolReadInBadNetwork, TestMySQLProtocolWriteRows, TestConn_ReadErr, TestConn_ReadOnePayload. Both PASS, `-test.count=1 -test.timeout=5m`, same memory-profile flags. | Metric | Before | After | | --- | ---: | ---: | | Sampled cumulative allocation (MiB) | 4,629.27 | 1,601.65 (-65.4%) | | Process peak RSS (bytes) | 1,604,616,192 | 1,372,192,768 (-14.5%) | | Process user + system CPU | 3.45s | 1.87s (-45.8%) | | Sum of five reported parent test durations | 3.11s | 1.55s | | End-to-end binary wall time, including initialization/profile/exit | 4.78s | 5.03s | These are single local observations with sampling/runtime variance. **Process wall time did not improve in this pair.** The established gain is markedly less fixture allocation and CPU work, not a demonstrated whole-CI speedup or a guarantee of shorter Linux stage time. Lower memory traffic/headroom pressure may help shared-runner contention, but that remains an inference, not measured CI savings. ### Follow-up validation and review - Full frontend normal package, without -short: PASS, 24.805s, via mo-cgo-test with `-count=1 -tags matrixone_test -timeout=8m -json ./pkg/frontend`. - Full frontend race package, without -short: PASS, terminal exit 0, using the wrapper-built final race binary with `-test.v -test.count=1 -test.timeout=8m` from pkg/frontend. - Incremental golangci-lint against af8e0fe for frontend: PASS, 0 issues; gofmt/diff-check PASS. - Focused changed frontend parents with race and count=2: PASS, terminal exit 0; fixture reentry/cleanup verified. - Independent GPT-6 medium follow-up: APPROVE, no remaining code blockers. Its P2 about periodic payloads hiding aligned field duplication was fixed with seed/absolute-position markers and re-reviewed. ReadErr error/panic/cleanup coverage was explicitly checked. - Design exemption: focused test-fixture maintenance only. No production SQL/BVT semantics change; no new concurrent lifecycle requiring stress scheduling. Original vector/replay validations above remain applicable to unchanged files. No merge or wait for CI. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29097
What this PR does / why we need it:
Serialize embedded race-test package execution with
go test -p 1. The existing runner-wide admission lock serializes cluster lifecycles, but it does not bound memory retained by a waiting test binary or competing package build/link and non-cluster work. The previous two-package execution budget left this resource-contention path open on constrained runners.Keep the opt-in prebuild budget separate and unchanged, including its heavy-budget cap. Preserve package selection, race flags, transaction deadlines, reporting, failure propagation, and cancellation cleanup. No partition behavior changes, retries, sleeps, or weakened SQL assertions.
Extend the existing mock scheduler tests to verify serial execution at the real command boundary, exact child failure-code propagation, and overall failure/report handling. Existing prebuild failure and cancellation controls remain covered.
Validation
unexpected embedded parallelism: ... -p 2 ..., then passes with the fix.go test -mod=readonly -v -count=1 -timeout=300s ./optoolspasses (44.709s).git diff --check, andgo vet ./optoolspass.Local validation used Go 1.26.4 on Darwin arm64. Self-review found no unresolved code blockers.
Limitations / tradeoff
The original CI log's two active tests do not prove two simultaneously running clusters; one test had substantial admission wait. CPU throttling and I/O-pressure totals are cumulative, so this change does not claim to prove the original timeout's sole cause.
Serial package execution removes an avoidable contention source at the cost of package-level overlap. Ubuntu 8-core/16-GiB race CI must still validate the original failing test, resource pressure, and total duration. No CI stability or wall-time improvement is claimed from the local mock tests. Optional prebuilding remains disabled by default.