Skip to content

[Bug]: ALTER TABLE ADD COLUMN permanently kills CDC replication (source generation mismatch, resume is a no-op, silent data loss) despite user guide claiming schema-change support #30645

Closed as not planned

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

b24d1b3 (2026-10-16)

Other Environment Information

  • Hardware: macOS arm64 (Apple Silicon)
  • Topology: two single-node standalone instances (source :16001, sink :16201), same main build
  • OS: macOS

Actual Behavior

ALTER TABLE ... ADD COLUMN on a CDC-replicated source table permanently kills replication for that table with silent data loss, even though the official CDC user guide (pkg/cdc/CDC_USER_GUIDE.md) states the architecture "Handles table schema changes and truncation".

Sequence (database-level CDC, source MO → sink MO):

-- source: create table t (id int primary key, v int); insert 1,10 / 2,20;
create cdc myc 'mysql://root:[email protected]:16001' 'matrixone' 'mysql://root:[email protected]:16201' 'cdd:cddink' {'Level'='database'};
-- baseline sync OK: sink has 1,2 ✓

alter table cdd.t add column extra int default 7;
insert into cdd.t (id,v) values (3,30);   -- never arrives at sink
insert into cdd.t values (5,50,7);        -- never arrives at sink

After the ADD COLUMN:

  1. The task transitions to state=failed with:
    internal error: CDC task myc has permanent table error on cdd.t: check mo_catalog.mo_cdc_watermark.err_msg for details
  2. mo_cdc_watermark.err_msg reveals the root cause:
    internal error: CDC source generation changed from 272647 to 272648 for 0.<uuid>.cdd.t; explicit target rebuild is required
  3. resume cdc task myc is a no-op: state flips back to running momentarily, then fails again on the next change — data continues to be silently dropped (verified: after resume, a fresh insert still never reaches the sink, and state returns to failed).
  4. There is no documented command or mechanism to perform the "explicit target rebuild" the error demands. DROP + re-CREATE the CDC task does not help either (same generation mismatch persists since the sink table keeps the old schema).
  5. Sink retains stale schema (2 columns) and stale data (1,2) while all subsequent rows are lost with no user-visible error unless the user knows to query mo_catalog.mo_cdc_task / mo_cdc_watermark.

Also observed in the same test session (database-level CDC):

  • TRUNCATE on source table is not replicated: after truncate cdd.t, sink keeps its rows (divergence). The user guide claims truncation is handled (L100).
  • CREATE TABLE on source (new table in a database-level task) is not replicated: sink never gets the new table.

Expected Behavior

Per the user guide's own architecture description ("Handles table schema changes and truncation"), ADD COLUMN should either (a) propagate the schema change and continue replicating, or (b) at minimum drop the task into an unambiguous, well-documented terminal state with upgrade instructions. Today it claims to support it but instead enters a permanent half-failed state with silent data loss, and resume misleadingly reports success before failing again.

Steps to Reproduce

  1. Two MO instances (16001 source / 16201 sink)
  2. Source: create database cdd; create table cdd.t (id int primary key, v int); insert into cdd.t values (1,10),(2,20);
  3. Source: create cdc myc 'mysql://root:[email protected]:16001' 'matrixone' 'mysql://root:[email protected]:16201' 'cdd:cddink' {'Level'='database'}; — baseline syncs
  4. Source: alter table cdd.t add column extra int default 7; then insert into cdd.t (id,v) values (3,30);
  5. Sink: row 3 never arrives. select state, err_msg from mo_catalog.mo_cdc_task ... → failed / permanent table error; mo_cdc_watermark.err_msg → "source generation changed ... explicit target rebuild is required"
  6. resume cdc task myc; → state shows running, but a new insert still never arrives and state returns to failed.

Root cause direction

