Skip to content

Spark: Extract streaming initial offset store - #18092

Open
huan233usc wants to merge 4 commits into
apache:mainfrom
huan233usc:xin-huang_data/spark-4.2-initial-offset-store
Open

huan233usc wants to merge 4 commits into
apache:mainfrom
huan233usc:xin-huang_data/spark-4.2-initial-offset-store

Conversation

@huan233usc

@huan233usc huan233usc commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Spark 4.2 currently embeds initial-offset checkpoint persistence inside SparkMicroBatchStream. Extract it into a package-private StreamingInitialOffsetStore so other streaming sources can reuse the same checkpoint handling.

The existing stream supplies its starting-offset calculation lazily, after checking for a persisted offset. The checkpoint location (offsets/0), JSON format, and use of Hadoop FileIO remain unchanged. Unit tests cover creating nested checkpoint directories, restoring an existing checkpoint, and restoring an empty-table start offset without invoking the initializer again.

Following the applicable cases in DeltaSourceOffsetSuite, the store tests also cover unknown, non-integer, and missing format versions, malformed JSON, and both values of the initial-snapshot flag. Invalid checkpoints must fail without invoking the initializer or overwriting the persisted file.

This is the first preparatory refactor split from #17953 and can merge independently.

Validation: TestStreamingInitialOffsetStore (9 cases), TestStreamingOffset (2 cases), TestStreamingCheckpointHadoopIO, and the checkpoint-resume and timestamp-start cases in TestStructuredStreamingRead3; Spark 4.2 Spotless check.


AI Disclosure

  • Model: GPT-6
  • Platform/Tool: Codex
  • Human Oversight: verified
  • Prompt Summary: Extract the initial-offset store refactor from Spark: Add native CDC for copy-on-write tables #17953 into a standalone prerequisite PR, including its existing streaming integration and regression test.

Move initial-offset checkpoint persistence into a package-private helper
with a lazy offset supplier. Preserve checkpoint format and Hadoop FileIO
behavior, and verify that recovery does not recompute the initial offset.

Split from apache#17953.

Generated-by: Codex
@github-actions github-actions Bot added the spark label Sep 13, 2026
Xin Huang added 3 commits September 13, 2026 15:01
Move nested checkpoint creation coverage to the offset store unit tests.
Verify restoration of existing checkpoints and empty-table start offsets
without recomputing the initial offset. Check the Iceberg source checkpoint
in the retained Hadoop FileIO integration test.

Generated-by: Codex
Keep the initial offset store refactor focused on extraction and helper
unit tests. Restore the existing Hadoop FileIO integration test.

Generated-by: Codex
Add Delta-inspired coverage for unknown, invalid, and missing format
versions, malformed JSON, and both initial-snapshot flag values. Verify
invalid checkpoints fail without reinitializing or overwriting the offset.

Generated-by: Codex

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice, behavior-preserving extraction, thank you @huan233usc for working on this! The checkpoint path, HadoopFileIO, JSON format, and read-before-write guard are byte-identical to the old inner class, so existing checkpoints recover after upgrade.

@uros-b

uros-b commented Sep 15, 2026

Copy link
Copy Markdown
Member

Please ping committers with more expertise in Iceberg Spark, for further review. e.g. @aokolnychyi has context on streaming source / checkpoint path changes

@szehon-ho szehon-ho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm , clean refactor, class is package private

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants