[FLINK-39197][jdbc&mysql] Fix NPE when finding chunk end#4296
[FLINK-39197][jdbc&mysql] Fix NPE when finding chunk end#4296ChengbingLiu wants to merge 1 commit intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes FLINK-39197 by preventing a NullPointerException during snapshot chunk splitting when the computed next chunk end is null (e.g., rows containing max values are removed between min/max discovery and subsequent chunk boundary queries).
Changes:
- Add an early
nullreturn inMySqlChunkSplitter.nextChunkEnd(...)whenqueryNextChunkMax(...)returnsnull. - Add the same early
nullreturn in the baseJdbcSourceChunkSplitter.nextChunkEnd(...)to protect all JDBC-based connectors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/source/assigners/MySqlChunkSplitter.java | Prevents NPE in MySQL snapshot chunk splitting when the next chunk end cannot be determined (returns null). |
| flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/main/java/org/apache/flink/cdc/connectors/base/source/assigner/splitter/JdbcSourceChunkSplitter.java | Applies the same null-guard to the shared JDBC chunk splitting logic used by multiple connectors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (chunkEnd == null) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Consider adding a regression test that covers the scenario fixed here: queryNextChunkMax(...) returning null (e.g., max rows deleted between the earlier MIN/MAX query and subsequent chunk-end queries). This change prevents an NPE, but without a test it’s easy for the null-handling path in nextChunkEnd to regress again. A unit test could stub the JDBC/StatementUtils interaction, or an ITCase could delete the max row after MIN/MAX is determined and assert chunk splitting completes without exceptions.
Fix https://issues.apache.org/jira/browse/FLINK-39197
We encountered the following problem when using MySQL pipeline connector:
This should be because max values are removed resulting in chunkEnd == null, as mentioned in