You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "davidzollo (via GitHub)" <gi...@apache.org> on 2026/09/01 03:46:49 UTC

[PR] [Test][E2E] Add master failover test during source close handshake [seatunnel]

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

   ## What this guards
   
   Guards the fix in #10836 ("[Fix][Zeta] Job stuck permanently after master failover, unable to complete (affects BATCH / bounded source / job shutdown phase)").
   
   Before that fix, `CheckpointCoordinator#readyToCloseStartingTask` — the set of bounded-source starting subtasks that have already finished emitting data and are waiting for the final `COMPLETED_POINT_TYPE` checkpoint to formally close the pipeline — lived only in the pre-failover master's JVM heap. A subtask that had already reported "ready to close" never reports again (there is nothing left for it to signal once it has finished). So a fresh master starting from an empty set could never again observe `readyToCloseStartingTask.size() == plan.getStartingSubtasks().size()`, the completing checkpoint never fired, and an otherwise-finished BATCH job stayed `RUNNING` forever.
   
   The fix persists that bookkeeping into `runningJobStateIMap` (keyed by `CheckpointCoordinator#getReadyToCloseImapKey()`) as each subtask reports in, and restores it in `CheckpointCoordinator#restoreCoordinator` after a master failover — including a special case for when *every* subtask had already reported ready right before the crash, which immediately re-triggers the completing checkpoint on restore.
   
   ## Why the existing coverage doesn't reach this window
   
   `CheckpointCoordinatorFailoverIT#testBatchJobCompletesAfterMasterFailover` (added by #10836 itself) already covers master failover for a BATCH job, but it deliberately triggers the kill once `observedRows > expectedTotalRows / 4` — I confirmed by reading it at current HEAD that this lands squarely in the middle of active source production (25% of expected output), nowhere near the close handshake this fix protects. It cannot exercise the `readyToCloseStartingTask` recovery path at all.
   
   ## What the new test does
   
   Adds `testBatchJobCompletesAfterMasterFailoverDuringCloseHandshake` to that same class (reusing its `createTestResources` helper and template-conf pattern), targeting the close-handshake window directly instead of guessing from timing:
   
   - A new conf template, `batch_fake_to_localfile_close_handshake_failover_template.conf`, defines two independent FakeSource operators feeding one shared LocalFile sink, so the job compiles into exactly one pipeline / one `CheckpointCoordinator` (asserted in the test via `PhysicalPlan#getPipelineList()`), with 4 starting subtasks total (parallelism 2 per source):
     - `table_fast`: `row.num = 5`, a single split — finishes in well under a second.
     - `table_slow`: `row.num = 300` spread across 30 splits with a 300ms read interval between them — at least ~8.7 seconds to drain, so it is still actively producing rows long after `table_fast` is done.
     - `checkpoint.interval` is set to 600000ms (far beyond the test's real runtime) so the completing checkpoint is the only checkpoint ever attempted, keeping the scenario isolated to the exact mechanism under test.
   - The test polls `runningJobStateIMap` directly — via `CheckpointCoordinator#getReadyToCloseImapKey()`, the same persisted key `restoreCoordinator` reads back from — until its value's size is strictly between 0 and 4 (i.e. `table_fast`'s two subtasks have reported ready to close, `table_slow`'s two have not), then immediately kills the active master.
   - The cluster uses two dedicated master-only nodes (`createMasterHazelcastInstance`) plus a separate worker node (`createWorkerHazelcastInstance`) that is never killed — unlike this class's other two tests, which use combined master+worker nodes. I confirmed in `SubPlan#restorePipelineState` (`jobMaster.getCheckpointManager().reportedPipelineRunning(pipelineId, allTaskRunning.get())`) that the "no redeploy" recovery path is gated on every task vertex still being observed as `RUNNING` after failover, which `PhysicalVertex#restoreExecutionState` verifies by checking the owning worker is still a live cluster member. Since the worker here is never killed, every task should stay `RUNNING` through the failover, so recovery is pure coordinator-side bookkeeping with nothing to redeploy or redo — which is what lets the final assertion check the post-recovery row count **exactly** (`610`) instead of with a `">="` tolerance like the existing mid-production test.
   - Final assertion: the job reaches `FINISHED` within a bounded timeout with exactly the expected row count — not stuck `RUNNING` forever (the pre-fix bug) and not `FAILED`.
   
   ## Why this trigger construction is reliable
   
   This reads the fix's own persisted bookkeeping directly (the same IMap entry the fix's `restoreCoordinator` restores from) rather than inferring readiness from a row-count threshold or timing guess. The `table_fast`/`table_slow` production gap is a deterministic ~8+ second window by construction (driven by `split.num` and `split.read-interval`, not scheduler jitter), so the polling loop (20ms interval) reliably lands the kill inside the intended partial-close-handshake window rather than racing a narrow, timing-dependent state transition.
   
   ## Test plan
   
   - `./mvnw spotless:apply -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base -am -nsu` — passed, no additional formatting changes beyond what's in this diff.
   - `./mvnw install -pl 'seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base,!seatunnel-engine/seatunnel-engine-ui' -am -nsu -Dmaven.gitcommitid.skip=true -DskipTests -Dspotless.check.skip=true -T 3C` — `BUILD SUCCESS` across the full reactor (`seatunnel-engine-ui` excluded since it is untouched and its `npm install` step is unrelated to this change).
   - `./mvnw install -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base -nsu -Dmaven.gitcommitid.skip=true -DskipTests -Dspotless.check.skip=true` — `BUILD SUCCESS`, with test-compile genuinely enabled this time (`Compiling 52 source files to .../target/test-classes`), confirming the new/modified test class compiles cleanly; verified `CheckpointCoordinatorFailoverIT.class` exists under `target/test-classes` with a fresh timestamp.
   - Per this series' local-verification policy for Apache SeaTunnel, actual test execution (including this new test) was intentionally not run locally; it will run under GitHub CI on this PR's head commit.


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Test][E2E] Add master failover test during source close handshake [seatunnel]

