Skip to content

[Fix][Connector-V2] Preserve disabled CDC schema behavior - #12346

Merged
nzw921rx merged 1 commit into
apache:devfrom
zhangshenghang:fix/12344-opengauss-cdc-schema-restore
Sep 20, 2026
Merged

nzw921rx merged 1 commit into
apache:devfrom
zhangshenghang:fix/12344-opengauss-cdc-schema-restore

Conversation

@zhangshenghang

Copy link
Copy Markdown
Member

Purpose

Fixes #12344.

What happened

After an OpenGauss CDC job was restored from a savepoint following an ADD COLUMN on the source table, the PostgreSQL-based CDC source rebuilt its deserializer with the savepoint schema even though schema evolution was disabled. The restored source then produced rows using an outdated column definition, so the existing OpenGauss restore E2E test failed consistently.

Changes

  • Create the PostgreSQL relation schema resolver only when schema-changes.enabled = true.
  • Preserve the current live schema for the default disabled configuration, maintaining backward-compatible behavior for OpenGauss CDC.
  • Add unit coverage for both enabled and disabled resolver creation paths.
  • Keep the OpenGauss restore E2E scenario as regression coverage.

Verification

  • ./mvnw -nsu spotless:apply
  • ./mvnw -nsu -pl :connector-cdc-postgres -Dtest=PostgresIncrementalSourceSchemaEvolutionTest test
  • ./mvnw -nsu -pl :connector-cdc-opengauss,:connector-cdc-postgres -DskipTests compile
  • ./mvnw -nsu -pl :connector-cdc-opengauss-e2e -DskipUT=true -DskipIT=false -Dit.test=OpengaussCDCIT#testAddFieldWithRestore verify

The targeted unit test passed (2 tests) and the OpenGauss CDC restore E2E passed (1 test).

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Problem Does This PR Solve?

PostgresIncrementalSource#createDebeziumDeserializationSchema always wired a
PostgresRelationSchemaChangeResolver into the deserializer, regardless of whether
schema-changes.enabled was true or false (the default). A non-null
SchemaChangeResolver has a second, less obvious effect besides parsing live RELATION
messages: SeaTunnelRowDebeziumDeserializeSchema#restoreCheckpointProducedType() only
applies the checkpoint's saved table schema when schemaChangeResolver != null
(connector-cdc-base/.../SeaTunnelRowDebeziumDeserializeSchema.java:360-362). So even
with schema evolution disabled, every job restore silently overwrote the freshly
discovered live schema with the (possibly stale) schema captured at savepoint time.

Concretely: user runs a Postgres/openGauss CDC job with schema-changes.enabled=false
(default), takes a savepoint, then does an out-of-band ADD COLUMN on both source and
sink tables (the documented workflow when evolution propagation is off), and restores
the job. Because the resolver was non-null, restoreCheckpointProducedType clobbered
the newly-discovered live schema with the old savepoint schema, so the deserializer kept
parsing rows with the pre-ADD COLUMN column set and dropped/mis-mapped the new column.
This is exactly what OpengaussCDCIT#testAddFieldWithRestore reproduces, and per issue
#12344 it has been failing 100% of CI runs on dev (24/24 legs across two unrelated
PRs), blocking the required Build check for everyone.

This PR makes resolver creation conditional on schema-changes.enabled, so the disabled
(default) path now gets a null resolver and restoreCheckpointProducedType correctly
skips the checkpoint-schema overwrite, preserving the live schema on restore — matching
the pre-existing behavior before schema evolution support was added.

1. Code Change Review

1.1 Core Logic Analysis

