You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "dybyte (via GitHub)" <gi...@apache.org> on 2026/02/22 17:49:13 UTC
[PR] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
dybyte opened a new pull request, #10506:
URL: https://github.com/apache/seatunnel/pull/10506
### Purpose of this pull request
When `CoordinatorService` is restored, `CoordinatorService.restoreAllRunningJobFromMasterNodeSwitch()` is executed asynchronously.
If `CoordinatorService.updateTaskExecutionState()` is invoked during this process, the `runningJobMasterMap` may not yet be fully restored, which can result in a `JobNotFoundException`.
This behavior is particularly critical when a worker node reports a terminal state to the master node.
If the master fails to receive the terminal state, the corresponding job may never be marked as completed.
```
private void notifyTaskStatusToMaster(
TaskGroupLocation taskGroupLocation, TaskExecutionState taskExecutionState) {
long sleepTime = 1000;
boolean notifyStateSuccess = false;
while (isRunning && !notifyStateSuccess) {
InvocationFuture<Object> invoke =
nodeEngine
.getOperationService()
.createInvocationBuilder(
SeaTunnelServer.SERVICE_NAME,
new NotifyTaskStatusOperation(
taskGroupLocation, taskExecutionState),
nodeEngine.getMasterAddress())
.invoke();
try {
invoke.get();
notifyStateSuccess = true;
} catch (InterruptedException e) {
logger.severe("send notify task status failed", e);
} catch (JobNotFoundException e) {
logger.warning("send notify task status failed because can't find job", e);
notifyStateSuccess = true;
// If updateTaskExecutionState() throws JobNotFoundException, this operation is ignored
} catch (ExecutionException e) {
if (e.getCause() instanceof JobNotFoundException) {
logger.warning("send notify task status failed because can't find job", e);
notifyStateSuccess = true;
} else {
logger.warning(ExceptionUtils.getMessage(e));
logger.warning(
String.format(
"notify the job of the task(%s) status failed, retry in %s millis",
taskGroupLocation, sleepTime));
try {
Thread.sleep(sleepTime);
} catch (InterruptedException ex) {
logger.severe(e);
}
}
}
}
}
```
```
public void updateTaskExecutionState(TaskExecutionState taskExecutionState) {
logger.info(
String.format(
"Received task end from execution %s, state %s",
taskExecutionState.getTaskGroupLocation(),
taskExecutionState.getExecutionState()));
TaskGroupLocation taskGroupLocation = taskExecutionState.getTaskGroupLocation();
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
if (runningJobMaster == null) {
throw new JobNotFoundException(
String.format("Job %s not running", taskGroupLocation.getJobId()));
}
runningJobMaster.updateTaskExecutionState(taskExecutionState);
}
```
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
- `testUpdateTaskExecutionStateWaitsForRestoreCompletion()`
- `testUpdateTaskExecutionStateThrowsWhenJobNotFound()`
### Check list
* [ ] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] If necessary, please update `incompatible-changes.md` to describe the incompatibility caused by this PR.
* [ ] If you are contributing the connector code, please check that the following files are updated:
1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
--
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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo merged PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506
--
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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#issuecomment-4003457207
@yzeng1618 Updated, thanks
--
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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "DanielLeens (via GitHub)" <gi...@apache.org>.
DanielLeens commented on PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#issuecomment-4899173092
Thanks @nzw921rx. I rechecked the current PR metadata on the unchanged head `6c0b5e381d8c046a89f7a5b16959ccd7f9fc5557` before replying here. Daniel already approved this exact revision on July 4, 2026 after the earlier CI gate turned green, and there is still no new code delta after that approval. From Daniel's side I do not see a reopened source-level blocker on the current head, so there is nothing new to add beyond the existing approval unless a follow-up commit lands.
--
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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "yzeng1618 (via GitHub)" <gi...@apache.org>.
yzeng1618 commented on code in PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#discussion_r2887359923
##########
seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/CoordinatorServiceTest.java:
##########
@@ -480,6 +486,200 @@ public void testClearCoordinatorService() {
.count());
}
+ @Test
+ void testUpdateTaskExecutionStateWaitsForRestoreCompletion() throws Exception {
Review Comment:
update the test method name to reflect the actual behavior,refer to testUpdateTaskExecutionStateRetriesUntilRestoreComplete
##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/TaskExecutionService.java:
##########
@@ -461,6 +462,17 @@ private void notifyTaskStatusToMaster(
} catch (JobNotFoundException e) {
logger.warning("send notify task status failed because can't find job", e);
notifyStateSuccess = true;
+ } 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));
+ try {
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException ex) {
+ logger.severe(e);
Review Comment:
It is recommended to change it to ex and invoke Thread.currentThread().interrupt() to restore the interrupt flag.
--
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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "DanielLeens (via GitHub)" <gi...@apache.org>.
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
Re: [PR] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#issuecomment-3944612956
@DanielCarter-stack
Issue 1,2,3,4 have been addressed.
Also, it seems `updateTaskExecutionState()` never gets called by `TaskExecutionService` when the job is still `PENDING`.
--
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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "DanielCarter-stack (via GitHub)" <gi...@apache.org>.
DanielCarter-stack commented on PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#issuecomment-3941608493
<!-- code-pr-reviewer -->
<!-- cpr:pr_reply_v2_parts {"group": "apache/seatunnel#10506", "part": 1, "total": 1} -->
### Issue 1: Improper exception handling when Restore fails
**Location**: `CoordinatorService.java:898-901`
```java
if (runningJobMaster == null) {
restoreAllJobFromMasterNodeSwitchFuture.join(); // May throw CompletionException
runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
}
```
**Related context**:
- `restoreAllRunningJobFromMasterNodeSwitch()` (lines 449-504): Throws `SeaTunnelEngineException` on exception
- `TaskExecutionService.notifyTaskStatusToMaster()` (lines 442-480): Expects to catch `JobNotFoundException`
**Issue description**:
If `restoreAllJobFromMasterNodeSwitchFuture` completes exceptionally due to restore failure, `.join()` will throw `CompletionException` (wrapping `SeaTunnelEngineException`), instead of the expected `JobNotFoundException`. This leads to:
1. Worker-side retry logic becomes ineffective: `notifyTaskStatusToMaster()` only catches `JobNotFoundException`, for `CompletionException` it will enter the generic exception branch and continue retrying
2. Log pollution: A large number of retries will generate warning logs
3. Semantic confusion: restore failure and job not found are two different errors and should be handled separately
**Potential risks**:
- **Risk 1**: After restore failure, all task status updates will fail and continuously retry, affecting system stability
- **Risk 2**: Error logs will mislead operations personnel, as it looks like "job not found" but is actually "restore failed"
**Impact scope**:
- **Direct impact**: `CoordinatorService.updateTaskExecutionState()` method
- **Indirect impact**: `TaskExecutionService.notifyTaskStatusToMaster()` retry logic
- **Affected area**: Zeta core framework, all jobs in scenarios where master switches and restore fails
**Severity**: **MAJOR**
**Improvement suggestion**:
```java
// CoordinatorService.java:890-907
public void updateTaskExecutionState(TaskExecutionState taskExecutionState) {
logger.info(
String.format(
"Received task end from execution %s, state %s",
taskExecutionState.getTaskGroupLocation(),
taskExecutionState.getExecutionState()));
TaskGroupLocation taskGroupLocation = taskExecutionState.getTaskGroupLocation();
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
if (runningJobMaster == null) {
try {
// Wait for job restoration to complete during master node switch
restoreAllJobFromMasterNodeSwitchFuture.join();
} catch (Exception e) {
// If restore failed, treat it as job not found and log the error
logger.warning(
String.format(
"Failed to wait for restore completion for job %s: %s",
taskGroupLocation.getJobId(),
ExceptionUtils.getMessage(e)));
throw new JobNotFoundException(
String.format("Job %s not running (restore failed)",
taskGroupLocation.getJobId()), e);
}
runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
}
if (runningJobMaster == null) {
throw new JobNotFoundException(
String.format("Job %s not running", taskGroupLocation.getJobId()));
}
runningJobMaster.updateTaskExecutionState(taskExecutionState);
}
```
**Rationale**:
- Catch all exceptions that `.join()` may throw, convert to `JobNotFoundException`
- Keep worker-side retry logic working normally
- Clearly distinguish between "restore failed" and "job not found" in logs
---
### Issue 2: Missing critical logs and comments
**Location**: `CoordinatorService.java:898-901`
```java
if (runningJobMaster == null) {
restoreAllJobFromMasterNodeSwitchFuture.join();
runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
}
```
**Related context**:
- Method JavaDoc: None
- Caller: `NotifyTaskStatusOperation.runInternal()` (lines 71-74)
**Issue description**:
The newly added waiting logic has no comments explaining it, and no logs are recorded when triggered. This leads to:
1. **Poor maintainability**: Future code reviewers or maintainers won't understand why we need to join future here
2. **Weak diagnosability**: When status updates are delayed due to master switch, it's impossible to see from logs that we're waiting for restore
3. **Difficult debugging**: When problems occur in production, it's impossible to determine whether this waiting branch was entered
**Potential risks**:
- **Risk 1**: Future developers may mistakenly think this is an unnecessary block and remove it
- **Risk 2**: During performance tuning, unable to accurately assess the impact of master switch on status updates
**Impact scope**:
- **Direct impact**: Code maintainability and observability
- **Indirect impact**: Problem diagnosis efficiency
- **Affected area**: Only affects `CoordinatorService.updateTaskExecutionState()` method
**Severity**: **MINOR**
**Improvement suggestion**:
```java
public void updateTaskExecutionState(TaskExecutionState taskExecutionState) {
logger.info(
String.format(
"Received task end from execution %s, state %s",
taskExecutionState.getTaskGroupLocation(),
taskExecutionState.getExecutionState()));
TaskGroupLocation taskGroupLocation = taskExecutionState.getTaskGroupLocation();
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
// During master node switch, jobs are being restored asynchronously.
// If a job is not found in the runningJobMasterMap, wait for the restoration
// to complete before throwing JobNotFoundException. This prevents false negatives
// when workers report task status during the restore window.
if (runningJobMaster == null) {
logger.info(String.format(
"Job %s not found in runningJobMasterMap, waiting for restore completion",
taskGroupLocation.getJobId()));
restoreAllJobFromMasterNodeSwitchFuture.join();
runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
logger.info(String.format(
"Restore completed, job %s %s",
taskGroupLocation.getJobId(),
runningJobMaster != null ? "found" : "still not found"));
}
if (runningJobMaster == null) {
throw new JobNotFoundException(
String.format("Job %s not running", taskGroupLocation.getJobId()));
}
runningJobMaster.updateTaskExecutionState(taskExecutionState);
}
```
**Rationale**:
- Clear comments explain why waiting is necessary
- Logs can help diagnose status update behavior during master switch
- Facilitates performance analysis and troubleshooting
---
### Issue 3: Insufficient test coverage: Restore failure scenarios
**Location**: `CoordinatorServiceTest.java:472-562`
**Related context**:
- `testUpdateTaskExecutionStateWaitsForRestoreCompletion()` (lines 472-542)
- `testUpdateTaskExecutionStateThrowsWhenJobNotFound()` (lines 545-562)
**Issue description**:
Existing tests only cover restore success scenarios, but not restore failure scenarios. Specifically:
1. **Missing exceptional completion test**: No test for behavior when `restoreAllJobFromMasterNodeSwitchFuture` completes exceptionally
2. **Edge cases**: No test for scenario where restore completes but job is still not found (e.g., job was cancelled during restore)
3. **Concurrency scenarios**: No test for behavior when multiple threads call `updateTaskExecutionState()` simultaneously
**Potential risks**:
- **Risk 1**: The exception handling issue described in Issue 1 may not be discovered in tests and go directly to production
- **Risk 2**: Future code changes may break this fix, and tests won't detect it
**Impact scope**:
- **Direct impact**: Test coverage
- **Indirect impact**: Code quality assurance
- **Affected area**: `CoordinatorService.updateTaskExecutionState()` method
**Severity**: **MINOR**
**Improvement suggestion**:
```java
@Test
void testUpdateTaskExecutionStateWhenRestoreFailed() throws Exception {
JobInformation jobInformation =
submitJob(
"CoordinatorServiceTest_testUpdateTaskExecutionStateWhenRestoreFailed",
"batch_fake_to_console.conf",
"test_update_task_execution_state_when_restore_failed");
CoordinatorService coordinatorService = jobInformation.coordinatorService;
await().atMost(30000, TimeUnit.MILLISECONDS)
.untilAsserted(
() ->
Assertions.assertEquals(
JobStatus.RUNNING,
coordinatorService.getJobStatus(jobInformation.jobId)));
// Remove job from runningJobMasterMap to simulate master switch
Field mapField = CoordinatorService.class.getDeclaredField("runningJobMasterMap");
mapField.setAccessible(true);
@SuppressWarnings("unchecked")
Map<Long, JobMaster> runningJobMasterMap =
(Map<Long, JobMaster>) mapField.get(coordinatorService);
runningJobMasterMap.remove(jobInformation.jobId);
// Create a failed future to simulate restore failure
CompletableFuture<Void> failedFuture = new CompletableFuture<>();
failedFuture.completeExceptionally(new SeaTunnelEngineException("Restore failed"));
PassiveCompletableFuture<Void> failedPassiveFuture =
new PassiveCompletableFuture<>(failedFuture);
Field futureField =
CoordinatorService.class.getDeclaredField(
"restoreAllJobFromMasterNodeSwitchFuture");
futureField.setAccessible(true);
futureField.set(coordinatorService, failedPassiveFuture);
// Try to update task state
TaskGroupLocation fakeLocation = new TaskGroupLocation(jobInformation.jobId, 0, 0);
TaskExecutionState taskExecutionState =
new TaskExecutionState(fakeLocation, ExecutionState.FAILED);
// Should throw JobNotFoundException even when restore failed
Assertions.assertThrows(
JobNotFoundException.class,
() -> coordinatorService.updateTaskExecutionState(taskExecutionState));
jobInformation.coordinatorServiceTest.shutdown();
}
@Test
void testUpdateTaskExecutionStateWhenJobRemovedDuringRestore() throws Exception {
JobInformation jobInformation =
submitJob(
"CoordinatorServiceTest_testUpdateTaskExecutionStateWhenJobRemovedDuringRestore",
"batch_fake_to_console.conf",
"test_update_task_execution_state_job_removed_during_restore");
CoordinatorService coordinatorService = jobInformation.coordinatorService;
await().atMost(30000, TimeUnit.MILLISECONDS)
.untilAsserted(
() ->
Assertions.assertEquals(
JobStatus.RUNNING,
coordinatorService.getJobStatus(jobInformation.jobId)));
Field mapField = CoordinatorService.class.getDeclaredField("runningJobMasterMap");
mapField.setAccessible(true);
@SuppressWarnings("unchecked")
Map<Long, JobMaster> runningJobMasterMap =
(Map<Long, JobMaster>) mapField.get(coordinatorService);
// Remove job from map but don't add it back (simulating job cancellation during restore)
Long jobId = jobInformation.jobId;
runningJobMasterMap.remove(jobId);
// Create a future that completes but doesn't restore the job
CompletableFuture<Void> completedFuture = CompletableFuture.completedFuture(null);
PassiveCompletableFuture<Void> completedPassiveFuture =
new PassiveCompletableFuture<>(completedFuture);
Field futureField =
CoordinatorService.class.getDeclaredField(
"restoreAllJobFromMasterNodeSwitchFuture");
futureField.setAccessible(true);
futureField.set(coordinatorService, completedPassiveFuture);
// Try to update task state
TaskGroupLocation fakeLocation = new TaskGroupLocation(jobId, 0, 0);
TaskExecutionState taskExecutionState =
new TaskExecutionState(fakeLocation, ExecutionState.FAILED);
// Should throw JobNotFoundException
Assertions.assertThrows(
JobNotFoundException.class,
() -> coordinatorService.updateTaskExecutionState(taskExecutionState));
jobInformation.coordinatorServiceTest.shutdown();
}
```
**Rationale**:
- Cover restore failure scenarios, verify exception handling correctness
- Cover scenario where restore completes but job still doesn't exist
- Improve test coverage, prevent future regression
---
### Issue 4: Potential risk of Hazelcast Operation thread blocking
**Location**: `CoordinatorService.java:898-901`
```java
if (runningJobMaster == null) {
restoreAllJobFromMasterNodeSwitchFuture.join(); // Blocking in Hazelcast Operation thread
runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
}
```
**Related context**:
- `NotifyTaskStatusOperation.runInternal()` (lines 71-74): This method executes in Hazelcast's Operation thread
- `restoreAllRunningJobFromMasterNodeSwitch()` (lines 458-466): Restore process includes `Thread.sleep(1000)` loop waiting for worker registration
**Issue description**:
The `updateTaskExecutionState()` method is called through `NotifyTaskStatusOperation`, which executes in Hazelcast's Operation thread. When executing `restoreAllJobFromMasterNodeSwitchFuture.join()`, it blocks the Operation thread.
If the restore process takes a long time (e.g., waiting for worker registration), it will block Hazelcast's Operation thread, potentially affecting:
1. **Cluster communication**: Hazelcast's partition operations and RPC calls may be delayed
2. **Heartbeat detection**: If blocked for too long, nodes may be incorrectly determined as down
3. **Other operations**: Other Operations may be queued waiting
**Potential risks**:
- **Risk 1**: After master switch, if a large number of workers concurrently report status, multiple Operation threads may be blocked
- **Risk 2**: If restore process includes `Thread.sleep()` (lines 458-466), blocking time may reach several seconds or longer
- **Risk 3**: Hazelcast's Operation thread pool size is limited (default value is usually small), long blocking may cause thread pool exhaustion
**Impact scope**:
- **Direct impact**: Hazelcast cluster communication performance
- **Indirect impact**: Other operations depending on Hazelcast RPC
- **Affected area**: Communication stability of the entire cluster
**Severity**: **MAJOR** (depends on Hazelcast thread pool configuration and restore duration)
**Improvement suggestion**:
There are several possible optimization solutions, but all involve significant architectural changes:
**Solution A: Async processing (recommended for long-term optimization)**
```java
// In NotifyTaskStatusOperation
@Override
public void runInternal() throws Exception {
SeaTunnelServer server = getService();
// Use async processing to avoid blocking Operation thread
CompletableFuture.runAsync(() -> {
server.getCoordinatorService().updateTaskExecutionState(taskExecutionState);
}, server.getCoordinatorService().getExecutorService());
}
```
**Solution B: Check instead of wait (lighter-weight solution)**
```java
public void updateTaskExecutionState(TaskExecutionState taskExecutionState) {
logger.info(
String.format(
"Received task end from execution %s, state %s",
taskExecutionState.getTaskGroupLocation(),
taskExecutionState.getExecutionState()));
TaskGroupLocation taskGroupLocation = taskExecutionState.getTaskGroupLocation();
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
// Check if restore is still in progress
if (runningJobMaster == null &&
!restoreAllJobFromMasterNodeSwitchFuture.isDone()) {
// Restore still in progress, return early and let worker retry
// This is acceptable because worker already has retry logic
logger.info(String.format(
"Job %s not found and restore still in progress, worker will retry",
taskGroupLocation.getJobId()));
throw new JobNotFoundException(
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);
}
```
**Rationale**:
- **Solution A**: Transfer status updates to `CoordinatorService`'s thread pool, avoiding blocking Hazelcast Operation threads
- **Solution B**: Don't wait for restore completion, directly throw `JobNotFoundException`, let worker retry. This leverages existing retry logic and avoids blocking
**Trade-offs**:
- Solution A requires modifying `NotifyTaskStatusOperation`, with a larger impact surface
- Solution B may lead to more retries, but won't block Operation threads
- **The current PR chooses the waiting solution**, which is a simple fix, but requires evaluating whether the Hazelcast thread pool is large enough to handle potential blocking
---
### Issue 5: Jobs in PendingJobQueue state not considered
**Location**: `CoordinatorService.java:897-906`
```java
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
if (runningJobMaster == null) {
restoreAllJobFromMasterNodeSwitchFuture.join();
runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
}
```
**Related context**:
- `getJobMaster()` method (lines 392-398) checks both `pendingJobQueue` and `runningJobMasterMap`
- `pendingJobSchedule()` method (lines 250-328): Jobs are scheduled from pending queue to running map
**Issue description**:
When `runningJobMaster` is null, the code only waits for restore completion, then queries `runningJobMasterMap` again. However, it doesn't check `pendingJobQueue`.
Although under normal circumstances, the restore process will restore jobs to `pendingJobQueue` then schedule to `runningJobMasterMap`, theoretically the following timing exists:
1. Job is restored to `pendingJobQueue`
2. Worker calls `updateTaskExecutionState()`
3. At this time, `runningJobMasterMap` still doesn't have this job (because scheduling hasn't occurred yet)
4. `.join()` returns (because restore completed)
5. Second query of `runningJobMasterMap` is still null
6. Throw `JobNotFoundException`
**Potential risks**:
- **Risk 1**: Status updates will fail when restore completes but job hasn't been scheduled from pending queue to running map yet
- **Risk 2**: This time window is very short, but theoretically exists
**Impact scope**:
- **Direct impact**: Accuracy of `updateTaskExecutionState()` method
- **Indirect impact**: Reliability of job status updates
- **Affected area**: All jobs immediately restored after master switch
**Severity**: **MINOR** (because scheduling is usually fast after restore completes, and worker has retry mechanism)
**Improvement suggestion**:
```java
public void updateTaskExecutionState(TaskExecutionState taskExecutionState) {
logger.info(
String.format(
"Received task end from execution %s, state %s",
taskExecutionState.getTaskGroupLocation(),
taskExecutionState.getExecutionState()));
TaskGroupLocation taskGroupLocation = taskExecutionState.getTaskGroupLocation();
// Try to get job master from running map first
JobMaster runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
// If not found, check if restore is in progress or job is in pending queue
if (runningJobMaster == null) {
// Check if job is in pending queue
PendingJobInfo pendingJobInfo = pendingJobQueue.getById(taskGroupLocation.getJobId());
if (pendingJobInfo != null) {
// Job is in pending queue, use its job master
runningJobMaster = pendingJobInfo.getJobMaster();
} else {
// Not in pending queue, wait for restore to complete
restoreAllJobFromMasterNodeSwitchFuture.join();
runningJobMaster = runningJobMasterMap.get(taskGroupLocation.getJobId());
// Check again after restore
if (runningJobMaster == null) {
pendingJobInfo = pendingJobQueue.getById(taskGroupLocation.getJobId());
if (pendingJobInfo != null) {
runningJobMaster = pendingJobInfo.getJobMaster();
}
}
}
}
if (runningJobMaster == null) {
throw new JobNotFoundException(
String.format("Job %s not running", taskGroupLocation.getJobId()));
}
runningJobMaster.updateTaskExecutionState(taskExecutionState);
}
```
**Rationale**:
- Keep consistent with `getJobMaster()` method, check both `pendingJobQueue` and `runningJobMasterMap`
- Cover scenarios where jobs are in pending queue
- Avoid status update failure when restore completes but scheduling hasn't completed
**Trade-offs**:
- Increases code complexity
- Need to evaluate whether `JobMaster` obtained from `PendingJobInfo` can correctly handle `updateTaskExecutionState` calls
- Current `getJobMaster()` returns jobMaster in pendingJobInfo, indicating this is legitimate
---
--
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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#issuecomment-4889437640
> ```java
> try {
> invoke.get();
> notifyStateSuccess = true;
> } catch (InterruptedException e) {
> logger.severe("send notify task status failed", e);
> } catch (JobNotFoundException e) {
> logger.warning("send notify task status failed because can't find job", e);
> notifyStateSuccess = true;
> } 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));
> try {
> Thread.sleep(sleepTime);
> } catch (InterruptedException ex) {
> Thread.currentThread().interrupt();
> logger.severe(e);
> }
> } catch (ExecutionException e) {
> if (e.getCause() instanceof JobNotFoundException) {
> logger.warning("send notify task status failed because can't find job", e);
> notifyStateSuccess = true;
> } else {
> logger.warning(ExceptionUtils.getMessage(e));
> logger.warning(
> String.format(
> "notify the job of the task(%s) status failed, retry in %s millis",
> taskGroupLocation, sleepTime));
> try {
> Thread.sleep(sleepTime);
> } catch (InterruptedException ex) {
> Thread.currentThread().interrupt();
> logger.severe(e);
> }
> }
> }
> }
> ```
>
> I have concerns about the retry logic in the restore scenario here. I believe that users deployed on the k8s cluster will inevitably encounter cluster upgrades, and when the Seattunnel cluster restarts a large number of tasks for restore, it will consume a lot of Hazelcast thread resources. Therefore, I think a retry limit should be added in this scenario
The worker already has the same outer retry loop for generic notify failures before this patch. If there is a problem with this specific logic, it should be handled in a separate issue or 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] [Fix][Zeta] Fix JobNotFoundException in updateTaskExecutionState [seatunnel]
Posted by "DanielLeens (via GitHub)" <gi...@apache.org>.
DanielLeens commented on PR #10506:
URL: https://github.com/apache/seatunnel/pull/10506#issuecomment-4889546009
Thanks for clarifying that. On the unchanged current head, Daniel's source-side approval still stands for me.
I would keep the same boundary as before: the broader retry-cap discussion is a valid follow-up design topic, but I would not reopen this targeted restore-window fix on that point alone. If a new code revision lands, I can recheck it quickly.
--
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