yuxiqian commented on code in PR #3221: URL: https://github.com/apache/flink-cdc/pull/3221#discussion_r1560784586
########## flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mongodb-cdc/src/main/java/org/apache/flink/cdc/connectors/mongodb/source/reader/fetch/MongoDBStreamFetchTask.java: ########## @@ -108,7 +110,32 @@ public void execute(Context context) throws Exception { this.taskRunning = true; try { while (taskRunning) { - Optional<BsonDocument> next = Optional.ofNullable(changeStreamCursor.tryNext()); + Optional<BsonDocument> next; + try { + next = Optional.ofNullable(changeStreamCursor.tryNext()); + } catch (MongoQueryException e) { + if (e.getErrorCode() == CHANGE_STREAM_FATAL_ERROR) { + ChangeStreamOffset offset = + new ChangeStreamOffset(streamSplit.getStartingOffset().getOffset()); Review Comment: Yes, it would be much cleaner to move that checking logic to `openChangeStreamCursor` and implement the fallback logic along with existing routes. CMIIW but seems `MongoCommandException` will only be thrown [when getNext or tryGetNext is called](https://github.com/mongodb/mongo/blob/a71feef352a1f08e3f9dbc2b840691e75775a370/src/mongo/db/pipeline/document_source_change_stream_ensure_resume_token_present.cpp#L133C31-L133C83), and we can't intentionally trigger an `MongoCommandException` by calling other methods like `hasNext` earlier. @Jiabao-Sun Any suggestions about 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-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org