yraivo opened a new pull request, #13389:
URL: https://github.com/apache/seatunnel/pull/13389

   ### Purpose of this pull request
   
   Yes — I am contributing this fix and regression test suite to Seatunnel 
(Apache SeaTunnel) for #13340.
   
   Fixes #13340 (serialized red/green reproduction fixture and discussion: 
https://github.com/apache/seatunnel/issues/13340#issuecomment-7061176090, scope 
aligned with 
https://github.com/apache/seatunnel/issues/13340#issuecomment-7062350126); PR 
commit sequence: red reproduction 8a0b19f870d461bac72b6ad8e57bcb4210337b09, 
green fix 2db47602e5f3b9ed3f9405810843eccdff7f4fd3).
   
   #### Root Cause
   
   When a checkpoint or savepoint is taken after a CDC reader finishes its 
final `SnapshotSplit` (`splitEnd == null`, `isSnapshotReadFinished() == true`) 
and persists it in `IncrementalSourceReader.finishedUnackedSplits` (`#12163`), 
while `CompletedSnapshotSplitsReportEvent` has not yet been recorded in the 
enumerator's `SnapshotPhaseState.splitCompletedOffsets`:
   
   1. On restore, `IncrementalSource.restoreEnumerator` constructs a shared 
`SplitAssigner.Context` from `checkpointSnapshotState` and 
`HybridSplitAssigner` passes it to both `SnapshotSplitAssigner` and 
`IncrementalSplitAssigner`, whereas `SnapshotSplitAssigner`'s constructor 
copies `assignedSplits` and `splitCompletedOffsets` into its own 
`ConcurrentHashMap` instances.
   2. During `addSplitsBack`, 
`SnapshotSplitAssigner.restoreCompletedSnapshotSplit` (`#12162`) reconstructs 
the missing `SnapshotSplitWatermark` only into `SnapshotSplitAssigner`'s 
private `splitCompletedOffsets` map and does not synchronize it into 
`context.getSplitCompletedOffsets()` (and `SnapshotSplitAssigner.addSplits` 
does not re-evaluate `allSplitsCompleted()`, leaving `parallelism = 1` restores 
unable to transition without another checkpoint).
   3. Once snapshot completion flips, 
`IncrementalSplitAssigner.createIncrementalSplit` reads 
`context.getSplitCompletedOffsets().get(split.splitId())`, gets `null`, and 
throws `NullPointerException` when selecting the incremental start offset 
(`getLowWatermark()` / `getHighWatermark()`). In addition, if a completed 
snapshot state carries a `SnapshotSplitWatermark` whose required low/high 
offset is `null`, `minOffset` previously remained `null` and silently fell back 
to `startupOffset`.
   
   #### Changes
   
   Confined strictly to the CDC restore-state ownership path while preserving 
`#11677` waiting-reader reassignment behavior:
   
   - **`SnapshotSplitAssigner`**:
     - Synchronize reconstructed completion watermarks into 
`context.getSplitCompletedOffsets()` via `putIfAbsent` inside 
`restoreCompletedSnapshotSplit` (matching the shared-context ownership boundary 
in `getNext()`).
     - Re-evaluate `allSplitsCompleted()` in `addSplits` after handling 
restored completed splits (`currentParallelism == 1` marks `assignerCompleted = 
true` immediately; `currentParallelism > 1` waits for an aligned checkpoint 
completion).
   - **`SplitAssigner.Context`**:
     - Defensively copy `assignedSnapshotSplit` and `splitCompletedOffsets` 
into `ConcurrentHashMap` instances so shared-context updates are thread-safe 
and safe when callers pass immutable maps.
   - **`IncrementalSplitAssigner`**:
     - Fail fast with an actionable `IllegalStateException` naming the 
`tableId` and `splitId` (instead of throwing a raw `NullPointerException` on 
the coordinator/reader or silently falling back to `startupOffset`) whenever a 
completed snapshot state is missing a `SnapshotSplitWatermark`, has a `null` 
high watermark on any completed split metadata handed to the reader (or a 
`null` low watermark when selecting a non-exactly-once start offset), or 
restores an `IncrementalSplit` whose `CompletedSnapshotSplitInfo` is missing 
its watermark or high watermark.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A CDC job can now resume when its reader restores a finished snapshot 
split whose completion had not yet been recorded by the enumerator. An 
incomplete checkpoint that lacks a required watermark now fails with the 
affected table and split IDs.
   
   ### How was this patch tested?
   
   1. **Component serialized restore tests in `IncrementalSourceEnumeratorTest` 
