You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "yuxiqian (via GitHub)" <gi...@apache.org> on 2025/02/08 03:44:59 UTC

[PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

yuxiqian opened a new pull request, #3912:
URL: https://github.com/apache/flink-cdc/pull/3912

   This closes FLINK-37278.
   
   Currently, regular SE topology uses the following POC to drain existing `DataChangeEvent`s in the pipeline:
   
   1. SchemaOperator ("client") emits `FlushEvent` to downstream.
   2. The "client" keeps polling the SchemaCoordinator ("server") with 1-second interval.
   3. The "server" rejects all requests from clients until it has collected enough `FlushSuccessEvent` notifications from Sink.
   
   As a result, all schema change requests will took at least 1 second to finish, after at least  one polling interval.
   
   ---
   
   This PR replaces the polling code with maintaining a pending schema change request queue, where SchemaCoordinator could manage all pending clients and effectively blocking them from handling upstream events. Schema evolution process could start immediately after `FlushSuccessEvent` got reported, needless to wait for polling requests from clients.
   
   ---
   
   With this change, time consumption of `testRegularTablesSourceInMultipleParallelism` test case has been reduced from ~6 minutes to ~50 seconds.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "lvyanquan (via GitHub)" <gi...@apache.org>.
lvyanquan commented on code in PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#discussion_r1976847009


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/operators/schema/regular/SchemaCoordinator.java:
##########
@@ -73,16 +75,13 @@ public class SchemaCoordinator extends SchemaRegistry {
     /** Executor service to execute schema change. */
     private final ExecutorService schemaChangeThreadPool;
 
-    /**
-     * Atomic flag indicating if current RequestHandler could accept more schema changes for now.
-     */
-    private transient RequestStatus schemaChangeStatus;
-
     /** Sink writers which have sent flush success events for the request. */
     private transient ConcurrentHashMap<Integer, Set<Integer>> flushedSinkWriters;
 
-    /** Currently handling request's completable future. */
-    private transient CompletableFuture<CoordinationResponse> pendingResponseFuture;
+    /** Currently handling requests' completable future. */
+    private transient Map<
+                    Integer, Tuple2<SchemaChangeRequest, CompletableFuture<CoordinationResponse>>>

Review Comment:
   Can you help add a comment that explains the key here as they are Integer type which cannot directly discern the meaning it represents, and update the comment of ` flushedSinkWriters` too.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#issuecomment-2664532009

   Thanks for Shawn's kindly review, comments addressed.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "Shawn-Hx (via GitHub)" <gi...@apache.org>.
Shawn-Hx commented on code in PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#discussion_r1951890862


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/operators/schema/regular/SchemaCoordinator.java:
##########
@@ -219,73 +227,14 @@ protected void handleUnrecoverableError(String taskDescription, Throwable t) {
      */
     public void handleSchemaChangeRequest(
             SchemaChangeRequest request, CompletableFuture<CoordinationResponse> responseFuture) {
-
-        // We use subTaskId to identify each schema change request
-        int subTaskId = request.getSubTaskId();
-
-        if (schemaChangeStatus == RequestStatus.IDLE) {
-            if (activeSinkWriters.size() < currentParallelism) {
-                LOG.info(
-                        "Not all active sink writers have been registered. Current {}, expected {}.",
-                        activeSinkWriters.size(),
-                        currentParallelism);
-                responseFuture.complete(wrap(SchemaChangeResponse.waitingForFlush()));
-                return;
-            }
-
-            if (!activeSinkWriters.equals(flushedSinkWriters.get(subTaskId))) {
-                LOG.info(
-                        "Not all active sink writers have completed flush. Flushed writers: {}, expected: {}.",
-                        flushedSinkWriters.get(subTaskId),
-                        activeSinkWriters);
-                responseFuture.complete(wrap(SchemaChangeResponse.waitingForFlush()));
-                return;
-            }
-
-            LOG.info(
-                    "All sink writers have flushed for subTaskId {}. Switching to APPLYING state and starting schema evolution...",
-                    subTaskId);
-            flushedSinkWriters.remove(subTaskId);
-            schemaChangeStatus = RequestStatus.APPLYING;
-            pendingResponseFuture = responseFuture;
-            startSchemaChangesEvolve(request, responseFuture);
-        } else {
-            responseFuture.complete(wrap(SchemaChangeResponse.busy()));

Review Comment:
   Method `SchemaChangeResponse.busy()` can be removed. Also for `ResponseCode.BUSY`.



##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/operators/schema/regular/SchemaCoordinator.java:
##########
@@ -219,73 +227,14 @@ protected void handleUnrecoverableError(String taskDescription, Throwable t) {
      */
     public void handleSchemaChangeRequest(
             SchemaChangeRequest request, CompletableFuture<CoordinationResponse> responseFuture) {
-
-        // We use subTaskId to identify each schema change request
-        int subTaskId = request.getSubTaskId();
-
-        if (schemaChangeStatus == RequestStatus.IDLE) {
-            if (activeSinkWriters.size() < currentParallelism) {
-                LOG.info(
-                        "Not all active sink writers have been registered. Current {}, expected {}.",
-                        activeSinkWriters.size(),
-                        currentParallelism);
-                responseFuture.complete(wrap(SchemaChangeResponse.waitingForFlush()));
-                return;
-            }
-
-            if (!activeSinkWriters.equals(flushedSinkWriters.get(subTaskId))) {
-                LOG.info(
-                        "Not all active sink writers have completed flush. Flushed writers: {}, expected: {}.",
-                        flushedSinkWriters.get(subTaskId),
-                        activeSinkWriters);
-                responseFuture.complete(wrap(SchemaChangeResponse.waitingForFlush()));

Review Comment:
   Method `SchemaChangeResponse.waitingForFlush()` can be removed. Also for `ResponseCode.WAITING_FOR_FLUSH`.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang merged PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#issuecomment-2644730353

   Would @hiliuxg like to take a look?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "gongzexin (via GitHub)" <gi...@apache.org>.
gongzexin commented on PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#issuecomment-2680469662

   > It seems that `SchemaChangeResponse#ResponseCode` can only be SUCCESS now. Can we remove `SchemaChangeResponse#ResponseCode` and simplify the logic in `SchemaOperator#handleSchemaChangeEvent` ?
   
   @yuxiqian @Shawn-Hx 
   Hi, Have you noticed that during fault tolerance, the same table will be flushed multiple times (related to the task parallelism).So I think SchemaChangeResponse#ResponseCode#DUPLICATE should not be deleted, but it should be strengthened. 


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "mingmingruyue321 (via GitHub)" <gi...@apache.org>.
mingmingruyue321 commented on PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#issuecomment-3545738181

   @yuxiqian I have a table that I want to delete and resynchronize with both full and incremental data. The schema recorded by the Schema Manager will not be automatically deleted when the table is deleted, skipping the new table creation statement. What should I do
   ```
    // For redundant schema change events (possibly coming from duplicate emitted
           // CreateTableEvents in snapshot stage), we just skip them.
           if (!SchemaUtils.isSchemaChangeEventRedundant(currentUpstreamSchema, originalEvent)) {
               schemaManager.applyOriginalSchemaChange(originalEvent);
               deducedSchemaChangeEvents.addAll(deduceEvolvedSchemaChanges(originalEvent));
           }
   ```


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "yuxiqian (via GitHub)" <gi...@apache.org>.
yuxiqian commented on PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#issuecomment-2680689436

   > > It seems that `SchemaChangeResponse#ResponseCode` can only be SUCCESS now. Can we remove `SchemaChangeResponse#ResponseCode` and simplify the logic in `SchemaOperator#handleSchemaChangeEvent` ?
   > 
   > @yuxiqian @Shawn-Hx Hi, Have you noticed that during fault tolerance, the same table will be flushed multiple times (related to the task parallelism).So I think SchemaChangeResponse#ResponseCode#DUPLICATE should not be deleted, but it should be strengthened.
   
   Thanks for @gongzexin's report. IIUC, the root cause of this problem is `PreTransformOperator` invokes `getUnionListState` to store persistent schemas, all subTasks of `SchemaOperator`s will obtain the same set of table schemas when restoring from state, and `SchemaCoordinator` is expected to receive $N$ duplicate requests ($N$ = parallelism). Worse still, `UnionListState` will block the checkpointing process when some subTasks have entered the FINISHED state (FLINK-37368).
   
   I wonder if we can handle it in another PR, and focus on modifying the schema evolution request queueing logic here?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37278] Optimize regular schema evolution topology's performance [flink-cdc]

Posted by "lvyanquan (via GitHub)" <gi...@apache.org>.
lvyanquan commented on PR #3912:
URL: https://github.com/apache/flink-cdc/pull/3912#issuecomment-2693351244

   Hi, @leonardBang @ruanhang1993, could you take a look at this?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org