Before (introduced by #11922, 8bea8c68):

.setSchemaChangeResolver(new PostgresRelationSchemaChangeResolver())

After (this PR):

.setSchemaChangeResolver(createSchemaChangeResolver(config))
...
static SchemaChangeResolver createSchemaChangeResolver(ReadonlyConfig config) {
    return config.get(SourceOptions.SCHEMA_CHANGES_ENABLED)
            ? new PostgresRelationSchemaChangeResolver()
            : null;
}

Real call chain (verified in source, not just PR description):

  • IncrementalSourceReader.restoreCheckpointState() (connector-cdc-base/.../reader/IncrementalSourceReader.java:258-283) is the normal split-restore entry point (called whenever an IncrementalSplit carries checkpointTables, i.e. every restore-from-savepoint/checkpoint of a snapshot-completed split with an evolvable schema) — not an exception/recovery-only branch.
  • It calls debeziumDeserializationSchema.restoreCheckpointProducedType(checkpointTables).
  • SeaTunnelRowDebeziumDeserializeSchema.restoreCheckpointProducedType() (connector-cdc-base/.../row/SeaTunnelRowDebeziumDeserializeSchema.java:356-396) starts with if (schemaChangeResolver == null) { return; } — this early-return is the actual fix mechanism this PR activates for the disabled case; it is pre-existing code, not touched by this PR.
  • Before this PR, PostgresIncrementalSource always supplied a non-null resolver, so this guard never triggered for Postgres/openGauss, and the checkpoint's stale checkpointTables always overwrote this.tables, silently discarding any live-schema ADD COLUMN applied while the job was stopped.
  • After this PR, when schema-changes.enabled=false (the default), the resolver is null, the guard fires, and the live schema built during job (re)initialization is kept.

Runtime flow:

Savepoint job -> (out-of-band ADD COLUMN on source+sink) -> restore job
  -> PostgresIncrementalSource.createDebeziumDeserializationSchema(config)
       -> createSchemaChangeResolver(config)      [THIS PR: gated on schema-changes.enabled]
  -> IncrementalSourceReader.restoreCheckpointState(split, deserializationSchema)
       -> deserializationSchema.restoreCheckpointProducedType(checkpointTables)
            -> if (schemaChangeResolver == null) return;   [pre-existing guard, now reachable]
  -> deserializer keeps the live schema discovered at restore time
     instead of the stale savepoint schema

I confirmed via git log --follow on PostgresIncrementalSource.java that the
unconditional resolver wiring was introduced by #11922 ("Support PostgreSQL CDC ADD
COLUMN schema evolution"), i.e. this is a genuine regression fix, not a
long-standing pre-existing limitation.

Sibling-connector precedent: SqlServerIncrementalSource.java:161-162 already does
exactly this same schemaChangesEnabled ? new SqlServerSchemaChangeResolver() : null
gating. This PR brings Postgres in line with the already-correct SQL Server pattern
rather than inventing a new mechanism, which lowers the risk of this change
considerably.

Verification the claimed problem is real (not just trusting the PR description):
issue #12344 shows OpengaussCDCIT.testAddFieldWithRestore failing 24/24 CI legs on two
unrelated PRs with actual iterable was <null> at index [1][4] — exactly consistent
with the sink never receiving rows for the new column after restore because the
deserializer's schema was reverted to the pre-ADD-COLUMN savepoint schema. The E2E job
config (opengausscdc_to_opengauss_test_add_Filed.conf) does not set
schema-changes.enabled, so it runs the default-disabled path this PR fixes.

Observation (non-blocking, out of scope for this PR): MySqlIncrementalSource and
OracleIncrementalSource (connector-cdc-mysql/.../MySqlIncrementalSource.java:275-276,
connector-cdc-oracle/.../OracleIncrementalSource.java:177-179) still construct their
SchemaChangeResolver unconditionally, without consulting
SourceOptions.SCHEMA_CHANGES_ENABLED, and AbstractSchemaChangeResolver has no
internal enabled-check either. If restoreCheckpointProducedType's null-guard is indeed
the intended contract for "schema evolution disabled" mode, MySQL and Oracle CDC may
have the same restore-time live-schema-loss bug this PR fixes for Postgres. I'd
recommend filing a follow-up issue to audit those two connectors — not a blocker here
since it's a different module/file set with its own regression history.

1.2 Compatibility Impact

Fully compatible.

  • No config option added, renamed, or given a new default; schema-changes.enabled
    keeps its existing default (false) and documented semantics
    (docs/en/connectors/source/PostgreSQL-CDC.md:119).
  • No public API/SPI signature changes visible outside the module; the new
    createSchemaChangeResolver is package-private (used by the new unit test in the same
    package).
  • For schema-changes.enabled=true users, behavior is byte-for-byte identical to
    pre-PR (resolver still constructed).
  • For schema-changes.enabled=false users (the default, and effectively every
    production job created before #11922 added this option), this PR removes a
    restore-time schema regression introduced by #11922 and restores the schema-preserving
    behavior these connectors had before that feature landed. It changes runtime behavior
    only in the direction of fixing incorrect data loss, not in a way that breaks any
    documented contract.

1.3 Performance / Side-Effect Analysis

Negligible and strictly positive for the disabled path: when
schema-changes.enabled=false, one object allocation
(PostgresRelationSchemaChangeResolver) is avoided per source instantiation, and
restoreCheckpointProducedType's stream/collector work
(connector-cdc-base/.../SeaTunnelRowDebeziumDeserializeSchema.java:364-395) is now
skipped entirely on restore instead of being done and then silently corrupting state.
No new locking, retries, network calls, or unbounded structures are introduced. Nothing
changes for the enabled path.

1.4 Error Handling and Logging

No new exception paths. No log statements added or removed at non-comment lines. No
sensitive data involved.

Issue 1: createSchemaChangeResolver's null branch has no comment explaining its
cross-file effect

  • Location: seatunnel-connectors-v2/connector-cdc/connector-cdc-postgres/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/postgres/source/PostgresIncrementalSource.java:138-142
  • Problem description: The ternary silently decides whether
    SeaTunnelRowDebeziumDeserializeSchema.restoreCheckpointProducedType() — in a
    different module file — will apply or skip the checkpoint schema on restore. That
    contract (schemaChangeResolver == null ⇒ "keep live schema on restore") is not
    discoverable from this file at all; a future maintainer editing either side of this
    contract independently could silently reintroduce the #11922 regression or break the
    enabled path without realizing the two are linked.
  • Potential risk: Silent regression reintroduction (exactly this bug) by a future
    change that "cleans up" one side without knowing about the other.
  • Best improvement: Add a short comment on createSchemaChangeResolver (or right
    above the .setSchemaChangeResolver(...) call) stating that returning null here is
    load-bearing: it makes restoreCheckpointProducedType skip applying the checkpoint's
    saved schema and keep the live schema discovered at restart, per the pattern also used
    by SqlServerIncrementalSource.
  • Severity: Medium
  • Raised by another reviewer: No

2. Code Quality Assessment

2.1 Coding Standards

Formatting, license header (new test file has it), and import style all look correct.
createSchemaChangeResolver is package-private rather than private, which is a
reasonable, minimal choice purely to make it unit-testable without reflection — no
concerns there. See Issue 1 above for the one comment gap; no other missing-Javadoc
findings (the two new @Test methods are simple, self-explanatory, and JUnit
test methods are not required to be public/documented here per project convention).

2.2 Test Coverage and Test Stability

  • PostgresIncrementalSourceSchemaEvolutionTest directly calls the real
    PostgresIncrementalSource.createSchemaChangeResolver(config) under test (not a
    reimplementation/mock of the logic), covering both the enabled and disabled branches —
    this is the right level of test, hitting the exact code path that was broken.
  • The existing OpengaussCDCIT.testAddFieldWithRestore E2E scenario is kept unchanged
    in logic (only a clarifying comment edit) and continues to serve as the regression
    test for the restore-preserves-live-schema behavior; per the PR description it now
    passes.
  • Test-stability rating: Stable. The unit test is a pure, deterministic function
    call with no timing/async/shared-state involved. The E2E diff is a comment-only
    change — no Thread.sleep, no assertion changes, no altered wait windows,
    no new shared/static state introduced.

2.3 Documentation Updates

Not required. docs/en/connectors/source/PostgreSQL-CDC.md and
docs/zh/connectors/source/PostgreSQL-CDC.md already document
schema-changes.enabled with its existing default (false) and scope; this PR does not
change the documented option contract, only fixes an internal implementation bug that
violated it. No docs/en/introduction/concepts/incompatible-changes.md entry is needed
since nothing here is an incompatible change.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise fix. The change is a minimal, root-cause fix at the exact point the
regression was introduced (PostgresIncrementalSource.createDebeziumDeserializationSchema),
using a pattern that already exists and is proven in a sibling connector
(SqlServerIncrementalSource), rather than adding a workaround elsewhere (e.g. a special
case inside restoreCheckpointProducedType, or skipping the E2E test).

3.2 Maintainability

Good, once Issue 1's comment gap is addressed — the cross-file null-contract is the only
thing that makes this code harder to maintain than it needs to be.

3.3 Extensibility

The SchemaChangeResolver-nullability pattern is now established/reinforced for one
more connector; see the non-blocking MySQL/Oracle observation in 1.1 for where the same
pattern may still be missing.

3.4 Historical-Version Compatibility

This PR targets apache/seatunnel dev only (no Whale-specific 2.6/3.0 upgrade path
involved). It restores default (schema-evolution-disabled) behavior to what it was
before #11922 introduced Postgres CDC schema evolution support, so any already-released
version that included #11922 was shipping this regression for default-configured jobs;
this PR is a straightforward correctness fix for that released defect and does not
require any migration guidance since no persisted format, config key, or public
contract changes.

4. Issue Summary

Number Issue Location Severity
1 Missing comment explaining createSchemaChangeResolver's null branch and its link to restoreCheckpointProducedType PostgresIncrementalSource.java:138-142 Medium

5. Merge Recommendation

Conclusion: Ready to merge after fixes

  1. Blockers — must be fixed: none.
  2. Recommended fixes — non-blocking:
    • Issue 1: add a short comment documenting the null-resolver restore contract, to
      prevent this exact regression from being silently reintroduced later.
    • Consider filing a follow-up issue to audit MySqlIncrementalSource /
      OracleIncrementalSource for the same unconditional-resolver pattern (see 1.1).

Overall assessment: this is a well-targeted, minimally-invasive, root-cause fix for a
real, CI-proven, 100%-reproducible regression (issue #12344) that is currently blocking
the required Build check on dev for unrelated PRs. The mechanism was verified end to
end in source (not just trusted from the PR description), it follows an existing sibling
connector's pattern, and it ships focused unit-test coverage of the exact fixed method
plus retains the E2E regression test. I'm not aware of any other maintainer review on
this PR yet. CI (Build, run in the contributor's fork) was still in_progress at
review time — please confirm it turns green before merging.

Thanks for tracking this down to the exact root cause and fixing it at the source
instead of just patching the E2E test's timing/assertions — that's exactly the kind of
fix we want here.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI was previously the only remaining item (the fork's Build run was still in_progress at review time, and my earlier conclusion listed zero hard blockers). I just confirmed the fork's actual Build run for the current head commit completed successfully, so I'm updating this to approve.

The one item from my earlier review (a short comment documenting why createSchemaChangeResolver returning null is load-bearing for restoreCheckpointProducedType) was explicitly non-blocking — still a nice-to-have for a future maintainer, but not required before merge.

SEZ9 pushed a commit to SEZ9/seatunnel that referenced this pull request Sep 20, 2026
Backport apache#12346 to retain the current table schema when
restoring PostgreSQL/OpenGauss CDC with schema evolution disabled.

Source: af5572d
Keep this dependency separate from the REST change so it can be dropped
when the upstream base contains the fix.
SEZ9 pushed a commit to SEZ9/seatunnel that referenced this pull request Sep 20, 2026
Backport apache#12346 to retain the current table schema when
restoring PostgreSQL/OpenGauss CDC with schema evolution disabled.

Source: af5572d
Keep this dependency separate from the REST change so it can be dropped
when the upstream base contains the fix.

@nzw921rx nzw921rx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 good job

@nzw921rx
nzw921rx added this pull request to the merge queue Sep 20, 2026
Merged via the queue into apache:dev with commit ea3df16 Sep 20, 2026
4 checks passed
@goutamadwant goutamadwant mentioned this pull request Sep 22, 2026
1 of 4 tasks
davidzollo added a commit to davidzollo/seatunnel that referenced this pull request Oct 5, 2026
Reconcile the PG base CDC abstraction with the dev changes that landed on
the pre-refactor Postgres CDC classes:

- apache#12346: keep the schema-change resolver conditional on
  schema-changes.enabled in the PG-base-backed PostgresIncrementalSource
- apache#11399: keep database.include.list unset; the rationale comment moves to
  PgBaseSourceConfigFactory where the Debezium properties are assembled now,
  and the regression assertion is kept in PostgresSourceConfigFactoryTest
- apache#12447: take the corrected server-time-zone / connect.timeout.ms rows in
  the Opengauss-CDC docs and keep the require-replica-identity-full row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][E2E] OpengaussCDCIT.testAddFieldWithRestore fails on every CI run, blocking unrelated PRs

3 participants