[spark] Fix restarted streaming query re-scanning full snapshot instead of resuming from checkpoint#8207
Open
yugeeklab wants to merge 1 commit into
Open
Conversation
…ad of resuming from checkpoint planInputPartitions clamped the checkpointed start offset up to initOffset whenever it compared lower. initOffset is recomputed from the current table state on every restart, so with scan modes like latest-full it always points at the current snapshot with scanSnapshot=true. Any restarted query therefore dropped its valid checkpointed position, skipped the changelog gap, and re-emitted the entire snapshot as +I rows. Fall back to initOffset only when the checkpointed snapshot has actually expired (older than earliestSnapshotId). Co-Authored-By: Claude Fable 5 <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.
Purpose
Linked issue: close #8205
PaimonMicroBatchStream#planInputPartitionsclamped the checkpointed start offset up toinitOffsetwhenever it compared lower.initOffsetis recomputed from the current table state on every restart, so with scan modes likelatest-fullit always points at the current snapshot withscanSnapshot=true. Any restarted query therefore dropped its valid checkpointed position, silently skipped the changelog gap, and re-emitted the entire snapshot as+Irows.This PR falls back to
initOffsetonly when the checkpointed snapshot has actually expired (older thanearliestSnapshotId); otherwise the query resumes from the checkpointed offset as-is. A warning is logged when the fallback is taken.Tests
Verified against a production 5-minute-trigger streaming query (~300k-row source): with the fix the first batch after a restart resumes from the checkpointed offset and reads only the downtime changelog; without it, restarts produced one empty batch followed by a full-snapshot re-emission (offset WAL evidence in #8205).
I did not find an existing harness for restart simulation of
PaimonMicroBatchStreamunit-side; happy to add one if maintainers can point at a preferred pattern.🤖 Generated with Claude Code