[Bug]: CDC pause/resume can permanently lose a DELETE across a pending-watermark pause

Aperta
#33,277 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@jiangxinmeng1 ci sta già lavorando.

Dal 26/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

area/cdc kind/bug severity/s0

Description

Tested on MatrixOne main commit c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (git_version() = c0cef5c) with a table-level MatrixOne-to-MatrixOne CDC task. The minimal scenario reproduced in 3/3 fresh runs.

If a second PAUSE CDC TASK arrives after the sink transaction is visible but before its durable CDC watermark is published, the next RESUME can permanently omit a DELETE. The task remains running with an empty error and continues replicating later inserts, so this is silent source/sink divergence rather than ordinary replication lag.

Actual behavior

The reproducer below performs two pause/resume rounds:

  1. Initially replicate IDs (1,2) and wait for a nonzero durable watermark.
  2. Pause; commit DELETE 2 + INSERT 3; resume.
  3. As soon as the sink visibly contains (1,3), pause again without waiting for the watermark to advance.
  4. Commit DELETE 3 + INSERT 4; resume.
  5. Insert ID 5 as a liveness control.

Observed in all three runs:

after-resume-1: sink = (1,3)
source:         (1,4,5)
sink:           (1,3,4,5)   -- deleted ID 3 survives permanently
task:           state=running, err_msg=''

ID 5 reaches the sink after the mismatch, and the expected (1,4) state was not reached during a 30-second poll. A control that waits for the durable watermark to advance after every resume converges correctly.

Expected behavior

Every committed source DELETE must eventually be applied exactly once to the sink after resume. The final sink must be (1,4,5). CDC must not advance its watermark past a tombstone that was omitted from the emitted changes, and a pause must not discard watermark state for a transaction already committed to the sink.

Runnable reproduction

Requires Python 3, pymysql, and a local MatrixOne SQL endpoint on 127.0.0.1:6001. Adjust the three endpoint/password constants if necessary. The source and sink are separate databases on the same instance.

Python reproducer
import time
import pymysql

conn = pymysql.connect(
    host='127.0.0.1', port=6001,
    user='root', password='111', autocommit=True,
)

def rows(cur, db):
    cur.execute(f'SELECT id FROM {db}.t ORDER BY id')
    return cur.fetchall()

def wait_rows(cur, expected, timeout=45):
    deadline = time.time() + timeout
    last = None
    while time.time() < deadline:
        try:
            last = rows(cur, 'qa_delins_sink')
            if last == expected:
                return last
        except Exception as e:
            last = str(e).splitlines()[0]
        time.sleep(0.25)
    raise RuntimeError(f'want={expected!r} last={last!r}')

def wait_state(cur, expected, timeout=45):
    deadline = time.time() + timeout
    state = None
    while time.time() < deadline:
        cur.execute("SELECT state FROM mo_catalog.mo_cdc_task "
                    "WHERE task_name='qa_cdc_delins'")
        state = cur.fetchone()[0]
        if str(state).lower() == expected:
            return
        time.sleep(0.25)
    raise RuntimeError(f'state timeout: want={expected} last={state}')

def wait_initial_watermark(cur, timeout=60):
    deadline = time.time() + timeout
    while time.time() < deadline:
        cur.execute("""
            SELECT w.watermark
            FROM mo_catalog.mo_cdc_watermark w
            JOIN mo_catalog.mo_cdc_task t
              ON t.account_id=w.account_id AND t.task_id=w.task_id
            WHERE t.task_name='qa_cdc_delins'
        """)
        row = cur.fetchone()
        if row and row[0] != '0-0':
            print('initial-watermark', row[0])
            return
        time.sleep(0.25)
    raise RuntimeError('initial watermark timeout')