(`connector-cdc-base`)** (sharing `InMemoryCdcRestoreTestFixture` via 
`DefaultSerializer` with zero private-map mutation or out-of-order private 
calls):
      - Unacknowledged finished tail split (`splitEnd == null`) restored under 
`exactly_once = false`, `parallelism = 2`: reproduces `NullPointerException` at 
`IncrementalSplitAssigner.createIncrementalSplit:300` before the fix; waits for 
`notifyCheckpointComplete` and selects minimum `lowWatermark` (`95`) after the 
fix.
      - Counterpart under `exactly_once = true`, `parallelism = 2` (waits for 
`notifyCheckpointComplete` and selects minimum `highWatermark` `108`) and 
`parallelism = 1` (transitions immediately on `handleSplitRequest` and selects 
minimum `highWatermark` `108`).
      - Waiting-reader reassignment of unfinished restored splits (`#11677`) 
and incomplete-restore waiting behavior.
      - Malformed serialized state checks: missing `SnapshotSplitWatermark`, 
`null` low/high watermark under `exactly_once = false` / `true` (including 
multi-split completed `SnapshotPhaseState` selecting `lowWatermark` and 
restored `IncrementalSplit` carrying a `null` `highWatermark`, verified with 
`highWatermark = 108` positive controls through 
`IncrementalSourceStreamFetcher.submitTask`), and restored `IncrementalSplit` 
carrying a `CompletedSnapshotSplitInfo` with `null` watermark — all fail fast 
on the coordinator side with `IllegalStateException` naming `db1.table1` and 
`db1.table1:1`.
   2. **In-JVM Zeta savepoint-restore test in existing `SavePointTest` 
(`seatunnel-engine-server`)**:
      - Reuses `AbstractSeaTunnelServerTest` and `SavePointTest`'s existing 
checkpoint storage infrastructure 
(`testSavePointAndRestoreCdcUnackedTailSplit`, with bounded future timeouts and 
running-job cancellation cleanup): runs a 2-parallelism streaming CDC job 
(`JOB_RETRY_TIMES = 0`), triggers `savePoint(jobId)` while the finished tail 
split is held in reader `finishedUnackedSplits`, and restores with 
`isStartWithSavePoint = true`. Fails at 
`SourceSplitEnumeratorTask.notifyCheckpointComplete -> 
IncrementalSplitAssigner.createIncrementalSplit:300` before the fix; completes 
cleanly (`JobStatus.FINISHED`) and emits exact unique keys `[1, 100, 200, 300]` 
after the fix.
      - The embedded CDC savepoint regression passed on Linux before the 
timeout and cancellation changes. With those changes, the engine tests compiled 
on Windows and all 153 CDC component tests passed. The external MySQL 
Testcontainers suite was not run locally.
   
   Verification commands on a clean checkout of `dev`:
   
   ```sh
   ./mvnw -pl 
seatunnel-connectors-v2/connector-cdc/connector-cdc-base,seatunnel-engine/seatunnel-engine-server,seatunnel-ci-tools
 -am -DskipTests -Dskip.spotless=true -Dskip.ui=true 
-Dlicense.skipAddThirdParty=true install
   ./mvnw -pl 
seatunnel-connectors-v2/connector-cdc/connector-cdc-base,seatunnel-engine/seatunnel-engine-server
 -Dskip.spotless=false spotless:check
   ./mvnw -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base test
   ./mvnw -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base 
-DskipTests -Dskip.spotless=true install
   ./mvnw -pl seatunnel-engine/seatunnel-engine-server -Dtest=SavePointTest test
   ```
   
   ### Check list
   
   * [x] If any new Jar binary package adding in your PR, please add License 
Notice according
     [New License 
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
 (N/A — no new third-party dependency added)
   * [x] If necessary, please update the documentation to describe the new 
feature. https://github.com/apache/seatunnel/tree/dev/docs (N/A — bug fix)
   * [x] If necessary, please update `incompatible-changes.md` to describe the 
incompatibility caused by this PR. (N/A)
   * [x] If you are contributing the connector code, please check that the 
following files are updated: (N/A — bug fix in existing `connector-cdc-base`, 
not a new connector)
     1. Update 
[plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties)
 and add new connector information in it
     2. Update the pom file of 
[seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in 
[label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in 
[seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector 
[plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
   


-- 
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]

Reply via email to