The ADD COLUMN bumps the source table's generation (data version epoch). The watermark machinery intentionally guards against cross-generation replication and demands an "explicit target rebuild", but no rebuild pathway exists in the frontend (no REBUILD/RESYNC CDC subcommand), so the guard turns every schema evolution into a permanent task failure with silent loss. If schema changes are genuinely unsupported, the user guide's architecture section must be corrected and the task should fail loudly at the DDL itself, not strand the pipeline.

Additional information

Activity

  1. added
    kind/bug
    on Oct 20, 2026
  2. added this to the MO-202610 milestone on Oct 20, 2026
  3. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    Scope confirmation: the DROP COLUMN and RENAME COLUMN variants hit the same guard

    Additional test on the same database-level CDC task:

    • alter table dcs.t drop column junk; → identical failure signature: CDC source generation changed from 272650 to 272651 ... explicit target rebuild is required; task straddles running/failed with all subsequent inserts silently dropped (sink stale at 1,2).
    • alter table ... rename column → same permanent failure.

    So the generation guard kills replication for any column-level schema evolution (add/drop/rename), all covered by this issue. The user-guide claim at CDC_USER_GUIDE.md L100 ("Handles table schema changes and truncation") is inaccurate for the entire ALTER family, not just ADD COLUMN.

  4. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    New trigger path: db-level SNAPSHOT RESTORE on the source also kills CDC via the same generation guard

    Third confirmed trigger family member (after ADD/DROP/RENAME COLUMN):

    CDC running (baseline 1,2 synced) → create snapshot → insert id=3 (synced, sink=1,2,3) → restore database rcs {snapshot="..."} → upstream back to 1,2
    

    After the restore:

    • task state still shows running for a window (misleading health signal), but mo_cdc_watermark.err_msg already contains:
      CDC source generation changed from 272655 to 272657 for ...rcs.t; explicit target rebuild is required
    • all subsequent inserts (verified with a fresh row) never reach the sink; task eventually flips to failed.
    • the sink keeps pre-restore data (1,2,3) — diverges permanently from the restored source (1,2) with no automatic reconciliation.

    This means any table-rebuilding source-side operation (column DDL or snapshot restore) is a silent CDC killer. Two additional problems surfaced here:

    1. the transient running state after the fatal condition is set is a false-health signal;
    2. the restore side has no awareness of active CDC tasks (unlike the publication case where restore also drops publications — see [Bug]: RESTORE DATABASE {snapshot=...} silently deletes publications targeting the restored database and never recreates them — subscribers break permanently #30610 — CDC is neither paused, nor failed loudly at restore time, nor documented to conflict).
  5. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    Reproducibility characterization (important for triage)

    Repeated the exact ADD COLUMN scenario in a controlled environment (PITR p1 with range 3h present — CDC requires a ≥2h PITR to be creatable at all, see gate at pkg/frontend/cdc_util.go:440-443) across multiple independent task instances:

    • Earlier runs today: deterministic-looking failures (2/2 then 2/3)
    • Controlled 3-round replication just now: round 1 did NOT trigger (rows fully synced, state healthy, watermark empty) while rounds 2 and 3 did trigger (generation changed error; round 3 ending state=failed).

    So the failure is intermittent but highly frequent (~70-80% per attempt), depending on where the ALTER lands relative to the task internal sync cycle: if the ALTER+insert happen before the first full incremental pass completes, the generation bump can slip through undetected in that window (and the row syncs); once the reader catches up, the mismatch is fatal.

    Data point that matters for fix design: the guard correctly detects the mismatch (the error message is precise), the missing pieces are (a) no schema-evolution path that adapts the sink, and (b) no recovery subcommand — resume cdc task <name> 'restart' (the documented RESTART form, CDC_USER_GUIDE.md L1512) was also tried on a killed task and does not clear a generation mismatch: the task shows running but the watermark error persists and the pending rows still never arrive (see cdc-restart2.sh output).

    Also to demystify a gate encountered: create cdc now requires a PITR of ≥ 2 hours covering the pattern (account/db/table cascade check in CDCCheckPitrGranularityWithExclude). That gate is fine; just noting for the repro environment.

  6. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    This report is now tracked together with #30512. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions