You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "DanielLeens (via GitHub)" <gi...@apache.org> on 2026/04/20 06:55:22 UTC
Re: [PR] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
DanielLeens commented on PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#issuecomment-4278476849
Hi @dybyte, thank you for the update. I reviewed the PR locally from branch `seatunnel-review-10506` at commit `95c8d42364e7b90e85f8ab29d0da31e843844169`, compared against merge base `2ab882482afe3665c183dc9a6559f59df0aab029`. I did source-level review only and did not run tests locally; the visible GitHub Build check is green.
# What This PR Solves
- User pain point: during a master switch, workers can report task state before the new master has restored `runningJobMasterMap`. The old path returns `JobNotFoundException`, and the worker treats that as a terminal notification result, so the restored `JobMaster` can miss the task's final state.
- Fix approach: the PR introduces `JobRestoreInProgressException`. If `updateTaskExecutionState()` sees the job missing while master-switch restore is still running, it throws this retryable exception instead of `JobNotFoundException`; the worker then sleeps and retries.
- One-sentence summary: this prevents task-state notifications from being dropped during the new master's restore window.
Simple example: a task finishes while master A has failed and master B is still rebuilding the job masters. Before this PR, the worker could be told “job not found” and stop notifying. After this PR, master B says “restore in progress”, so the worker retries until the job master is available again.
# 1. Code Change Review
## 1.1 Core Logic Analysis
### Precise Change Description
- `seatunnel-engine/seatunnel-engine-common/src/main/java/org/apache/seatunnel/engine/common/exception/JobRestoreInProgressException.java:20-32` adds a dedicated engine exception.
- `seatunnel-engine/seatunnel-engine-common/src/main/java/org/apache/seatunnel/engine/common/utils/ExceptionUtil.java:65-68` registers the exception with Hazelcast client exception mapping.
- `seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1223-1248` changes `updateTaskExecutionState()` so a missing `JobMaster` during restore throws `JobRestoreInProgressException`.
- `seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/TaskExecutionService.java:456-508` catches the new exception and retries notification after a sleep.
- `CoordinatorServiceTest.java` adds coverage for restore-in-progress, real not-found, failed restore, and removed-job cases.
### Before / After Snippets
Before:
```java
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
if (runningJobMaster == null) {
throw new JobNotFoundException(
String.format("Job %s not running", taskGroupLocation.getJobId()));
}
runningJobMaster.updateTaskExecutionState(taskExecutionState);
```
After:
```java
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
if (runningJobMaster == null && !restoreAllJobFromMasterNodeSwitchFuture.isDone()) {
throw new JobRestoreInProgressException(
String.format(
"Job %s not running (restore in progress)",
taskGroupLocation.getJobId()));
}
if (runningJobMaster == null) {
throw new JobNotFoundException(
String.format("Job %s not running", taskGroupLocation.getJobId()));
}
runningJobMaster.updateTaskExecutionState(taskExecutionState);
```
Before:
```java
} catch (JobNotFoundException e) {
logger.warning("send notify task status failed because can't find job", e);
notifyStateSuccess = true;
}
```
After:
```java
} catch (JobRestoreInProgressException e) {
logger.info(ExceptionUtils.getMessage(e));
logger.info(
String.format(
"notify the job of the task(%s) status failed, retry in %s millis",
taskGroupLocation, sleepTime));
Thread.sleep(sleepTime);
}
```
### Key Findings
- The normal affected path is real: `NotifyTaskStatusOperation.runInternal()` calls `CoordinatorService.updateTaskExecutionState()` from the worker-to-master notification path.
- The PR specifically covers the master-switch restore window where `restoreAllJobFromMasterNodeSwitchFuture` is not done and `runningJobMasterMap` is temporarily incomplete.
- This is a targeted fix, not a broad state-machine rewrite.
- The original `JobNotFoundException` behavior is preserved after restore completes or when the job is genuinely unknown/removed.
### Deep Correctness Analysis
The full runtime chain is:
```text
Worker task reaches terminal state
-> TaskExecutionService.notifyTaskStatusToMaster()
-> OperationService.invoke(new NotifyTaskStatusOperation(...), masterAddress)
-> NotifyTaskStatusOperation.runInternal() on current master
-> CoordinatorService.updateTaskExecutionState()
-> runningJobMasterMap.get(jobId)
-- found
-> JobMaster.updateTaskExecutionState()
-- missing and restoreAllJobFromMasterNodeSwitchFuture not done
-> throw JobRestoreInProgressException
-> worker logs and retries after 1s
-- missing and restore future done
-> throw JobNotFoundException
-> worker treats it as terminal not-found and stops retrying
Master switch path
-> initCoordinatorService()
-> restoreAllJobFromMasterNodeSwitchFuture =
CompletableFuture.runAsync(restoreAllRunningJobFromMasterNodeSwitch)
-> restoreAllRunningJobFromMasterNodeSwitch()
-> scan runningJobInfoIMap
-> wait for worker registration
-> restoreJobFromMasterActiveSwitch()
-> recreate JobMaster / repopulate runningJobMasterMap
```
The important part is that the retry is bounded by the same lifecycle signal that owns restore: once `restoreAllJobFromMasterNodeSwitchFuture` completes, the method falls back to `JobNotFoundException`. That keeps genuine deleted/unknown-job cases from retrying forever after restore is done.
## 1.2 Compatibility Impact
Judgement: fully compatible.
- API: adds an internal engine exception class; no public user API is changed.
- Config: no config changes.
- Defaults: no default behavior changes outside the restore race window.
- Protocol: Hazelcast client exception registration gets one new SeaTunnel exception code.
- Serialization format: no job/checkpoint state format change.
- Historical behavior: the only changed behavior is that a temporary master-restore miss becomes retryable instead of terminal.
## 1.3 Performance / Side Effect Analysis
- CPU: no hot-path overhead except one `isDone()` check when task state notification reaches the master.
- Memory/GC: one new exception object only when the restore race is hit.
- Network: retry can add repeated notification RPCs during restore, but only while the master is rebuilding job masters.
- Lock contention/concurrency: uses existing `ConcurrentHashMap` and existing restore future; no new lock is introduced.
- Retry/idempotency: task-state notification is already retry-based. Re-sending the same task state during restore is acceptable because the state is only applied once a `JobMaster` exists.
- Resource release: production code introduces no new resources.
## 1.4 Error Handling And Logs
The error distinction is improved: restore-in-progress is logged at INFO and retried, while real not-found remains WARN and terminal for the worker notification loop.
### Issue 1: Test helper executor is not shut down
- Location: `seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/CoordinatorServiceTest.java:801`
- Problem description: `testUpdateTaskExecutionStateRetriesUntilRestoreComplete()` creates `Executors.newSingleThreadExecutor()` only to reinsert the `JobMaster` after a short delay, but it does not retain or shut down the executor service.
- Potential risk: this is test-only and did not fail the current Build check, but it can leave an idle non-daemon test thread and make future test-suite behavior harder to reason about.
- Best improvement suggestion: keep the `ExecutorService` in a local variable and call `shutdownNow()` in a `finally` block, or use a `CompletableFuture.delayedExecutor(...)` style helper if available.
- Severity: low
# 2. Code Quality Evaluation
## 2.1 Code Style
The production code follows the existing engine exception and retry style. The new file includes the ASF header. `git diff --check` reported no whitespace errors.
## 2.2 Test Coverage
The PR adds focused tests for the main restore-in-progress case and for the fallback cases where the job is truly not found or restore has completed/failed. Remaining coverage gap: the tests call `CoordinatorService.updateTaskExecutionState()` directly, so they do not fully exercise Hazelcast operation exception wrapping through `NotifyTaskStatusOperation`, but the worker already retries generic non-`JobNotFoundException` execution failures as well.
## 2.3 Documentation
No user-facing docs are required because this is an internal engine race fix with no new user configuration.
# 3. Architecture Reasonableness
## 3.1 Elegance Of The Solution
This is a precise fix. It adds a specific transient exception rather than weakening `JobNotFoundException` globally.
## 3.2 Maintainability
The boundary is clear: `CoordinatorService` decides whether missing job state is transient, and `TaskExecutionService` owns retrying worker notifications. This keeps the state-machine decision close to restore ownership.
## 3.3 Extensibility
The pattern is reusable for other master-restore transient cases if needed, but it does not over-generalize the current bug into a larger retry framework.
## 3.4 Historical Version Compatibility
Fully compatible. Existing jobs/checkpoints do not need migration.
# 4. Issue Summary
| No. | Issue | Location | Severity |
|---|---|---|---|
| 1 | Test helper executor is not shut down | `CoordinatorServiceTest.java:801` | Low |
# 5. Merge Conclusion
### Conclusion: can merge
1. Blocking items that must be fixed:
- None. I did not find a blocking production issue.
2. Recommended fixes, non-blocking:
- Issue 1: shut down the test helper executor to avoid test-thread leakage. This is cleanup-level and should not block merge because the production path and current Build check look good.
Overall, this is a good targeted fix for a real master-switch restore race. I also verified with a temporary local worktree that the PR auto-merges cleanly into current `upstream/dev`, and the visible GitHub Build check is green.
--
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