with conn.cursor() as cur:
    cur.execute('DROP CDC IF EXISTS qa_cdc_delins')
    cur.execute('DROP DATABASE IF EXISTS qa_delins_src')
    cur.execute('DROP DATABASE IF EXISTS qa_delins_sink')
    cur.execute('CREATE DATABASE qa_delins_src')
    cur.execute('CREATE DATABASE qa_delins_sink')
    cur.execute('CREATE TABLE qa_delins_src.t(id INT PRIMARY KEY)')
    cur.execute('INSERT INTO qa_delins_src.t VALUES(1),(2)')
    # CREATE CDC on this commit requires a PITR window of at least two hours.
    cur.execute("CREATE PITR IF NOT EXISTS qa_cdc_delins_pitr "
                "FOR ACCOUNT RANGE 2 'h'")
    cur.execute("""
        CREATE CDC qa_cdc_delins
        'mysql://root:[email protected]:6001'
        'matrixone'
        'mysql://root:[email protected]:6001'
        'qa_delins_src.t:qa_delins_sink.t'
        {'Level'='table'}
    """)

    print('initial', wait_rows(cur, ((1,), (2,))))
    wait_initial_watermark(cur)

    cur.execute('PAUSE CDC TASK qa_cdc_delins')
    wait_state(cur, 'paused')
    cur.execute('BEGIN')
    cur.execute('DELETE FROM qa_delins_src.t WHERE id=2')
    cur.execute('INSERT INTO qa_delins_src.t VALUES(3)')
    cur.execute('COMMIT')
    cur.execute('RESUME CDC TASK qa_cdc_delins')
    wait_state(cur, 'running')
    print('after-resume-1', wait_rows(cur, ((1,), (3,))))

    # Deliberately do not wait for watermark publication here.
    cur.execute('PAUSE CDC TASK qa_cdc_delins')
    wait_state(cur, 'paused')
    cur.execute('BEGIN')
    cur.execute('DELETE FROM qa_delins_src.t WHERE id=3')
    cur.execute('INSERT INTO qa_delins_src.t VALUES(4)')
    cur.execute('COMMIT')
    cur.execute('RESUME CDC TASK qa_cdc_delins')
    wait_state(cur, 'running')
    try:
        print('after-resume-2', wait_rows(cur, ((1,), (4,)), timeout=30))
    except RuntimeError as e:
        print('MISMATCH', e)

    cur.execute('INSERT INTO qa_delins_src.t VALUES(5)')
    deadline = time.time() + 30
    while time.time() < deadline:
        if any(row[0] == 5 for row in rows(cur, 'qa_delins_sink')):
            break
        time.sleep(0.25)

    print('source', rows(cur, 'qa_delins_src'))
    print('sink', rows(cur, 'qa_delins_sink'))
    cur.execute("SELECT state,err_msg FROM mo_catalog.mo_cdc_task "
                "WHERE task_name='qa_cdc_delins'")
    print('task', cur.fetchall())
    cur.execute('DROP CDC qa_cdc_delins')

Code analysis and controls

The failure window involves sink commit preceding watermark publication. A pause in that interval can discard the already-committed transaction's pending watermark update. On resume, CDC reads both transactions again; normal net-effect collection folds the replayed INSERT id=3 together with the later DELETE id=3, even though the sink already contains that inserted row. The final watermark then advances beyond the omitted tombstone.

Relevant paths at the tested commit include:

  • pkg/cdc/reader_v2_txn_manager.go: sink commit and watermark-only update ordering.
  • pkg/frontend/cdc_exector.go and pkg/cdc/watermark_updater.go: pause/watermark handling.
  • pkg/cdc/change_handle.go: collection does not retain the trailing DELETE required by this replay case.

Only-DELETE short sequences did not reproduce the mismatch. Repeating the mixed-DML scenario while waiting for a strictly advancing durable watermark after each resume passed, which isolates the bug to the pending-watermark pause window rather than ordinary pause/resume replication.

Duplicate check

Searched CDC pause/resume, watermark, DELETE and net-effect reports. #24797 and #25794 concern inconsistent pause states; #26633 concerns recovery from a target-table error; #30647 concerns sink-outage retries; #30512 concerns source-generation changes. None reports this committed-sink/pending-watermark sequence silently losing a DELETE.

Lingua principale
Go
Stelle
1.9k
Fork
312
Merge medio
22h 59m
PR unite (30g)
736

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di matrixorigin/matrixone

Tutte le issue di matrixorigin/matrixone

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.