Skip to content

[spark] Fix restarted streaming query re-scanning full snapshot instead of resuming from checkpoint#8207

Open
yugeeklab wants to merge 1 commit into
apache:masterfrom
yugeeklab:fix/spark-microbatch-restart-rescan
Open

[spark] Fix restarted streaming query re-scanning full snapshot instead of resuming from checkpoint#8207
yugeeklab wants to merge 1 commit into
apache:masterfrom
yugeeklab:fix/spark-microbatch-restart-rescan

Conversation

@yugeeklab

Copy link
Copy Markdown

Purpose

Linked issue: close #8205

PaimonMicroBatchStream#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, silently skipped the changelog gap, and re-emitted the entire snapshot as +I rows.

This PR falls back to initOffset only when the checkpointed snapshot has actually expired (older than earliestSnapshotId); 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 PaimonMicroBatchStream unit-side; happy to add one if maintainers can point at a preferred pattern.

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Spark: restarted streaming query drops valid checkpoint offset and re-scans the full snapshot (scan.mode=latest-full)

1 participant