Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
Linux amd64, Go 1.27.1, race detector, matrixone_test tags. One local embedded CN; GOMAXPROCS=4. Existing unrelated service was left running. Independent temporary directory and port leases.
Actual Behavior
The existing TestCDCGenerationReplacementOnMO completes its SQL assertions but fails with a data race between:
CDCWatermarkUpdater.finishTargetAcknowledgement, watermark_updater.go:1770: deletes a key fromreadKeysBufferunder the updater cache mutex.CDCWatermarkUpdater.resetJobs, watermark_updater.go:488: clears the same map in the batch queue worker without that mutex.
readKeysBuffer is batch-worker scratch storage; onJobs and execReadWM also access it without the cache mutex. Holding the cache mutex in the ACK path cannot synchronize these accesses. This is a production CDC concurrency defect, not an assertion timeout. A race on a Go map can corrupt processing or terminate the process; those outcomes were not observed in this run.
Expected Behavior
Target acknowledgement must preserve the single ownership of batch scratch storage and prevent stale batch read results from overwriting acknowledged watermark/generation state. Concurrent ACK, batch execution and cleanup must be race-free without holding the cache mutex across database queries or callback waits.
Steps to Reproduce
Build the existing embed tests at the commit above using the repository CGo wrapper:
.agents/skills/mo-dev/scripts/mo-cgo-test -tags matrixone_test -vet=off -p 1 -race -c -o /tmp/embed.test ./pkg/embedRun from the pkg/embed package directory with an owned writable TMPDIR and matching native library paths:
GOMAXPROCS=4 /tmp/embed.test -test.v -test.run='^TestCDCGenerationReplacementOnMO$' -test.timeout=5mOne observed invocation failed after 132.56 seconds with WARNING: DATA RACE and the two mapdelete paths above. Reproduction is timing dependent; a deterministic regression is needed in the updater owning package.
Additional information
Found while preparing a performance baseline for #29562. Performance optimization must not hide this race by altering scheduling. Local evidence: /mnt/nvme/ut-opt-local/cdc-baseline.log; no source changes were present during reproduction.
Activity
fix(cdc): keep batch scratch private and preserve acknowledged progress
perf(optools): batch exclusive race tests safely
fix(cdc): keep batch scratch private and preserve acknowledged progress
perf(optools): batch exclusive race tests safely
perf(optools): bound race UT critical path safely (#29760)