Copilot commented on code in PR #4446:
URL: https://github.com/apache/flink-cdc/pull/4446#discussion_r3464198751


##########
flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/source/reader/IncrementalSourceReaderTest.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.cdc.connectors.base.source.reader;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.cdc.connectors.base.config.SourceConfig;
+import org.apache.flink.cdc.connectors.base.source.meta.offset.Offset;
+import org.apache.flink.cdc.connectors.base.source.meta.offset.OffsetFactory;
+import org.apache.flink.cdc.connectors.base.source.meta.split.SnapshotSplit;
+import org.apache.flink.cdc.connectors.base.source.meta.split.SourceRecords;
+import org.apache.flink.cdc.connectors.base.source.meta.split.SourceSplitBase;
+import 
org.apache.flink.cdc.connectors.base.source.meta.split.SourceSplitSerializer;
+import org.apache.flink.cdc.connectors.base.source.meta.split.SourceSplitState;
+import org.apache.flink.cdc.connectors.base.source.metrics.SourceReaderMetrics;
+import org.apache.flink.cdc.debezium.DebeziumDeserializationSchema;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
+import 
org.apache.flink.connector.base.source.reader.synchronization.FutureCompletingBlockingQueue;
+import org.apache.flink.connector.testutils.source.reader.TestingReaderContext;
+import org.apache.flink.table.types.logical.IntType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.util.Collector;
+
+import io.debezium.relational.TableId;
+import org.apache.kafka.connect.source.SourceRecord;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.function.Supplier;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link IncrementalSourceReader}. */
+class IncrementalSourceReaderTest {
+
+    @Test
+    void testInitializedStateAppliesSplitToRecordEmitter() {
+        TestingReaderContext readerContext = new TestingReaderContext();
+        TrackingRecordEmitter recordEmitter =
+                new TrackingRecordEmitter(new 
SourceReaderMetrics(readerContext.metricGroup()));
+        TestingIncrementalSourceReader reader =
+                new TestingIncrementalSourceReader(
+                        recordEmitter, new 
IncrementalSourceReaderContext(readerContext));
+
+        SnapshotSplit split =
+                new SnapshotSplit(
+                        new TableId("catalog", "schema", "table"),
+                        "split-0",
+                        RowType.of(new IntType()),
+                        null,
+                        null,
+                        null,
+                        Collections.emptyMap());

Review Comment:
   The test uses the `@Internal` SnapshotSplit constructor with a custom 
splitId ("split-0"), but SnapshotSplit’s Javadoc warns this constructor should 
not be used directly and the splitId format must match generateSplitId(...) for 
parsing to work. Using the public constructor (tableId + chunkId) avoids 
depending on internal behavior and makes the test future-proof.



##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-sqlserver/src/main/java/org/apache/flink/cdc/connectors/sqlserver/source/reader/SqlServerPipelineRecordEmitter.java:
##########
@@ -124,33 +129,28 @@ private void emitAllCreateTableEvents(SourceOutput<T> 
output) {
 
     @SuppressWarnings("unchecked")
     private void emitCreateTableEventIfNeeded(
-            io.debezium.relational.TableId tableId, SourceOutput<T> output) {
+            io.debezium.relational.TableId tableId,
+            SourceOutput<T> output,
+            SourceSplitState splitState) {
         if (alreadySendCreateTableTables.contains(tableId)) {
             return;
         }
 
+        
cacheCreateTableEventsFromSchemas(splitState.toSourceSplit().getTableSchemas());
         CreateTableEvent createTableEvent = createTableEventCache.get(tableId);
-        if (createTableEvent != null) {
-            output.collect((T) createTableEvent);
-        } else {
-            // Table not in cache, fetch schema from database
-            try (SqlServerConnection jdbc =
-                    
createSqlServerConnection(sourceConfig.getDbzConnectorConfig())) {
-                createTableEvent = buildCreateTableEvent(jdbc, tableId);
-                output.collect((T) createTableEvent);
-                createTableEventCache.put(tableId, createTableEvent);
-            } catch (SQLException e) {
-                throw new RuntimeException("Failed to get table schema for " + 
tableId, e);
-            }
+        if (createTableEvent == null) {
+            throw new IllegalStateException(
+                    "Missing CreateTableEvent for table "
+                            + tableId
+                            + ". Table schema should have been restored before 
processing records.");
         }

Review Comment:
   Changing the cache-miss behavior from a JDBC fallback to an 
IllegalStateException makes the job fail hard if the CreateTableEvent cache is 
incomplete (e.g., restoring from an older savepoint format, a newly added table 
whose schema wasn’t present in split state, or any unexpected cache eviction). 
Other pipeline emitters (e.g., 
MySqlPipelineRecordEmitter/PostgresPipelineRecordEmitter) retain a best-effort 
JDBC fallback for these rare cases. Consider restoring the previous fallback 
(still only one lookup per table) to preserve operational robustness.



-- 
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]

Reply via email to