[hotfix] Optimize SchemaChangeEventVisitor to reduce class inflations#4350
Merged
Conversation
…er class & introduce voidVisitors
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors schema change event visiting to reduce the number of per-event visitor interfaces by introducing generic visitor handler types and a dedicated voidVisit dispatch for side-effect-only handlers.
Changes:
- Replace per-event visitor interfaces with generic
VisitorHandler/VoidVisitorHandler. - Add
SchemaChangeEventVisitor.voidVisit(...)and migrate several call sites to it (serializer + Doris/Paimon/StarRocks metadata appliers). - Remove now-redundant per-event visitor interface classes.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/serializer/event/SchemaChangeEventSerializer.java | Switch serialization dispatch to SchemaChangeEventVisitor.voidVisit(...) to avoid Void returns. |
| flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-starrocks/src/main/java/org/apache/flink/cdc/connectors/starrocks/sink/StarRocksMetadataApplier.java | Use voidVisit + method references for schema change application dispatch. |
| flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-paimon/src/main/java/org/apache/flink/cdc/connectors/paimon/sink/PaimonMetadataApplier.java | Use voidVisit + method references for schema change application dispatch. |
| flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-doris/src/main/java/org/apache/flink/cdc/connectors/doris/sink/DorisMetadataApplier.java | Use voidVisit + method references for schema change application dispatch. |
| flink-cdc-common/src/main/java/org/apache/flink/cdc/common/event/visitor/VoidVisitorHandler.java | Introduce generic void visitor handler interface. |
| flink-cdc-common/src/main/java/org/apache/flink/cdc/common/event/visitor/VisitorHandler.java | Introduce generic visitor handler interface returning a value. |
| flink-cdc-common/src/main/java/org/apache/flink/cdc/common/event/visitor/SchemaChangeEventVisitor.java | Update to generic handlers and add voidVisit(...) dispatch method. |
| flink-cdc-common/src/main/java/org/apache/flink/cdc/common/event/visitor/*EventVisitor.java | Remove per-event visitor interfaces now replaced by generic handler types. |
Comments suppressed due to low confidence (2)
flink-cdc-common/src/main/java/org/apache/flink/cdc/common/event/visitor/VoidVisitorHandler.java:25
VoidVisitorHandleris generic over anySchemaChangeEvent, but the Javadoc still refers toTruncateTableEventand theTruncateTableEventimport is unused. This is misleading and may fail style checks; update the Javadoc to describe the generic handler and remove the unused import.
flink-cdc-common/src/main/java/org/apache/flink/cdc/common/event/visitor/VisitorHandler.java:25VisitorHandleris now a generic functional interface, but the Javadoc still says it's a visitor forTruncateTableEventand theTruncateTableEventimport is unused. Please update the Javadoc to match the new purpose and remove the unused import to keep the file consistent with project style checks.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ThorneANN
pushed a commit
to ThorneANN/flink-cdc
that referenced
this pull request
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces generic
SchemaChangeEventVisitorto reduce the amount of visitor classes, as we're likely to support more schema change events.