sun-9545sunoj opened a new pull request, #13374: URL: https://github.com/apache/seatunnel/pull/13374
Yes — this is a contribution to Apache SeaTunnel. ### Purpose of this pull request Part of #13360 (STIP-45: offload checkpoint state persistence to workers). This PR implements **phases 1 and 2** of the split proposed in https://github.com/apache/seatunnel/issues/13360#issuecomment-7015614096: 1. **State handle abstraction** — `StateHandle` / `InlineStateHandle` / `FileChunkStateHandle`; `ActionSubtaskState` (and therefore acks, `PendingCheckpoint`, `CompletedCheckpoint`, restore operations) can now carry either inline bytes or a handle to externalized state. 2. **v2 storage format and dual-format restore** — a non-breaking `ChunkSupportStorage` SPI extension, the chunk and `_metadata` (with CRC) formats, implementations for `localfile` and `hdfs`, and restore that reads both v1 blobs and v2 checkpoints. **Nothing writes the v2 format yet.** The runtime write path is unchanged: all states are inline and checkpoints are persisted as v1 blobs exactly as before. Landing the readers before any writer means a version that writes v2 (phase 3, worker write-through) can always be rolled back to a version that reads it. #### State handle (phase 1) - `ActionSubtaskState` gets a new last field `externalStateHandle` (null for inline state). - Checkpoint blobs are ProtoStuff object graphs numbered by field declaration order, and ProtoStuff skips null fields. So **inline states serialize to exactly the same bytes as before**. This is enforced by a golden-file test: `v1-completed-checkpoint.ser` was generated from unmodified `dev`, and the test asserts it still deserializes and that re-serializing the same checkpoint yields identical bytes. I verified that the test fails if the new field is moved before `state`. - Workers resolve external handles back to inline bytes in `NotifyTaskRestoreOperation`, on the task executor (not the operation thread), before `Task#restoreState`. Connector and transform restore code is untouched. #### v2 format (phase 2) ``` <namespace>/<jobId>/<pipelineId>/chk-<id>/_metadata commit point <namespace>/<jobId>/<pipelineId>/chk-<id>/subtask-<sha256(actionKey)[:16]>-<index|coordinator>.chunk ``` - chunk: `[entryCount:int]{[length:int][bytes]}*`, null segment = length -1 - `_metadata`: `["STCKMD"][version=2][flags][payloadLen][CRC32]` + payload. The payload is the same ProtoStuff `CompletedCheckpoint` that v1 stores in `PipelineState.states`, so restore converts it into a `PipelineState` and the coordinator path is unchanged. - Writes are tmp → rename. On object stores, where rename is not atomic, a partially written `_metadata` fails the CRC check on read. - v1 files (`*.ser` directly under `<jobId>/`) and the v2 tree coexist. All existing `CheckpointStorage` methods stay v1-only, so their behavior is unchanged. `deleteCheckpoint(jobId)` already removes the whole job directory. #### Restore selection (`DualFormatCheckpointReader`, used by `CheckpointManager`) - Picks the restorable checkpoint with the **highest checkpoint id across both formats** (ties go to v2). This differs slightly from the issue's "v2 first, else v1", which could ignore a newer v1 written after switching back to the deprecated master mode. - A `_metadata` that fails validation is skipped with a WARN and the next older checkpoint is used. `chk-*` directories without `_metadata` are ignored. - Storage plugins without `ChunkSupportStorage` behave exactly as before (v1 only). #### Also included: `stateSize` statistic now in bytes `PendingCheckpoint` reported the *number of state arrays* as the subtask `stateSize`. The REST docs (`rest-api-v2.md`, en and zh) and `CheckpointMonitorService#onCheckpointCompleted(…, stateSizeBytes)` already describe it as bytes. It now reports true bytes. This is issue item #5; it is also required here, because the old code would throw an NPE on an external state. ### Does this PR introduce _any_ user-facing change? - No new or changed config options and no changed defaults. The v1 on-disk format is byte-identical. - The checkpoint overview `stateSize` (REST / Web UI) now shows bytes, as documented, instead of an array count. - No incompatible change, so `incompatible-changes.md` is not updated. Docs for the v2 layout and the new options will come with phase 3, when the format is actually written. ### Not in this PR (follow-ups per the issue) - Phase 3: worker write-through, the `state-write-mode` / `state-inline-threshold` options, capability fallback, worker storage config validation, and v2 in the job-level `CheckpointService` REST views. - Phase 4: orphan / `.tmp` / retention cleanup of the v2 tree, chunk-missing fallback, and metrics. ### How was this patch tested? All run locally on JDK 11: - `./mvnw spotless:apply` - New `CheckpointStateFormatTest` (storage-api, 9 tests): chunk/metadata round trips, truncation, padding, CRC, magic and version rejection, path safety, `chk-` parsing. - `LocalFileStorageTest` and `AbstractFileCheckPointTest` (HDFS on the local FS) extended: v2 written next to v1. All existing v1 assertions still pass, plus chunk round trip, retry overwrite, no `.tmp` leftovers, listing that ignores incomplete checkpoints, and corruption detection. - `CheckpointSerializeTest` extended: v1 golden-file compatibility, and external handles surviving ProtoStuff (`_metadata`) and Java serialization (ack path). - New `DualFormatCheckpointReaderTest` (8 tests): v1 only, newer v2, newer v1, corrupted latest → older v2 → v1, incomplete v2 ignored, merge, non-chunk storage. - All tests in `org.apache.seatunnel.engine.server.checkpoint` (66 run, 0 failures, 2 skipped — the existing `@Disabled` tests). - E2E (`connector-seatunnel-e2e-base`, `-DskipUT -DskipIT=false`), all passing: - `ClusterFaultToleranceIT`: 8 passed, 2 skipped (the existing `@Disabled` tests). - `CheckpointCoordinatorFailoverIT`: 5 passed. - `JobRestoreIT`, `SavepointRestoreIT`, `CheckpointRestoreWithStopIT` (Docker): 1, 1 and 2 passed. - Not run locally: a full-repository `./mvnw -DskipTests verify` and the complete `seatunnel-engine-server` unit-test suite. I ran the affected modules and packages listed above and left the full runs to CI. ### Benchmarks Following the review question on #13360: this PR does not change the runtime write path (states stay inline and v1 blobs are written by the master), so master heap, GC and ack payload sizes are unchanged by construction. The before/after measurement (CDC initial-snapshot job: master heap and old-gen usage, GC pauses, ack payload size, checkpoint duration) belongs with phase 3, which moves the bytes off the master. I'll attach the benchmark plan and results there. ### Check list * [x] No new dependencies * [x] No incompatible changes * [ ] Docs: no user-visible option change in this PR; the `stateSize` docs already say bytes 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