Posted by "nzw921rx (via GitHub)" <gi...@apache.org>.
nzw921rx merged PR #12031:
URL: https://github.com/apache/seatunnel/pull/12031


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Test][E2E] Add master failover test during source close handshake [seatunnel]

Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on PR #12031:
URL: https://github.com/apache/seatunnel/pull/12031#issuecomment-5549650459

   ### CI update for head `08b795b` — this PR's own test now passes; the one remaining failure is unrelated
   
   The redesign is in (`f34f4f1`) and it worked. On run [33942789441](https://github.com/davidzollo/seatunnel/actions/runs/33942789441):
   
   ```
   Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 82.729 s
     - in org.apache.seatunnel.engine.e2e.CheckpointCoordinatorFailoverIT
   ```
   
   green on **both** `engine-v2-it (8)` and `engine-v2-it (11)`, so `testBatchJobCompletesAfterMasterFailoverDuringCloseHandshake` is fixed on both JDKs.
   
   #### What the fix actually changed
   
   Per my previous analysis, the assertion was written against a total that cannot occur. Correcting that, rather than loosening the bound:
   
   - `CLOSE_HANDSHAKE_STARTING_SUBTASKS` `4` -> `2`. `env.parallelism = 2` scales each source's *reader* tasks; `PhysicalPlanGenerator#getEnumeratorTask` allocates exactly one split-enumerator coordinator subtask per source action regardless of reader parallelism, and the enumerator coordinator is what the ready-to-close handshake tracks. So the real total is one per pipeline, two overall, and the partial state the test waits for is `1` — reachable, where the old `(0, 4)` window was not.
   - Poll interval `20ms` -> `1ms`. The window is genuinely transient (once `table_fast`'s lone starting subtask reports ready, its `COMPLETED_POINT_TYPE` checkpoint fires immediately and `CheckpointCoordinator#shutdown` removes the `readyToCloseImapKey` entry), so this buys more chances to land inside it. The 30s `atMost` bound and the strict `0 < n < 2` assertion are unchanged — nothing was weakened.
   
   #### The remaining red job is not this PR
   
   `engine-v2-it (8)` failed in a test this PR does not touch:
   
   ```
   ClusterFaultToleranceTwoPipelineIT.testTwoPipelineStreamJobRestoreIn2NodeMasterDown  <<< ERROR!
   java.lang.RuntimeException: java.util.concurrent.ExecutionException:
     SeaTunnelEngineRetryableException: Can not get coordinator service from an active master node.
     at ClusterFaultToleranceTwoPipelineIT.java:755
   ```
   
   This PR changes exactly two files — `CheckpointCoordinatorFailoverIT.java` and `batch_fake_to_localfile_close_handshake_failover_template.conf` — and neither is on that test's path. The failure is a master-election timing race inside that test's own wait (it gave up after 17s), and the same test passed on `engine-v2-it (11)` in this run.
   
   I have re-run **only** that one job (attempt 2); the passing JDK 11 result is preserved. Nothing further is pending from my side on this PR.
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Test][E2E] Add master failover test during source close handshake [seatunnel]

Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on PR #12031:
URL: https://github.com/apache/seatunnel/pull/12031#issuecomment-5548995351

   ### CI analysis for the current head (`4af856f`) — root cause found, it is in the test, not the engine
   
   `engine-v2-it` now fails on **both JDK 8 and JDK 11** (previously JDK 8 only), so this is deterministic:
   
   ```
   CheckpointCoordinatorFailoverIT.testBatchJobCompletesAfterMasterFailoverDuringCloseHandshake
   org.awaitility.core.ConditionTimeoutException:
     Waiting for a partial close handshake (readyToClose=0, total=4) ==> expected: <true> but was: <false> within 30 seconds
     at CheckpointCoordinatorFailoverIT...(...:513)  /  lambda$...(...:524)
   ```
   
   The failure is confined to this PR's own new test: `SplitClusterPendingJobLifecycleFailoverIT` passes in this run, and `CheckpointCoordinatorFailoverIT` passes on branches without this test.
   
   #### Root cause
   
   The test waits for a **steady-state** partial handshake:
   
   ```java
   readyCount = getReadyToCloseCount(master, jobId, firstPipelineId)
              + getReadyToCloseCount(master, jobId, secondPipelineId);
   Assertions.assertTrue(readyCount > 0 && readyCount < CLOSE_HANDSHAKE_STARTING_SUBTASKS /* 4 */, ...);
   ```
   
   `getReadyToCloseCount` reads `IMAP_RUNNING_JOB_STATE[readyToCloseImapKey]`, which is **per pipeline** and only transient:
   
   - `CheckpointCoordinator.readyToClose` (`seatunnel-engine-server/.../checkpoint/CheckpointCoordinator.java:552-558`) persists each report and, as soon as **that pipeline's** starting subtasks are all ready, fires `tryTriggerPendingCheckpoint(COMPLETED_POINT_TYPE)`.
   - When that completed point finishes, the coordinator clears the state and deletes the key (`CheckpointCoordinator.java:1192-1201`): `readyToCloseStartingTask.clear()` and, for any non-`CHECKPOINT_COORDINATOR_RESET` close reason, `runningJobStateIMap.remove(readyToCloseImapKey)`.
   
   Because the config splits the shared-sink union into two independent pipelines (one per `FakeSource`), each pipeline's key rises `0 -> 1 -> 2` and is then **deleted**, independently of the other. The aggregate the test sums therefore never settles anywhere in `(0, 4)`: it is 0 almost always, briefly 2, then 0 again. The `total=4` invariant the assertion is written against is not reachable as a stable state at all.
   
   The run confirms the timing — the completed point for the fast pipeline fires ~1.4 s after the job starts running, long before the polling loop can catch a partial value:
   
   ```
   16:32:21,224 PhysicalPlan - Job testBatchJobCompletesAfterMasterFailoverDuringCloseHandshake (1148294491912798209) ...
   16:32:22,641 CheckpointCoordinator - skip schedule trigger checkpoint because checkpoint type is COMPLETED_POINT_TYPE
   ```
   
   A 20 ms poll cannot reliably observe a window that narrow, and once the key is removed the count is 0 for the rest of the 30 s — exactly what the failure message reports.
   
   So the engine behaviour is correct here; the test's assumption about where a partial handshake is observable is what is wrong. This is a pure test-design defect and the fix belongs entirely in the test file.
   
   #### Why I have not pushed a redesign yet
   
   Making this deterministic is not a one-line change. The scenario needs a genuine partial handshake that persists long enough to land a failover on, which means either:
   
   - driving a **single** pipeline whose starting subtasks report readiness at clearly separated times (with `FakeSource` splits assigned round-robin, the parallel subtasks of one source finish near-simultaneously, so this needs a deliberately asymmetric source setup), or
   - instrumenting a different, non-transient observation point instead of the `readyToClose` IMap key.
   
   I would rather agree the approach than guess: this repository's policy is CI-only verification for these E2E paths, so an unvalidated redesign costs a full CI cycle per attempt. I am explicitly **not** widening the 30 s timeout or relaxing the assertion — the window being waited for does not exist in steady state, so loosening the bound would just make the test pass without testing anything.
   
   Marking this as blocking pending agreement on which of the two directions above to take.
   


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org