JNSimba commented on code in PR #69673:
URL: https://github.com/apache/doris/pull/69673#discussion_r4736998689


##########
fe/fe-core/src/main/java/org/apache/doris/job/offset/jdbc/JdbcSourceOffsetProvider.java:
##########
@@ -160,6 +164,63 @@ public void ensureInitialized(Long jobId, Map<String, 
String> newProps) throws J
                         DataSourceConfigKeys.SNAPSHOT_PARALLELISM_DEFAULT));
     }
 
+    @Override
+    public boolean hasPendingIncludeTablesChange() {
+        return addedTables != null;
+    }
+
+    private boolean hasCommittedIncrementalOffset() {
+        return MapUtils.isNotEmpty(binlogOffsetPersist);
+    }
+
+    @Override
+    public void validateAlterIncludeTables(List<String> updatedTables) throws 
JobException {
+        synchronized (splitsLock) {
+            if (!hasCommittedIncrementalOffset()) {
+                throw new JobException("Cannot alter include_tables before an 
incremental offset is committed");
+            }
+            if (hasPendingIncludeTablesChange() && 
!updatedTables.containsAll(addedTables)) {
+                throw new JobException("Cannot remove newly added tables until 
incremental synchronization resumes");
+            }
+        }
+    }
+
+    @Override
+    public void applyIncludeTablesChange(List<String> updatedTables, 
List<String> addedTables) throws JobException {
+        synchronized (splitsLock) {
+            // CDC fills missing schemas before resuming incremental reads; 
retain existing baselines.
+            String retainedSchemas = filterTableSchemas(tableSchemas, 
updatedTables);
+            if (!hasPendingIncludeTablesChange()) {
+                // Reset snapshot progress while preserving the committed 
incremental offset for resumption.
+                clearSnapshotState();
+                this.addedTables = new ArrayList<>();
+            }
+            // Extend the pending snapshot without resetting its chunks, 
watermarks or splitting cursor.
+            this.addedTables.addAll(addedTables);
+            cachedSyncTables = new ArrayList<>(updatedTables);
+            setTableSchemas(retainedSchemas);
+            hasMoreData = true;
+        }
+    }
+
+    private JdbcOffset createIncrementalOffset() {

Review Comment:
   There are two issues here:
   1. Data duplication: The current "from-to" style code uses `skip_backfill`, 
which effectively results in "at-least-once" semantics.
   2. Schema mismatch: This falls into two categories:
   2.1 If a DDL operation is introduced after a pause at time T0 (and new 
tables are added), and the schema retrieved during the initial fetch is 
uniform, the DDL will be replayed. Downstream systems handle this via 
idempotency; `ADD` and `DROP` operations are supported automatically, while 
unsupported DDL operations will trigger an error—requiring manual intervention 
and a resume. Note that `TRUNCATE` is not supported by the current schema 
change mechanism, which is a known limitation. 
   2.2 If a DDL operation is introduced after a pause at time T0, followed by 
the addition of a new table, the schema for the new table may not match. For 
example, if the schema at T0 was `(id, a)` and at T1 it became `(id, a, a2)`, 
but the CDC process retrieves the schema as `(id, a, a2)`, consumption will 
fail. The upstream Flink CDC cannot handle this scenario, as it only maintains 
the most recent schema.
   In summary, a key limitation is that schema changes occurring during the 
full-load (backfill) phase—specifically when new tables are added—are not 
guaranteed to be handled correctly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to