zhangshenghang opened a new issue, #13515:
URL: https://github.com/apache/seatunnel/issues/13515

   ### Search before asking
   
   - [x] I searched the existing issues and PRs before filing.
   
   ### What happened
   
   When two or more clients submit the **same job id** at nearly the same time, 
every submission returns success, but the job creates more than one `JobMaster` 
for that id and then never reaches a terminal state. Its tasks run to 
completion and write all rows, yet the job stays `RUNNING` forever; only a 
manual cancel or a master restart clears it.
   
   Reproduced on `dev` (`ee0fb0d72f`) with a single in-process Zeta node and a 
trivial bounded job (FakeSource, 200 rows -> LocalFile, BATCH):
   
   1. Build 6 to 8 `ClientJobExecutionEnvironment`s against the same cluster, 
each with its own `JobConfig` but the **same explicit job id**.
   2. Release them together so all of them call `execute()` at the same moment.
   3. Every submission returns successfully (`ok <jobId>` x N), and every 
client receives a proxy for that job id.
   4. The sink receives exactly 200 lines (the workers skip the redundant 
task-group deploy), so the data path looks correct.
   5. The job never becomes `FINISHED`. Observing it for 180 seconds after the 
last row was written, `getJobStatus()` still returns `RUNNING`.
   
   Server log signatures from that run:
   
   ```text
   WARN TaskExecutionService - TaskGroupLocation{jobId=..., pipelineId=1, 
taskGroupId=1}
     already exists and is active, skipping redeploy for master failover 
recovery
   WARN TaskExecutionService - TaskGroupLocation{jobId=..., pipelineId=1, 
taskGroupId=2}
     already exists and is active, skipping redeploy for master failover 
recovery
   WARN PhysicalPlan - Job <name> (<id>) state process is stopped
   WARN CheckpointCoordinator - checkpoint_state_<id>_1 has already been 
cleaned, skip persisting transition to FINISHED
   WARN PhysicalVertex - ... state process is not start
   ```
   
   The `already exists and is active` warnings come from the second and third 
`PhysicalPlan` trying to deploy task groups the first one already deployed. The 
shared job/pipeline/task state is then updated by competing state machines, and 
the terminal transition is lost.
   
   ### Root cause
   
   `CoordinatorService#submitJob` splits the duplicate check and the 
publication of the new job onto different threads:
   
   1. On the caller (RPC) thread it checks `getJobMaster(jobId) != null`. That 
only sees a `JobMaster` already put into `pendingJobQueue` / 
`runningJobMasterMap`.
   2. It then schedules an asynchronous admission task. That task deserializes 
the job, builds `new JobMaster(...)`, calls `init()`, and only then performs 
`pendingJobQueue.put(...)` and completes the submission future.
   
   A second submission that arrives between step 1 and the 
`pendingJobQueue.put(...)` in step 2 also sees `getJobMaster(jobId) == null`, 
so it builds a second `JobMaster` for the same job id. Both are enqueued and 
both are scheduled. Nothing later rejects the duplicate: the worker's 
`TaskExecutionService` sees the same `TaskGroupLocation` already active and 
skips the deploy, so the duplicate `PhysicalPlan` keeps running against state 
that the first one owns.
   
   The window is not exotic: admitting one job deserializes the DAG, builds the 
physical plan and creates the checkpoint manager, which takes tens of 
milliseconds. Any client retry (a timeout before the response arrives, an 
operator re-running the same command, or two submitters using the same explicit 
job id) hits it.
   
   ### Impact
   
   - A bounded/streaming job can be left permanently `RUNNING` with all its 
data already processed. It reports no error and holds its slots/checkpoint 
coordinator, so it also blocks `WAIT` capacity and confuses monitoring.
   - The same id can hold duplicate `JobMaster`s, duplicate 
`CheckpointCoordinator`s and duplicate resource pre-applies, all writing the 
same `runningJobStateIMap` / `runningJobStateTimestampsIMap` keys.
   - The client cannot recover by itself: it was told the submission succeeded, 
and cancelling affects the (single) visible id.
   
   ### Expected behavior
   
   Admission of one job id must be atomic. A redundant submission of a job id 
whose first submission is still being admitted must resolve to that same job 
(the existing dedicated "the job is currently running; no need to submit again" 
path already defines this behavior for an already published job), and only one 
`JobMaster` may ever be created and enqueued for the id.
   
   ### Suggested fix direction
   
   Track in-flight submissions per job id on the coordinator (an atomic 
`putIfAbsent` registry of the submission future). The first caller owns the 
admission; concurrent duplicates get the owner's future instead of starting a 
second admission. Remove the entry when admission finishes (success or failure) 
and fail the registered futures when the coordinator steps down so a retry 
against the next active master cannot wait on a stale entry.
   
   I have an E2E (`ConcurrentDuplicateSubmissionIT`) that drives 8 concurrent 
identical submissions on an in-process cluster and asserts: all submissions 
resolve, the job reaches `FINISHED`, and the sink contains exactly one copy of 
the rows. On unmodified `dev` this test fails with the job stuck in `RUNNING` 
(proven above); with the fix it passes twice back to back. I will submit it 
together with the fix.
   
   ### SeaTunnel Version
   
   dev (`ee0fb0d72f`), Zeta engine, `3.1.1-SNAPSHOT`
   
   ### Zeta or Flink or Spark Version
   
   Zeta
   
   ### Java or Scala Version
   
   17
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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