[FLINK-40538][postgres] Skip WAL position search on idle publication … - #4521
Open
eskabetxe wants to merge 1 commit into
Open
[FLINK-40538][postgres] Skip WAL position search on idle publication …#4521eskabetxe wants to merge 1 commit into
eskabetxe wants to merge 1 commit into
Conversation
…for a fresh start PostgresSourceFetchTaskContext.loadStartingOffsetState always returns a non-null PostgresOffsetContext built from the stream split's starting offset, so in the forked PostgresStreamingChangeEventSource#execute the WAL position search branch was taken unconditionally. On an idle publication that search loops forever waiting for a decoded message: no WAL is produced, and the heartbeat action query that would generate some only runs from the main streaming loop, which the search precedes. The job stays RUNNING while the slot's confirmed_flush_lsn never advances and WAL grows without bound. Guard the search with offsetContext.hasCompletelyProcessedPosition(), mirroring the fix Debezium shipped in 2.7. On a fresh start (nothing processed yet) the search is skipped; streaming still starts from the stored LSN, so no events are missed. On a resumed offset the search still runs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What is the purpose of this pull request?
Fixes FLINK-40538: a Postgres CDC source pointed at a database whose captured publication receives no writes never leaves Debezium's WAL-position search, so it never starts streaming.
While stuck in the search, the job reports RUNNING and healthy and all checkpoints complete, but:
Root cause. PostgresSourceFetchTaskContext.loadStartingOffsetState always returns a non-null PostgresOffsetContext (built from the stream split's starting offset), so in the forked PostgresStreamingChangeEventSource#execute the WAL-search branch is entered unconditionally (walPosition.searchingEnabled() is always true). searchWalPosition then loops until a message is decoded but — unlike the main streaming loop — dispatches no heartbeat while waiting. On an idle publication that is a deadlock: the search waits for publication traffic, and the only thing that would generate traffic (heartbeat.action.query, driven from the main loop) runs only after the search returns.
Fix. Guard the search with offsetContext.hasCompletelyProcessedPosition(), mirroring the fix Debezium shipped in 2.7 (searchingEnabled() && effectiveOffset.hasCompletelyProcessedPosition()). On a fresh start nothing has been completely processed, so the search is skipped; streaming still begins from the stored LSN via startStreaming(lsn, walPosition), so no events are missed. On a resumed offset (e.g. after a checkpoint) the search still runs, preserving exact-resume behavior.
Brief change log
Verifying this change
This change added tests and can be verified as follows:
yields both true (search still runs).
streams immediately and the slot advances.
Documentation