yraivo commented on issue #13340:
URL: https://github.com/apache/seatunnel/issues/13340#issuecomment-7061176090
Hi @DanielLeens, thanks for the clear reproduction checklist. On `3.1.0`
(`2d3983aad94a`) and `dev` (`c8e7a262897f`), a serialized reader + enumerator
fixture (`DefaultSerializer` via
`SeaTunnelSource.getEnumeratorStateSerializer()` and `getSplitSerializer()`)
reproduces the non-exactly-once `NullPointerException`
(`IncrementalSplitAssigner.createIncrementalSplit:300`) through
`handleSplitRequest`, without touching private maps or calling private methods
out of order:
1. **Reproduced restore path (finished tail split retained in reader
`finishedUnackedSplits`)**: In the reproducing checkpoint, the reader retains
the finished final `SnapshotSplit` (`splitEnd == null`,
`isSnapshotReadFinished() == true`) and its watermarks in
`IncrementalSourceReader.finishedUnackedSplits` (`#12163`), while the
enumerator checkpoint lists that split in `assignedSplits` and has not yet
recorded its completion in `splitCompletedOffsets`. On restore,
`IncrementalSource.restoreEnumerator` builds the shared `SplitAssigner.Context`
from `checkpointSnapshotState` and `HybridSplitAssigner` passes it to both
assigners, whereas `SnapshotSplitAssigner`'s constructor copies
`assignedSplits` and `splitCompletedOffsets` into its own `ConcurrentHashMap`s.
During `addSplitsBack`, `SnapshotSplitAssigner.restoreCompletedSnapshotSplit`
(`#12162`) rebuilds the watermarks only into `SnapshotSplitAssigner`'s private
map, so `IncrementalSplitAssigner` cannot see them in `context.getSpl
itCompletedOffsets()` (and `addSplits` skips re-checking
`allSplitsCompleted()`, stalling `parallelism = 1` restores).
2. **Candidate fix & verified scopes**:
- **Component tests (`connector-cdc-base`)**: Syncing
`SplitAssigner.Context` when restoring completed splits, re-checking
`allSplitsCompleted()` on completed-split restore, and failing fast with an
actionable `IllegalStateException` in `IncrementalSplitAssigner` when a
completed snapshot state is genuinely missing a `SnapshotSplitWatermark` or has
a `null` low/high offset (instead of a raw `NPE` or silent `startupOffset`
fallback) recovers the expected minimum `lowWatermark` (`95`) on `dev` (`25`
suites / `152` tests green), as well as with baseline-adapted patches applied
on `#11988` (`729608635406`, NPE at line `343` -> `41/41` green) and `#13240`
(`da5eb47727ce`, NPE at line `320` -> `62` passed, `2` optional cost benchmarks
skipped, including `SnapshotSplitAssignerTest` `27/27`).
- **Embedded Zeta savepoint-restore test (`dev`)**: On `dev`, an in-JVM
`SeaTunnelServer` (`ExecutionMode.LOCAL` + `LocalFileStorage`, `JOB_RETRY_TIMES
= 0`) job with an in-memory `IncrementalSource` also failed at
`createIncrementalSplit:300` before the fix and completed the savepoint restore
cleanly after the fix.
- **Two-commit reproducer & candidate fix (`dev` base `c8e7a262897f`)**:
- Commit 1 (tests only — reproduces the NPE on unpatched `dev`):
[`yraivo/seatunnel@2c47c06dfb7d`](https://github.com/yraivo/seatunnel/commit/2c47c06dfb7d539827675368e0b26a19481aecac)
- Commit 2 (candidate `connector-cdc-base` fix — turns both suites
green):
[`yraivo/seatunnel@e6d31009c743`](https://github.com/yraivo/seatunnel/commit/e6d31009c7437101cc283ceefe08a747caae85c4)
<details>
<summary>Reproduced stack traces, test matrix, and fresh-checkout
verification commands on pinned commits</summary>
### 1. Tier 1 — `IncrementalSourceEnumeratorTest` (serialized
`HybridPendingSplitsState` + reader `finishedUnackedSplits`, `exactly_once =
false`, `parallelism = 2`)
Unpatched `3.1.0` (`2d3983aad94a`) and `dev` (`c8e7a262897f`, reproducer
commit
[`2c47c06dfb7d`](https://github.com/yraivo/seatunnel/commit/2c47c06dfb7d539827675368e0b26a19481aecac);
also reproduced at line `343` on `#11988` and line `320` on `#13240`):
```text
java.lang.NullPointerException: Cannot invoke
"org.apache.seatunnel.connectors.cdc.base.source.event.SnapshotSplitWatermark.getLowWatermark()"
because "splitWatermark" is null
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSplitAssigner.createIncrementalSplit(IncrementalSplitAssigner.java:300)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSplitAssigner.createIncrementalSplits(IncrementalSplitAssigner.java:275)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSplitAssigner.getNext(IncrementalSplitAssigner.java:152)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.HybridSplitAssigner.getNext(HybridSplitAssigner.java:113)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSourceEnumerator.assignSplits(IncrementalSourceEnumerator.java:197)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSourceEnumerator.handleSplitRequest(IncrementalSourceEnumerator.java:96)
```
### 2. Tier 2 — Embedded Zeta `SeaTunnelServer` on `dev`
(`ExecutionMode.LOCAL`, `LocalFileStorage`, `savePoint` -> `submitJob(...,
isStartWithSavePoint=true)`, `JOB_RETRY_TIMES = 0`)
Unpatched `dev` (`c8e7a262897f`, reproducer commit
[`2c47c06dfb7d`](https://github.com/yraivo/seatunnel/commit/2c47c06dfb7d539827675368e0b26a19481aecac)):
```text
org.apache.seatunnel.engine.server.checkpoint.CheckpointException:
Checkpoint notify complete failed
at
org.apache.seatunnel.engine.server.checkpoint.CheckpointCoordinator.handleCoordinatorError(CheckpointCoordinator.java:357)
...
Caused by: java.util.concurrent.CompletionException:
org.apache.seatunnel.engine.common.exception.SeaTunnelEngineException:
java.lang.NullPointerException: Cannot invoke
"org.apache.seatunnel.connectors.cdc.base.source.event.SnapshotSplitWatermark.getLowWatermark()"
because "splitWatermark" is null
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSplitAssigner.createIncrementalSplit(IncrementalSplitAssigner.java:300)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSplitAssigner.createIncrementalSplits(IncrementalSplitAssigner.java:275)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSplitAssigner.getNext(IncrementalSplitAssigner.java:152)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.HybridSplitAssigner.getNext(HybridSplitAssigner.java:113)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSourceEnumerator.assignSplits(IncrementalSourceEnumerator.java:197)
at
org.apache.seatunnel.connectors.cdc.base.source.enumerator.IncrementalSourceEnumerator.notifyCheckpointComplete(IncrementalSourceEnumerator.java:172)
at
org.apache.seatunnel.engine.server.task.SourceSplitEnumeratorTask.notifyCheckpointComplete(SourceSplitEnumeratorTask.java:413)
```
### 3. Scenarios covered & fresh-checkout verification commands (`dev` base
`c8e7a262897f341361094f158ffd4f60ae466b80`)
- **Valid restored metadata (`exactly_once = false`, `parallelism = 2`)**:
verifies `SnapshotPhaseState.isAssignerCompleted()` stays `false` before
`notifyCheckpointComplete`, transitions after `notifyCheckpointComplete` ->
`handleSplitRequest`, and selects the minimum `lowWatermark` (`95`) from the
restored `splitEnd == null` split.
- **Valid restored metadata (`exactly_once = true`, `parallelism = 1`)**:
transitions immediately on `handleSplitRequest` without requiring another
periodic checkpoint and selects the minimum `highWatermark` (`108`).
- **Incomplete/malformed serialized state (`assignerCompleted == true` with
missing `SnapshotSplitWatermark`, `null` required watermark offset, or restored
`IncrementalSplit` carrying a `CompletedSnapshotSplitInfo` with `null`
watermark)**: throws `IllegalStateException` naming the `tableId` and `splitId`.
- **In-memory unfinished add-back guards**: preserves `#11677` and prevents
premature incremental dispatch for current-attempt ordered in-memory replay
(note: disambiguating unacked duplicate reports from an earlier reader
assignment or persisting mid-replay post-completion state across another
failover would require split-attempt metadata / `SnapshotPhaseState` schema
changes and is kept separate from `#13340`).
- **Fresh-checkout Red -> Green verification commands**:
```sh
git fetch https://github.com/yraivo/seatunnel.git
fix-13340-cdc-restore-watermark
# 1) Checkout Commit 1 (tests + test POM dependency only, unpatched
production code) and pre-install reactor deps
git checkout 2c47c06dfb7d539827675368e0b26a19481aecac
./mvnw -pl
seatunnel-connectors-v2/connector-cdc/connector-cdc-base,seatunnel-engine/seatunnel-engine-server
-am -DskipTests -Dskip.spotless=true -Dskip.ui=true
-Dlicense.skipAddThirdParty=true install
# Observe RED failures (expected NPE at IncrementalSplitAssigner.java:300
in both component and embedded Zeta tests)
./mvnw -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base
-Dtest=IncrementalSourceEnumeratorTest test
./mvnw -pl seatunnel-engine/seatunnel-engine-server
-Dtest=ZetaCdcCheckpointRestoreVerificationTest test
# 2) Checkout Commit 2 (candidate connector-cdc-base fix), reinstall
connector-cdc-base, and observe GREEN
git checkout e6d31009c7437101cc283ceefe08a747caae85c4
./mvnw -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base
-Dskip.spotless=false spotless:check test
./mvnw -pl seatunnel-connectors-v2/connector-cdc/connector-cdc-base
-DskipTests -Dskip.spotless=true install
./mvnw -pl seatunnel-engine/seatunnel-engine-server -Dskip.spotless=false
spotless:check -Dtest=ZetaCdcCheckpointRestoreVerificationTest test
```
*(External Testcontainers `connector-cdc-mysql-e2e` was not run locally
yet.)*
</details>
@LiuHao0606, to check whether this unacknowledged tail-split window explains
the repeated restarts in your deployment, could you share the snapshot-phase
completion flag (`isAssignerCompleted`) and the anonymized difference between
`assignedSplits` IDs and `splitCompletedOffsets` IDs from the last checkpoint
(and @DanielLeens, if this looks good for a PR, would you prefer extending
`MysqlCDCCheckpointRestoreIT` or an in-JVM Zeta savepoint-restore test)?
--
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]