You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by gi...@apache.org on 2026/09/10 16:22:10 UTC
(seatunnel) branch gh-readonly-queue/dev/pr-12027-98ff97a743a175242a5c79087afbdb5feb0db684 created (now 3847226697)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/dev/pr-12027-98ff97a743a175242a5c79087afbdb5feb0db684
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
at 3847226697 [Test][E2E] Add regression coverage for duplicate pending-job dispatch after failover (#12027)
This branch includes the following new commits:
new 3847226697 [Test][E2E] Add regression coverage for duplicate pending-job dispatch after failover (#12027)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(seatunnel) 01/01: [Test][E2E] Add regression coverage for duplicate pending-job dispatch after failover (#12027)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/dev/pr-12027-98ff97a743a175242a5c79087afbdb5feb0db684
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
commit 384722669785f45d6354d71928f664a0f4423747
Author: David Zollo <da...@gmail.com>
AuthorDate: Thu Sep 10 15:53:14 2026 +0000
[Test][E2E] Add regression coverage for duplicate pending-job dispatch after failover (#12027)
Co-authored-by: Claude Sonnet 5 <no...@anthropic.com>
---
.../SplitClusterPendingJobLifecycleFailoverIT.java | 241 +++++++++++++++++++++
1 file changed, 241 insertions(+)
diff --git a/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/SplitClusterPendingJobLifecycleFailoverIT.java b/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/SplitClusterPendingJobLifecycleFailoverIT.java
index 964828cef2..2809eef410 100644
--- a/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/SplitClusterPendingJobLifecycleFailoverIT.java
+++ b/seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/SplitClusterPendingJobLifecycleFailoverIT.java
@@ -64,6 +64,28 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
+/**
+ * Multi-node failover coverage for the lifecycle of jobs that cannot be dispatched immediately.
+ *
+ * <p>Every scenario here builds a real split cluster (separate master and worker Hazelcast
+ * instances) and changes master ownership while a {@code ScheduleStrategy.WAIT} job is held back by
+ * occupied worker slots. That exercises the coordinator's pending-job bookkeeping against real
+ * membership changes and real resource contention, rather than against mocked coordinator state as
+ * the single-JVM unit tests do.
+ *
+ * <p>Scenarios covered:
+ *
+ * <ul>
+ * <li>{@code testPendingJobLifecycleInMasterFailover} - a pending job survives a single master
+ * handoff and is dispatched once the cluster grows enough capacity for it.
+ * <li>{@code testPendingJobScheduledAfterRunningJobCanceled} - a pending job is dispatched after
+ * the running job occupying its slots is canceled.
+ * <li>{@code testPendingJobNotDuplicatedAcrossRepeatedMasterFailover} - repeated master handoffs
+ * never revive a stale schedule generation, so the job is dispatched exactly once.
+ * <li>{@code testTerminalJobCleanupSkipsWorkerWaitAfterMasterSwitch} - cleanup of a terminal job
+ * is not blocked behind the worker-wait gate that live jobs go through after a master switch.
+ * </ul>
+ */
@Slf4j
public class SplitClusterPendingJobLifecycleFailoverIT {
private static final String JOB_CONFIG_FILE = "pending_jobs_streaming_lifecycle.conf";
@@ -427,6 +449,179 @@ public class SplitClusterPendingJobLifecycleFailoverIT {
}
}
+ /**
+ * Regression test for the duplicate pending-job dispatch bug fixed by <a
+ * href="https://github.com/apache/seatunnel/pull/11653">#11653</a> ("[Fix][Zeta] Avoid
+ * duplicate pending job scheduling after failover"). That fix introduced a monotonic scheduling
+ * epoch so a scheduler thread from a stale master generation cannot dispatch a pending job that
+ * a newer generation has already claimed, and made {@code clearCoordinatorService}
+ * unconditionally drop interrupted pending jobs from the local queue so a later flap-back
+ * cannot re-dispatch a poisoned {@code JobMaster}. The fix already ships with unit-level
+ * coverage of the epoch/lock mechanism in isolation ({@code CoordinatorServiceTest}); this test
+ * proves the same invariant holds through the real multi-node integration path: a real client
+ * submission, real Hazelcast membership changes, and real resource contention.
+ *
+ * <p>{@code ScheduleStrategy.WAIT} (set by {@link #configurePendingLifecycleTest}) sleeps a
+ * fixed 3 seconds between resource re-checks in {@code CoordinatorService#pendingJobSchedule},
+ * which gives this test a wide, deterministic window to land repeated master failovers while
+ * the pending job is actively being re-evaluated, instead of chasing a microsecond-scale race.
+ *
+ * <p>The contested job is a small bounded batch job rather than the streaming holder template,
+ * so it reaches FINISHED with an exactly countable output: if it were ever dispatched twice as
+ * two independent {@code JobMaster} instances, the sink would end up with double the expected
+ * rows instead of exactly {@code testRowNumber * testParallelism}.
+ */
+ @Test
+ public void testPendingJobNotDuplicatedAcrossRepeatedMasterFailover() throws Exception {
+ String testCaseName = "pendingJobNotDuplicatedAcrossRepeatedMasterFailover";
+ String testClusterName =
+ "SplitClusterPendingJobLifecycleFailoverIT_"
+ + "testPendingJobNotDuplicatedAcrossRepeatedMasterFailover";
+ long testRowNumber = 20;
+ int testParallelism = 1;
+ int flapRounds = 4;
+
+ HazelcastInstanceImpl workerNode = null;
+ HazelcastInstanceImpl extraWorkerNode = null;
+ SeaTunnelClient engineClient = null;
+ List<HazelcastInstanceImpl> masterNodes = new ArrayList<>();
+
+ try {
+ SeaTunnelConfig masterNode1Config = getSeaTunnelConfig(testClusterName);
+ SeaTunnelConfig masterNode2Config = getSeaTunnelConfig(testClusterName);
+ SeaTunnelConfig workerNodeConfig = getSeaTunnelConfig(testClusterName);
+ configurePendingLifecycleTest(masterNode1Config);
+ configurePendingLifecycleTest(masterNode2Config);
+ configurePendingLifecycleTest(workerNodeConfig);
+
+ masterNodes.add(
+ SeaTunnelServerStarter.createMasterHazelcastInstance(masterNode1Config));
+ masterNodes.add(
+ SeaTunnelServerStarter.createMasterHazelcastInstance(masterNode2Config));
+ workerNode = SeaTunnelServerStarter.createWorkerHazelcastInstance(workerNodeConfig);
+
+ HazelcastInstanceImpl finalWorkerNode = workerNode;
+ Awaitility.await()
+ .atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(
+ () ->
+ Assertions.assertEquals(
+ 3, finalWorkerNode.getCluster().getMembers().size()));
+
+ Common.setDeployMode(DeployMode.CLUSTER);
+ ClientConfig clientConfig = ConfigProvider.locateAndGetClientConfig();
+ clientConfig.setClusterName(TestUtils.getClusterName(testClusterName));
+ engineClient = new SeaTunnelClient(clientConfig);
+
+ ClientJobProxy holderJob =
+ submitJob(
+ engineClient,
+ masterNode1Config,
+ "pending_job_duplicate_dispatch_holder",
+ TestUtils.getResource(JOB_CONFIG_FILE));
+ assertJobStatusWithTimeout(holderJob, JobStatus.RUNNING, 120);
+
+ ImmutablePair<String, String> contestedJobResources =
+ createBatchTestResources(testCaseName, testRowNumber, testParallelism);
+ ClientJobProxy pendingJob =
+ submitJob(
+ engineClient,
+ masterNode1Config,
+ "pending_job_duplicate_dispatch_contested",
+ contestedJobResources.getRight());
+ long pendingJobId = pendingJob.getJobId();
+ assertJobStatusWithTimeout(pendingJob, JobStatus.PENDING, 120);
+
+ HazelcastInstanceImpl currentActive =
+ waitAndFindActiveMaster(masterNodes.get(0), masterNodes.get(1));
+ HazelcastInstanceImpl currentStandby =
+ currentActive == masterNodes.get(0) ? masterNodes.get(1) : masterNodes.get(0);
+
+ for (int round = 0; round < flapRounds; round++) {
+ currentActive.shutdown();
+ HazelcastInstanceImpl newActive = currentStandby;
+ awaitCoordinatorActive(newActive, 30);
+
+ SeaTunnelConfig replacementConfig = getSeaTunnelConfig(testClusterName);
+ configurePendingLifecycleTest(replacementConfig);
+ HazelcastInstanceImpl replacement =
+ SeaTunnelServerStarter.createMasterHazelcastInstance(replacementConfig);
+ masterNodes.add(replacement);
+
+ HazelcastInstanceImpl finalNewActive = newActive;
+ Awaitility.await()
+ .atMost(30, TimeUnit.SECONDS)
+ .untilAsserted(
+ () ->
+ Assertions.assertEquals(
+ 3,
+ finalNewActive.getCluster().getMembers().size()));
+
+ currentActive = newActive;
+ currentStandby = replacement;
+ }
+
+ // The job must have survived every epoch transition above as a single, still-pending
+ // entry before resources are freed, ruling out both the "silently lost" and the
+ // "already running under a stale generation" pre-fix failure modes.
+ ClientJobProxy pendingJobAfterFlapping =
+ engineClient.createJobClient().getJobProxy(pendingJobId);
+ assertJobStatusWithTimeout(pendingJobAfterFlapping, JobStatus.PENDING, 60);
+
+ // Hand off one final time while every worker slot is still occupied by the holder, so
+ // a coordinator that never saw the original submission has to rebuild the pending entry
+ // purely from distributed state. It must still be a single pending copy afterwards; a
+ // stale generation revived here would show up as a second dispatch below.
+ currentActive.shutdown();
+ awaitCoordinatorActive(currentStandby, 30);
+ assertJobStatusWithTimeout(pendingJobAfterFlapping, JobStatus.PENDING, 60);
+
+ // Free capacity by growing the cluster rather than by cancelling the holder. Cancelling
+ // the holder and immediately shutting its master down would additionally require the
+ // terminal job's worker slots to be reclaimed by the next coordinator, which is a
+ // separate resource-lifecycle concern from the duplicate-dispatch invariant under test.
+ // Adding a worker keeps the assertions below attributable to scheduling alone, and
+ // matches how testPendingJobLifecycleInMasterFailover releases a pending job.
+ SeaTunnelConfig extraWorkerConfig = getSeaTunnelConfig(testClusterName);
+ configurePendingLifecycleTest(extraWorkerConfig);
+ extraWorkerNode =
+ SeaTunnelServerStarter.createWorkerHazelcastInstance(extraWorkerConfig);
+
+ HazelcastInstanceImpl finalCoordinator = currentStandby;
+ Awaitility.await()
+ .atMost(60, TimeUnit.SECONDS)
+ .untilAsserted(
+ () ->
+ Assertions.assertEquals(
+ 3, finalCoordinator.getCluster().getMembers().size()));
+
+ assertJobStatusWithTimeout(pendingJobAfterFlapping, JobStatus.FINISHED, 180);
+
+ Long finalLineCount =
+ FileUtils.getFileLineNumberFromDir(contestedJobResources.getLeft());
+ Assertions.assertEquals(
+ testRowNumber * testParallelism,
+ finalLineCount,
+ "Contested job output must equal exactly one dispatch's worth of rows; a "
+ + "duplicate dispatch across the master flaps above would double it");
+ } finally {
+ if (engineClient != null) {
+ engineClient.close();
+ }
+ if (workerNode != null) {
+ workerNode.shutdown();
+ }
+ if (extraWorkerNode != null) {
+ extraWorkerNode.shutdown();
+ }
+ for (HazelcastInstanceImpl masterNode : masterNodes) {
+ if (masterNode.getLifecycleService().isRunning()) {
+ masterNode.shutdown();
+ }
+ }
+ }
+ }
+
/**
* Regression test for the terminal-zombie-job restore gate fixed by <a
* href="https://github.com/apache/seatunnel/pull/10692">#10692</a> ("[Fix][Zeta] Prevent
@@ -1008,6 +1203,52 @@ public class SplitClusterPendingJobLifecycleFailoverIT {
});
}
+ /** Waits until a standby master has taken over coordinator activity after a failover. */
+ private static void awaitCoordinatorActive(
+ HazelcastInstanceImpl masterNode, long timeoutSeconds) {
+ Awaitility.await()
+ .atMost(timeoutSeconds, TimeUnit.SECONDS)
+ .untilAsserted(
+ () -> {
+ Assertions.assertTrue(masterNode.getLifecycleService().isRunning());
+ Assertions.assertTrue(
+ isCoordinatorActive(masterNode),
+ "Standby master should become active after failover");
+ });
+ }
+
+ /**
+ * Renders a small bounded batch job from {@code cluster_batch_fake_to_localfile_template.conf}
+ * so the resulting output is exactly countable once the job reaches FINISHED. Mirrors {@code
+ * ClusterFaultToleranceIT#createTestResources}; kept local since it is only needed by the
+ * duplicate-dispatch regression test in this class.
+ *
+ * @return pair of (sink output directory, generated job config file path)
+ */
+ private static ImmutablePair<String, String> createBatchTestResources(
+ String testCaseName, long rowNumber, int parallelism) throws IOException {
+ Map<String, String> valueMap = new HashMap<>();
+ valueMap.put("dynamic_test_case_name", testCaseName);
+ valueMap.put("dynamic_job_mode", JobMode.BATCH.toString());
+ valueMap.put("dynamic_test_row_num_per_parallelism", String.valueOf(rowNumber));
+ valueMap.put("dynamic_test_parallelism", String.valueOf(parallelism));
+
+ String targetDir = ("/tmp/hive/warehouse/" + testCaseName).replace("/", File.separator);
+ FileUtils.createNewDir(targetDir);
+
+ String targetConfigFilePath =
+ File.separator
+ + "tmp"
+ + File.separator
+ + "test_conf"
+ + File.separator
+ + testCaseName
+ + ".conf";
+ TestUtils.createTestConfigFileFromTemplate(
+ "cluster_batch_fake_to_localfile_template.conf", valueMap, targetConfigFilePath);
+ return new ImmutablePair<>(targetDir, targetConfigFilePath);
+ }
+
private static boolean isCoordinatorActive(HazelcastInstanceImpl masterNode) {
if (masterNode == null || !masterNode.getLifecycleService().isRunning()) {
return false;