Skip to content

[Bug]: CDC target acknowledgement races with batch watermark scratch cleanup #29752

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

14e9669

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 from readKeysBuffer under 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/embed

Run 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=5m

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions