The checkpointed runtime schema is only restored when {@code schemaChangeEnabled} is true.
+ * Restoring it replaces the schema discovered from the live database at startup, so any column
+ * added while the job was stopped disappears from the produced rows until the change stream
+ * widens the schema again; only a job that propagates schema changes (MySQL DDL events,
+ * PostgreSQL RELATION messages, all gated on {@code schema-changes.enabled}) can do that. A job
+ * with schema change propagation disabled would otherwise keep silently dropping such columns
+ * after every savepoint restore, so it keeps the live-discovered schema, which is the contract
+ * it always had. Debezium table history is restored in both cases: it only drives how the
+ * change stream itself is decoded and is never widened by SeaTunnel.
+ *
+ * @param incrementalSplit the split restored from checkpoint state
+ * @param debeziumDeserializationSchema the deserializer whose runtime state is restored
+ * @param schemaChangeEnabled whether this job propagates source schema changes downstream
+ */
static void restoreCheckpointState(
IncrementalSplit incrementalSplit,
- DebeziumDeserializationSchema debeziumDeserializationSchema) {
+ DebeziumDeserializationSchema debeziumDeserializationSchema,
+ boolean schemaChangeEnabled) {
List checkpointTables = incrementalSplit.getCheckpointTables();
- if (checkpointTables != null && !checkpointTables.isEmpty()) {
+ if (!schemaChangeEnabled) {
+ if ((checkpointTables != null && !checkpointTables.isEmpty())
+ || incrementalSplit.getCheckpointDataType() != null) {
+ log.info(
+ "The incremental split[{}] carries a checkpoint schema, but schema change propagation is disabled for this job, so the live discovered schema is kept instead of restoring the checkpoint schema.",
+ incrementalSplit.splitId());
+ }
+ } else if (checkpointTables != null && !checkpointTables.isEmpty()) {
log.info(
"The incremental split[{}] has {} checkpoint table(s) for restore: {}.",
incrementalSplit.splitId(),
@@ -293,6 +323,26 @@ static void restoreCheckpointState(
}
}
+ /**
+ * Resolves whether the job propagates source schema changes downstream, i.e. the value of
+ * {@code schema-changes.enabled} as every JDBC-based CDC connector forwards it to Debezium's
+ * {@code include.schema.changes}. This is the same switch that gates DDL emission in the MySQL
+ * connector and the RELATION listener in the PostgreSQL connector, so it tells exactly whether
+ * a checkpoint-restored runtime schema can ever be widened again by the change stream. Non-JDBC
+ * sources never emit schema change events and therefore report false.
+ *
+ * @param sourceConfig the reader's source configuration
+ * @return true when schema change propagation is enabled for this job
+ */
+ static boolean isSchemaChangeEnabled(SourceConfig sourceConfig) {
+ if (sourceConfig instanceof JdbcSourceConfig) {
+ return ((JdbcSourceConfig) sourceConfig)
+ .getDbzConnectorConfig()
+ .isSchemaChangesHistoryEnabled();
+ }
+ return false;
+ }
+
private static List restoreLegacyCheckpointTables(
IncrementalSplit incrementalSplit) {
if (incrementalSplit.getCheckpointDataType() instanceof MultipleRowType) {
diff --git a/seatunnel-connectors-v2/connector-cdc/connector-cdc-base/src/test/java/org/apache/seatunnel/connectors/cdc/base/source/reader/IncrementalSourceReaderTest.java b/seatunnel-connectors-v2/connector-cdc/connector-cdc-base/src/test/java/org/apache/seatunnel/connectors/cdc/base/source/reader/IncrementalSourceReaderTest.java
index 39f2dd8d4546..471f1e7b16ee 100644
--- a/seatunnel-connectors-v2/connector-cdc/connector-cdc-base/src/test/java/org/apache/seatunnel/connectors/cdc/base/source/reader/IncrementalSourceReaderTest.java
+++ b/seatunnel-connectors-v2/connector-cdc/connector-cdc-base/src/test/java/org/apache/seatunnel/connectors/cdc/base/source/reader/IncrementalSourceReaderTest.java
@@ -27,6 +27,7 @@
import org.apache.seatunnel.api.table.type.MultipleRowType;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.cdc.base.config.JdbcSourceConfig;
import org.apache.seatunnel.connectors.cdc.base.config.SourceConfig;
import org.apache.seatunnel.connectors.cdc.base.dialect.DataSourceDialect;
import org.apache.seatunnel.connectors.cdc.base.source.offset.Offset;
@@ -44,6 +45,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
+import io.debezium.relational.RelationalDatabaseConnectorConfig;
import io.debezium.relational.TableId;
import java.util.Arrays;
@@ -257,7 +259,7 @@ void restoreCheckpointStateRestoresTablesAndHistoryFromNewCheckpointFormat() {
checkpointTables,
historyTableChanges);
- IncrementalSourceReader.restoreCheckpointState(incrementalSplit, schema);
+ IncrementalSourceReader.restoreCheckpointState(incrementalSplit, schema, true);
Mockito.verify(schema).restoreCheckpointProducedType(checkpointTables);
Mockito.verify(schema).restoreCheckpointHistoryTableChanges(historyTableChanges);
@@ -276,7 +278,7 @@ void restoreCheckpointStateIgnoresEmptyLegacyState() {
Mockito.mock(Offset.class),
Collections.emptyList());
- IncrementalSourceReader.restoreCheckpointState(incrementalSplit, schema);
+ IncrementalSourceReader.restoreCheckpointState(incrementalSplit, schema, true);
Mockito.verifyNoInteractions(schema);
}
@@ -301,7 +303,7 @@ void restoreCheckpointStateRestoresLegacyCheckpointDataType() {
Collections.emptyList(),
checkpointRowType);
- IncrementalSourceReader.restoreCheckpointState(split, schema);
+ IncrementalSourceReader.restoreCheckpointState(split, schema, true);
@SuppressWarnings("unchecked")
ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class);
@@ -339,7 +341,7 @@ void restoreCheckpointStateRestoresLegacyMultipleCheckpointTables() {
Collections.emptyList(),
checkpointRowType);
- IncrementalSourceReader.restoreCheckpointState(split, schema);
+ IncrementalSourceReader.restoreCheckpointState(split, schema, true);
@SuppressWarnings("unchecked")
ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class);
@@ -371,8 +373,94 @@ void restoreCheckpointStateSkipsLegacyCheckpointDataTypeWithoutRecoverableTableI
Collections.emptyList(),
checkpointRowType);
- IncrementalSourceReader.restoreCheckpointState(split, schema);
+ IncrementalSourceReader.restoreCheckpointState(split, schema, true);
Mockito.verifyNoInteractions(schema);
}
+
+ /**
+ * Regression guard for the savepoint-restore column drop: a job that does not propagate schema
+ * changes (the default) must keep the schema discovered from the live database, because nothing
+ * in its change stream could ever widen a checkpoint schema that predates an ADD COLUMN
+ * executed while the job was stopped. Debezium history is still restored, since it only drives
+ * decoding of the stream itself.
+ */
+ @Test
+ void restoreCheckpointStateKeepsLiveSchemaWhenSchemaChangesAreDisabled() {
+ @SuppressWarnings("unchecked")
+ DebeziumDeserializationSchema