Repository navigation
fix(disttae): hand alpha stats workers a detached table stock snapshot - #30926
Conversation
tableStatsExecutor handed alphaTask a slice aliasing dynamicCtx.tableStock.tbls's backing array. alphaTask dispatches its pairs to an ants pool whose workers write the handed-over tablePair elements (pState, errChan) without holding d.Lock - the invocation owns that memory exclusively - and alphaTask itself rewrites and reslices tbls as batches advance. A concurrent tableStatsExecutor invocation for the same dynamicCtx (a cron retrigger or heartbeat-expiry window racing the async-task row update that guards the executor's Concurrency=1 admission) mutates the same backing array under d.Lock: getChangedTableList appends to it (in-place writes, then growslice reads and copies the old elements) and cleanTableStock nils and truncates it. The unsynchronized worker element writes therefore race the locked collector rewrites, which is the data race reported in issue matrixorigin#27702 (an ants worker writing tbls[i].pState while getChangedTableList appended to the same backing array through runtime.growslice). The stock now stays exclusively inside the d.Lock discipline: snapshotTableStock takes the lock and returns an exact-size copy of the pending pairs, and the executor's per-tick handoff runStatsCollectionRound passes that detached snapshot to alphaTask, so every round owns its pairs through completion and no unsynchronized element memory is shared between overlapping rounds. alphaTask's exclusive-ownership caller contract is documented at its definition. The added copy is one stock length per round under the lock, dominated by the per-table work the round performs anyway. The regression drives this production handoff function under the race detector. With the base aliasing expression restored in that single executed hunk, the same byte-identical test reports the data race at the assigned base (3 race reports at -count=1, 6 at -count=10, exit 1); with this change it completes the round without the not-running-beta timeout, returns context.Canceled when an in-flight round is canceled, and the whole owning disttae package stays green under -race and in normal mode. Related to matrixorigin#27702
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? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 6f3a042b8e192f33343a78680f9e633c0d8060f9
Assessment: approve
Reviewed the complete two-file delta, callers, ownership, cancellation, cleanup and test design. The locked snapshot correctly gives alpha workers exclusive ownership without holding the collector lock during worker I/O. Shallow copying is sufficient because stock builders leave worker-owned pointers and channels unset. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Confirmed exact HEAD, clean source, complete frozen patch, formatting and whitespace. Isolation preflight passed; native prerequisites were built from matching revision inputs.
-
The focused regression passed under the race detector, followed by 100 successful repetitions covering collection and cancellation.
-
A diagnostic overlay restoring only the old slice alias reproduced four data-race reports with the committed tests unchanged. Its expected failure confirms regression sensitivity.
-
The handoff benchmark measured one allocation per nonempty snapshot: approximately 0.10 ms/1 MiB for 8,192 entries and 21.7 ms/122 MiB for one million entries. This linear background-round cost is justified by ownership isolation; foreground SQL paths do not invoke the new handoff.
-
Reused the frozen exact-head CI snapshot reporting successful build, UT, coverage, static analysis and BVT checks.
-
Commands, source fingerprints, exit receipts and retained logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/c044761b3cfd689b45d9fc44/attempt-1/validation-report.json; review coverage is recorded in review-scope.json.
Limitations:
-
The focused fixture exercises the production handoff and alpha workers with a controlled queue consumer, not full scheduler execution or beta SQL persistence.
-
Performance measurements isolate handoff cost; they do not establish end-to-end SQL throughput or contended-lock latency.
-
Broad CI evidence consists of the supplied exact-head status snapshot, without raw CI logs. The linked issue's original incident artifacts were not supplied.
|
@Mergifyio queue |
Merge Queue Status
This pull request spent 4 hours 40 minutes 26 seconds in the queue, with no time running CI. ReasonThe merge conditions cannot be satisfied due to failing checks
Failing checks: HintYou may have to fix your CI before adding the pull request to the queue again. Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
|
The What happened: the queue's in-place merge pulled the new Why it is unrelated: this PR's delta is only the disttae statistics collector's alpha-worker snapshot handoff ( Blocker removal is verified resolution of the linked issue / a passing coverage run at a current head. |
What type of PR is this?
Which issue(s) this PR fixes:
Related to #27702
What this PR does / why we need it:
Removes the data race in the mo_table_stats pipeline reported in issue #27702 by making each stats collection round own a detached snapshot of the pending changed tables.
Root cause
tableStatsExecutorhands the batch of pending changed tables toalphaTaskonce per tick, after itspreparestep (getChangedTableList) appended those tables todynamicCtx.tableStock.tbls. Before this change the handoff passedd.tableStock.tbls[:], a slice aliasing the stock's backing array. Two owners then touched the same element memory under different synchronization rules:alphaTasksubmits its pairs to an ants pool. Each worker writes thetablePairelement it was handed (pState, and the payloaderrChan) without holdingd.Lock— collection code treats the handed-over slice as exclusive to the invocation — andalphaTaskitself rewrites and reslicestblsas batches advance.tableStatsExecutorinvocation for the samedynamicCtxcan overlap it (a cron retrigger or heartbeat-expiry window racing the async-task row update that guards the executor's Concurrency=1 admission). It mutates the same backing array while holdingd.Lock:getChangedTableListappends (in-place writes until capacity is exhausted, thenruntime.growslicereads and copies the old elements), andcleanTableStocknils out and truncates the slice.The result is the CI-captured pair reported in the issue: an ants worker writing
tbls[i].pStatewhile another round'sgetChangedTableListappended to the same backing array.Exact change
pkg/vm/engine/disttae/mo_table_stats.go:dynamicCtx.snapshotTableStock(): takesd.Lockand returns an exact-size copy ofd.tableStock.tbls, so the collection round's memory is detached from the collector's stock.dynamicCtx.runStatsCollectionRound(ctx, service): the executor's per-tick handoff, now a named production seam that callsalphaTask(ctx, service, d.snapshotTableStock(), "main routine").tableStatsExecutorcalls it in place of the previous inline aliasing handoff.alphaTask's doc comment now states the exclusive-ownership caller contract: its pool workers write the handed-over elements withoutd.Lock, so the slice must be exclusive to the invocation.pkg/vm/engine/disttae/mo_table_stats_test.go— newTestTableStatsExecutorDetachesStockFromAlphaTaskwith two subtests, both driving the productionrunStatsCollectionRoundhandoff (not a test copy of it):collects a round while another collector mutates the stock: a produced-pair phase barrier proves a worker already wrote and transmitted its element while the round is still in flight; a second collector's stock mutation (cleanTableStockplus locked appends withcap == lengrowth, reproducinggetChangedTableList's append and the growslice read of the CI report) overlaps the remaining worker; the round must complete withtimeout == false,err == nil, and the stock afterwards must contain only collector-written elements.cancellation of an in-flight round reports ctx error: behind the same phase barrier, mid-flight cancellation must returncontext.Canceledwhile the stock stays consistent.Doneper pair (matchingerrWaitToReceive;launchTaskis a no-op so no production beta task consumes the queue), represents that consumer as the running beta soalphaTaskcannot end the round through its not-running-beta timeout shortcut, gives every round its owncontext.WithCancelwith a joined cancellation cleanup, and uses one-minute select deadlines instead of sleeps.Issue-to-test proof (red/green on the same byte-identical test)
The committed test was run against the assigned base
6cbe375b496with the production handoff alone restored to the base aliasing expression — the only executed production difference between the two trees; the test files are byte-identical on both sides (SHA25641a094cb847b499817b813eb53223a27d2b4f2cc88b99a6e5faccaccb7c0622d):-racerun at-count=1: exit 1 with 3WARNING: DATA RACEreports; the recorded pair is the production ants worker's element write (alphaTask.func2,mo_table_stats.go:2101, reached throughrunStatsCollectionRound) racing the locked collector'scleanTableStockrewrite (mo_table_stats.go:1727), with alpha logs showingprocessed=2/1— real in-flight work, no early exit. Repeated at-count=10: 6 race reports, exit 1.-raceat-count=1(both subtests) and at-count=100(ok 5.138s); the cancel subtest returnscontext.Canceled../pkg/vm/engine/disttae/green under-race(ok 16.035s) and in normal mode (ok 12.507s); full package selection (583 tests, including the pre-existingTestAlphaTask) verified non-empty.Test commands
pkg/vm/engine/disttaeis CGo-transitive; natives come frommake cgoand the repository's CGo test wrapper is used:All of the above pass on this change; the RED runs are reproduction-only evidence recorded at the base ownership harness and are not part of this branch.
Residual risks
tableStatsExecutorinvocations remain possible at the cron-framework level; after this change each round owns a detached snapshot, so no unsynchronized element memory is shared. Duplicate pair processing throughtblQueueis a pre-existing framework trait outside this change.snapshotTableStockadds one exact-size element copy per round underd.Lock, bounded by the stock length and dominated by the per-table I/O the round performs anyway.onlyUpdateTS(no production builder creates such pairs today),betaTask's batch path sends a secondDoneper pair and, under adverse scheduling, can send on a closederrQueue. This regression's fixture consumer sends exactly oneDoneper pair and exercises the alpha side only.