LuckysHorizon commented on PR #13136:
URL: https://github.com/apache/seatunnel/pull/13136#issuecomment-7170842061

   > Thanks for working on this. I reviewed the latest head `718f00b8d260`.
   > 
   > # What this PR fixes
   > * User pain: after a same-ID savepoint restore, realtime observability 
kept reading the previous attempt's `engine.observability` settings from 
retained history, so `/metrics/realtime/jobs/<id>/edges` reported 
`enabled=false` with empty `edges` while `/job-info` showed `enabled=true` 
(#13130).
   > * Fix approach: reorder `CoordinatorService.getJobInfo()` to running 
JobMaster -> pending JobMaster -> distributed `JobInfo` in `runningJobInfoIMap` 
-> finished history. `jobHistoryService.getJobDAGInfo(jobId)` moves from the 
first branch to the last fallback. The PR adds a doc note (en/zh), unit tests 
in `CoordinatorServiceTest` and one restore IT.
   > * One-line summary: the reorder fixes the restore case, but it is 
unconditional. A finished job's `runningJobInfoIMap` entry is retained for 
`state-cleanup-delay-ms` (default 60000) after `JobMaster.cleanJob()` archives 
the DAG, so during that window every finished job now gets a rebuilt DAG with 
an empty execution-address history instead of its archived one. The submit path 
already tells attempts apart with `pendingJobCleanupIMap` and 
`isCleanupOwnedByCurrentJob`, and the same check can gate this branch.
   > 
   > # Runtime chain I rechecked
   > ```
   > Changed lookup (shared by three callers)
   > Callers: RealtimeMetricsService.resolveObservabilityConfig 
(RealtimeMetricsService.java:314), GetJobInfoOperation 
(GetJobInfoOperation.java:55), BaseService.getRunningJobDAGInfo 
(BaseService.java:511)
   > CoordinatorService.getJobInfo(jobId)  CoordinatorService.java:1910
   >   -> runningJobMasterMap.get(jobId) -> JobMaster.getJobDAGInfo()  
CoordinatorService.java:1915-1917 (cached DAG built with 
historyExecutionAddress, JobMaster.java:931-952)
   >   -> pendingJobQueue.getById(jobId) -> getJobMaster().getJobDAGInfo()  
CoordinatorService.java:1920-1922
   >   -> runningJobInfoIMap.get(jobId) -> restoreJobDAGInfo(runningJobInfo)  
CoordinatorService.java:1925-1927
   >        -> restoreJobImmutableInformation() (deserialize)  
CoordinatorService.java:1961-1963
   >        -> DAGUtils.restoreLogicalDag() + DAGUtils.getJobDAGInfo(..., 
master address, new HashSet<>())  CoordinatorService.java:1943-1959 (rebuilt on 
every call, not cached)
   >   -> jobHistoryService.getJobDAGInfo(jobId)  CoordinatorService.java:1930 
(finishedJobDAGInfoImap, TTL history-job-expire-minutes)
   >   -> JobNotFoundException  CoordinatorService.java:1935
   > 
   > Terminal path that creates the overlap
   > JobMaster.cleanJob()  JobMaster.java:1041-1046
   >   -> jobHistoryService.storeJobInfo(jobId, getJobDAGInfo())  (archives the 
DAG, JobHistoryService.java:344)
   >   -> scheduleRemoveJobStateMaps()  JobMaster.java:900-913 -> 
CoordinatorService.schedulePendingJobCleanup()  CoordinatorService.java:855
   >   -> processPendingJobCleanup()  CoordinatorService.java:885-926 (removes 
the runningJobInfoIMap entry only after state-cleanup-delay-ms, default 60000)
   >   => until that cleanup runs, history and runningJobInfoIMap both describe 
the same finished attempt, and the new order returns the rebuilt DAG.
   > 
   > Restore path (the case the PR targets)
   > submitJob: pendingJobCleanupIMap.get(jobId) + isCleanupOwnedByCurrentJob() 
 CoordinatorService.java:1428-1442 (existing attempt-ownership check)
   >   -> runningJobInfoIMap.put(jobId, new JobInfo(initializationTimestamp, 
...))  CoordinatorService.java:1466-1469 (new attempt, while history still 
holds the previous one)
   > ```
   > 
   > # Findings
   > **Issue 1: The reorder is unconditional: `getJobInfo()` cannot tell a 
restored attempt's `JobInfo` from the retained `JobInfo` of an attempt that has 
already finished, so the finished attempt's distributed entry now shadows its 
own archived history. The branch needs an attempt-ownership check.**
   > 
   > * Location: 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1930`
   > * Why it matters: - Root cause: the history lookup moved below the 
distributed branch. A job with no running or pending `JobMaster` but an entry 
in `runningJobInfoIMap` now always goes through 
`restoreJobDAGInfo(runningJobInfo)`.
   > * That state is normal after every terminal job, not only during a 
restore. `JobMaster.cleanJob()` archives the DAG with 
`jobHistoryService.storeJobInfo(...)` and then only schedules the map cleanup. 
`processPendingJobCleanup` removes the `runningJobInfoIMap` entry 
`state-cleanup-delay-ms` later (default `60000`).
   > * The reorder is only correct when the distributed `JobInfo` belongs to a 
newer attempt than history. For the retained entry of a finished attempt, 
history is the authoritative record and is now skipped.
   > * Added cost: `restoreJobDAGInfo` deserializes `JobImmutableInformation` 
and rebuilds the logical DAG on every call, with no caching. 
`RealtimeMetricsService.collectOnce()` resolves the config for every key in 
`IMAP_RUNNING_JOB_INFO` on each cycle, so each retained finished job now pays 
that rebuild per poll where it used to be one history map read.
   > * Suggested fix: reuse the check the submit path already has. If 
`pendingJobCleanupIMap.get(jobId)` returns a record and 
`isCleanupOwnedByCurrentJob(runningJobInfo, jobId, record)` is true, the 
`JobInfo` is the finished attempt: return history first and fall back to 
`restoreJobDAGInfo` only when history is null. Otherwise keep the new order.
   > * The user-visible symptom and the inaccurate code comment are described 
in the comment on line 1913. One change resolves both.
   > * Evidence: 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1930
  JobDAGInfo jobInfo = jobHistoryService.getJobDAGInfo(jobId);`; 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1912
  // running/pending JobMaster and distributed JobInfo take precedence. 
Distributed metadata`; 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1931
  if (jobInfo != null) {`
   > * Suggested fix: Moving history below the `runningJobInfoIMap` branch is 
only right when the distributed `JobInfo` is a newer attempt than history. 
After any terminal state, `JobMaster.cleanJob()` archives the DAG and merely 
schedules the `JobInfo` removal (`state-cleanup-delay-ms`, default 60000). For 
that window we now return `restoreJobDAGInfo()` instead of the archived DAG, 
and we rebuild it on every call, including every realtime-metrics poll, since 
`RealtimeMetricsService` iterates all keys of `IMAP_RUNNING_JOB_INFO`.
   > 
   > The submit path already distinguishes the two cases with 
`pendingJobCleanupIMap.get(jobId)` and `isCleanupOwnedByCurrentJob(...)` (same 
initialization timestamp, end state). Could we use the same check here? If the 
cleanup record owns this `JobInfo`, read history first and only fall back to 
`restoreJobDAGInfo()` when history is null; otherwise keep the new order. That 
keeps the restore fix and leaves finished jobs on their archived DAG.
   > 
   > * Priority: P0 — must fix before merge
   > * I traced this in the code.
   > * When it happens: Finish any batch job with default 
`state-cleanup-delay-ms`. For the next 60 s every `getJobInfo(jobId)` call 
(client, REST, or the 5 s realtime collector) rebuilds the DAG from the 
retained `JobInfo` instead of reading that same attempt's archived history.
   > 
   > **Issue 2: For every finished job, `getJobInfo()` now returns a 
reconstructed DAG with an empty execution-address history and the current 
master address during the `state-cleanup-delay-ms` window, and the new code 
comment wrongly describes that DAG as equivalent to history.**
   > 
   > * Location: 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1913`
   > * Why it matters: - This is the visible effect of the unconditional 
reorder described in the comment on line 1930. It is the same root cause, and 
one fix resolves both.
   > * Once a job ends, its `JobMaster` leaves `runningJobMasterMap`, but the 
`runningJobInfoIMap` entry stays until `processPendingJobCleanup` runs, 
`state-cleanup-delay-ms` later (default `60000`). In that window the new order 
reaches `restoreJobDAGInfo(runningJobInfo)` before history.
   > * `restoreJobDAGInfo` calls `DAGUtils.getJobDAGInfo(...)` with `new 
HashSet<>()` for the execution addresses and `nodeEngine.getMasterAddress()` as 
master. The archived DAG stored by `JobMaster.cleanJob()` was built from the 
JobMaster's real `historyExecutionAddress` set and its own address.
   > * So the new comment's claim that the retained metadata "describes the 
same attempt as history" is true for the attempt but not for the returned 
object. The PR description's Notes section says the same: the reconstructed DAG 
has "the current master address and an empty `historyExecutionPlan`".
   > * Impact: the client job-info call (`GetJobInfoOperation`) and the REST 
job-info DAG (`BaseService.getRunningJobDAGInfo`) return the degraded DAG for 
about a minute after each job finishes, then switch back to the archived one. 
Before this PR they returned the archived DAG as soon as it was stored.
   > * Fix: return history for a retained finished attempt as proposed on line 
1930, and update this comment to state the actual rule.
   > * Evidence: 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1913
  // can briefly outlive a finished job and then describes the same attempt as 
history;`; 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1930
  JobDAGInfo jobInfo = jobHistoryService.getJobDAGInfo(jobId);`; 
`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java:1914
  // history is the fallback when no current attempt exists.`
   > * Suggested fix: This comment says the retained distributed metadata 
"describes the same attempt as history", but the two DAGs are not equivalent. 
`restoreJobDAGInfo()` passes `new HashSet<>()` for the execution addresses and 
`nodeEngine.getMasterAddress()` for master, while the DAG archived by 
`JobMaster.cleanJob()` carries the real `historyExecutionAddress` set.
   > 
   > Because the `runningJobInfoIMap` entry outlives the JobMaster by 
`state-cleanup-delay-ms` (default 60000), every finished job now reports an 
empty execution history through the client job-info call and the REST job-info 
DAG for that window, then flips back to the archived DAG. Before this change 
those callers got the archived DAG as soon as it was stored.
   > 
   > Same root cause as my comment on line 1930. Once that branch prefers 
history for a retained finished attempt, please reword this comment to describe 
the ownership rule.
   > 
   > * Priority: P0 — must fix before merge
   > * I traced this in the code.
   > * When it happens: Default config (`state-cleanup-delay-ms: 60000`), one 
worker, batch FakeSource -> Console job. After the job reaches FINISHED, call 
`SeaTunnelClient.getJobInfo(jobId)` within 60 s: `historyExecutionPlan` is 
empty, although `finishedJobDAGInfoImap` holds the DAG with the worker address. 
After cleanup fires, the same call returns the archived DAG with the address 
again. The merge base returns the address both times.
   > 
   > **Issue 3: The new doc note does not name the settings that follow the 
current attempt and does not say that changing `bucket_ms` or 
`retention_minutes` on restore restarts the in-memory realtime window. Whether 
the client-visible `getJobInfo()` change needs documenting depends on how the 
line 1930 concern is resolved.**
   > 
   > * Location: `docs/en/engines/zeta/realtime-observability.md:36`
   > * Why it matters: - The added paragraph (en line 36, zh line 36) says 
realtime observability "uses the current attempt's configuration" without 
naming `enabled`, `bucket_ms` and `retention_minutes`. The PR description names 
all three.
   > * `RealtimeMetricsService.collectOnce()` creates a new `JobStore` whenever 
the stored `bucketMs` or `retentionMinutes` differs from the resolved config. A 
restore that changes either value therefore drops the points collected so far. 
Users comparing before and after a restore will notice this, and the note does 
not mention it.
   > * Conditional point: the PR description's Notes section says 
`getJobInfo()` returns a DAG with the current master address and an empty 
`historyExecutionPlan` while distributed metadata outlives a finished job. If 
that behaviour is kept, it is a client-visible change. It belongs in 
`docs/en/introduction/concepts/incompatible-changes.md` and in the PR 
checklist, which currently says "No incompatible changes". It does not belong 
in this observability page.
   > * If the lookup is changed so retained finished attempts still come from 
history, that behaviour disappears and no extra documentation is needed.
   > * Evidence: `docs/en/engines/zeta/realtime-observability.md:37  current 
attempt's configuration. Retained history from the previous attempt does not 
override the`; `docs/zh/engines/zeta/realtime-observability.md:36  使用相同作业 ID 从 
savepoint 恢复作业时,实时可观测性使用当前执行尝试的配置。`
   > * Suggested fix: Two requests on this note (please mirror them in the zh 
page):
   > 
   > 1. Name the settings that follow the current attempt (`enabled`, 
`bucket_ms`, `retention_minutes`), and mention that changing `bucket_ms` or 
`retention_minutes` on restore restarts the in-memory realtime window. 
`RealtimeMetricsService.collectOnce()` creates a new `JobStore` when either 
value differs, so the earlier points are dropped.
   > 2. This one depends on the outcome of my comment on 
`CoordinatorService.java` line 1930. If finished jobs keep returning the 
reconstructed DAG (current master, empty `historyExecutionPlan`) during 
`state-cleanup-delay-ms`, that is a client-visible change to `getJobInfo()`. It 
should be recorded in `incompatible-changes.md` and the checklist item updated, 
not added to this page. If that branch is changed to prefer history for a 
finished attempt, nothing more is needed here.
   > 
   > * Priority: P2 — optional
   > * I traced this in the code.
   > * When it happens: Read the added paragraph: it mentions neither the empty 
`historyExecutionPlan` returned by `SeaTunnelClient.getJobInfo()` for about 60 
s after a job ends, nor that restoring with a different `bucket_ms` discards 
the existing realtime window.
   > 
   > **Issue 4: 
`testGetJobInfoReturnsHistoryWhenDistributedAndCurrentAttemptsMatch` does not 
test what its name says: it passes whichever source `getJobInfo()` picks and 
never checks which DAG was returned.**
   > 
   > * Location: 
`seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/CoordinatorServiceTest.java:1607`
   > * Why it matters: - The test removes the job from the pending queue and 
`runningJobMasterMap`, then calls `getJobInfo(jobId)`. With the 
`runningJobInfoIMap` entry present, that call already takes the distributed 
branch.
   > * It then stubs the history mock to return that same object and calls 
`getJobInfo(jobId)` again.
   > * The assertions compare only `isEnabled()`, `getBucketMs()` and 
`getRetentionMinutes()` between the two results. Those values are identical by 
construction, whichever branch answered the second call.
   > * The name says history is returned. On this head, as long as the 
`runningJobInfoIMap` entry is still there, the distributed rebuild answers and 
the mocked history is never read. Nothing in the test would notice either way.
   > * Impact: the test gives no signal about precedence between retained 
distributed metadata and history for the same attempt, which is the case 
discussed on `CoordinatorService.java` line 1930.
   > * Suggested change: make the two sources distinguishable. Stub history 
with a separate `JobDAGInfo` instance and assert identity on the result 
(`assertSame` or `assertNotSame`), so the test fails when the precedence it 
documents changes. If the lookup gains an ownership check, this is where to pin 
the "finished attempt reads history" case. Otherwise rename the test to say it 
only checks that the observability values agree.
   > * Evidence: 
`seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/CoordinatorServiceTest.java:1607
  
Mockito.when(jobHistoryService.getJobDAGInfo(jobId)).thenReturn(distributedJobDAGInfo);`;
 
`seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/CoordinatorServiceTest.java:1604
  JobDAGInfo distributedJobDAGInfo = coordinatorService.getJobInfo(jobId);`; 
`seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/CoordinatorServiceTest.java:1614
  Assertions.assertEquals(distributedConfig.isEnabled(), 
resolvedConfig.isEnabled());`
   > * Suggested fix: History is stubbed here with the DAG the distributed path 
just returned, and the assertions below compare only the three observability 
values. So this test passes whether `getJobInfo()` reads history or 
`runningJobInfoIMap`. While the `runningJobInfoIMap` entry is present, the 
current code returns the reconstructed DAG, which does not match the 
`ReturnsHistory...` name.
   > 
   > Could we make the two sources distinguishable? Stub history with its own 
`JobDAGInfo` instance and assert identity on the result (`assertSame` / 
`assertNotSame`). If the lookup gets an attempt-ownership check as suggested on 
`CoordinatorService.java` line 1930, this test is the natural place to pin "a 
retained finished attempt reads history". Otherwise please rename it to reflect 
that it only checks the config values agree.
   > 
   > * Priority: P2 — optional
   > * I traced this in the code.
   > * When it happens: Move the history lookup back above the 
`runningJobInfoIMap` branch in `CoordinatorService.getJobInfo()`, or leave it 
where it is: the three assertions at :1614-1617 hold in both cases.
   > 
   > **Issue 5: The restore IT cannot fail on the bug it is named after: in the 
e2e configuration the archived attempt-1 DAG expires after one minute, inside 
the two-minute await windows, so the old history-first order also ends up 
reading the running JobMaster.**
   > 
   > * Location: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:282`
   > * Why it matters: - 
`testRestoreUsesCurrentRealtimeObservabilityConfiguration` runs with the e2e 
`seatunnel.yaml`, which sets `history-job-expire-minutes: 1`. 
`JobHistoryService.storeJobInfo` writes the archived DAG with that TTL.
   > * Every post-restore assertion polls with `Awaitility.await().atMost(2, 
TimeUnit.MINUTES)`.
   > * Under the old history-first order, the stale attempt-1 DAG 
(`enabled=false`, `bucket_ms=1000`) is returned only until it expires. The 
lookup then falls through to the running JobMaster, and the assertions on 
`enabled=true` and `bucketMs=2000` succeed within the await window.
   > * This matches the PR description, which says the IT also passes under the 
previous ordering.
   > * Asserting the pre-restore state (attempt 1 reports `enabled=false`, an 
archived DAG exists) would make the precondition explicit. It would hold under 
both orderings, though, so on its own it does not turn the IT into a regression 
test.
   > * Suggested change: make the archived DAG outlive the assertions. For 
example, call `config.getEngineConfig().setHistoryJobExpireMinutes(...)` in 
`beforeEach` before the node is created, with a value longer than the test's 
total await budget. Alternatively, bound the first post-restore check on 
`/metrics/realtime/jobs` to well under the one-minute TTL. Either way the IT 
fails with history-first lookup and passes with this change.
   > * Evidence: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:292
  .restoreExecutionContext(`
   > * Suggested fix: As the description notes, this IT also passes with the 
old history-first order. The reason is timing rather than missing assertions. 
The e2e `seatunnel.yaml` sets `history-job-expire-minutes: 1`, and the 
post-restore checks poll for up to 2 minutes. The attempt-1 DAG archived at 
`SAVEPOINT_DONE` therefore expires inside the await window, and the old lookup 
then falls through to the running JobMaster.
   > 
   > Could we make the archived DAG outlive the assertions? For example, call 
`config.getEngineConfig().setHistoryJobExpireMinutes(...)` in `beforeEach` 
(before `createHazelcastInstance`) with a value longer than the awaits, or cap 
the first `/metrics/realtime/jobs` check well below one minute. With that, the 
test fails under history-first and guards #13130.
   > 
   > Asserting after `SAVEPOINT_DONE` that the archived DAG exists with 
`enabled=false` would be a nice explicit precondition, but it holds under both 
orderings, so it is not enough on its own.
   > 
   > * Priority: P2 — optional
   > * I traced this in the code.
   > * When it happens: Read the test body in `RealtimeMetricsRestIT.java` 
(diff lines +246 to +372): between `savePointJob(jobId)` and 
`restoreExecutionContext(...)` there is only the SAVEPOINT_DONE status wait; 
there is no assertion on attempt-1 metrics state or history.
   > 
   > **Issue 6: `awaitAllTasksReady` reads `CheckpointManager.coordinatorMap` 
through reflection by field name although 
`CheckpointManager.getCheckpointCoordinator(pipelineId)` is public and already 
used by other ITs. The IT's missing regression coverage is covered in the 
comment on line 282.**
   > 
   > * Location: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:453`
   > * Why it matters: - `awaitAllTasksReady` reads the private field 
`coordinatorMap` with `ReflectionUtils.getField(checkpointManager, 
"coordinatorMap")` and then the private `isAllTaskReady` flag of each 
coordinator.
   > * A rename of either field is not caught at compile time. The IT fails 
only at runtime, on an empty `Optional`.
   > * For the map lookup, reflection is avoidable. 
`CheckpointManager.getCheckpointCoordinator(int pipelineId)` is public and is 
used by `CheckpointCoordinatorFailoverIT`, `SavepointPreconditionRecoveryIT` 
and `SplitClusterWorkerRestartAfterFinalCheckpointIT`. Pipeline IDs are 
available from `jobMaster.getPhysicalPlan().getPipelineList()`.
   > * `isAllTaskReady` has no public accessor, so that single reflective read 
has to stay. Its diagnostics are covered in the comment on line 459.
   > * The test declared on line 250 is, by the PR description's own account, 
restore smoke coverage and not a regression test. The cause and a fix are in 
the comment on line 282, so I am not repeating them here.
   > * Evidence: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:453
  ReflectionUtils.getField(checkpointManager, "coordinatorMap")`; 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:469
  "isAllTaskReady")`
   > * Suggested fix: Reading `coordinatorMap` by field name only fails at 
runtime if the field is renamed. 
`CheckpointManager.getCheckpointCoordinator(pipelineId)` is public and other 
ITs in this package already use it, so this lookup can drop reflection: iterate 
`jobMaster.getPhysicalPlan().getPipelineList()` and fetch each coordinator by 
`getPipelineId()`. That leaves `isAllTaskReady` as the only reflective read 
(see my note on line 459).
   > * Priority: P2 — optional
   > * I traced this in the code.
   > * When it happens: Rename `CheckpointManager.coordinatorMap` (for example 
to `coordinators`). The e2e module still compiles. 
`testRestoreUsesCurrentRealtimeObservabilityConfiguration` then fails in 
`awaitAllTasksReady` with `NoSuchElementException: No value present` from line 
459, because `ReflectionUtils.getField(checkpointManager, "coordinatorMap")` 
returns an empty `Optional`. Separately, by the author's statement, reverting 
`CoordinatorService.getJobInfo` to history-first leaves this IT green.
   > 
   > **Issue 7: `awaitAllTasksReady` uses bare `orElseThrow()` on its 
reflective reads, so a renamed field surfaces as an uninformative 
`NoSuchElementException`. `SavepointPreconditionRecoveryIT` already has an 
`isAllTaskReady(CheckpointCoordinator)` helper with a descriptive assertion.**
   > 
   > * Location: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:459`
   > * Why it matters: - The new helper reads 
`CheckpointManager.coordinatorMap` and `CheckpointCoordinator.isAllTaskReady` 
through `ReflectionUtils.getField(...)` and ends both chains with a bare 
`.orElseThrow()`. The second read is followed by an unchecked `(AtomicBoolean)` 
cast.
   > * `SavepointPreconditionRecoveryIT` in the same package already has a 
private `isAllTaskReady(CheckpointCoordinator)` helper. It asserts the field's 
presence and type with the message "CheckpointCoordinator.isAllTaskReady field 
not found via reflection; it may have been renamed".
   > * Impact: if either private field is renamed or changes type, this IT 
reports `NoSuchElementException: No value present` or a `ClassCastException`, 
with no hint that the reflective lookup is the cause. This affects test 
diagnostics only, not production behaviour.
   > * Suggested change: move the existing helper to a shared test utility and 
reuse it here, or pass a supplier, for example `.orElseThrow(() -> new 
AssertionError("CheckpointCoordinator.isAllTaskReady not found via reflection; 
it may have been renamed"))`.
   > * Evidence: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:459
  .orElseThrow();`; 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:470
  .orElseThrow();`
   > * Suggested fix: Nit: a bare `orElseThrow()` here (and at line 470) means 
a rename of `coordinatorMap` or `isAllTaskReady` shows up as 
`NoSuchElementException: No value present` with no hint at the cause. 
`SavepointPreconditionRecoveryIT` in this package already has an 
`isAllTaskReady(CheckpointCoordinator)` helper that asserts the field with a 
descriptive message. Could we move that helper somewhere shared and reuse it, 
or at least throw with a message, e.g. `.orElseThrow(() -> new 
AssertionError("... not found via reflection; it may have been renamed"))`?
   > * Priority: P2 — optional
   > * I traced this in the code.
   > * When it happens: Rename `CheckpointCoordinator.isAllTaskReady` (for 
example to `allTaskReady`). `SavepointPreconditionRecoveryIT` fails with an 
assertion message that names the renamed field. 
`RealtimeMetricsRestIT.testRestoreUsesCurrentRealtimeObservabilityConfiguration`
 fails with `java.util.NoSuchElementException: No value present` thrown from 
line 470, with no hint of which field is missing.
   > 
   > **Issue 8: The restore IT never cancels the jobs it starts and creates its 
temp files outside the `try`; teardown relies entirely on `node.shutdown()` in 
`afterEach`.**
   > 
   > * Location: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:372`
   > * Why it matters: - Both temp files are created and written before the 
`try` block, and the `finally` only deletes the two files.
   > * If the second `createTempFile` or either `Files.writeString` throws, the 
file or files already created are left behind.
   > * The restored streaming job (`row.num = 10000000`, `write_delay_ms = 2`) 
is never cancelled. Neither is the initial job if an await fails before the 
savepoint completes.
   > * Impact: the test outcome is unaffected today, because `afterEach` closes 
the client and shuts the node down. Jobs are still running at that point, which 
makes teardown noisier, especially when an assertion has already failed.
   > * Suggested change: move the temp-file creation inside the `try` 
(null-check in `finally`), and add a best-effort `cancelJob()` for the job that 
is still running before deleting the files.
   > * Evidence: 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:372
  Files.deleteIfExists(disabledConfig);`; 
`seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/RealtimeMetricsRestIT.java:373
  Files.deleteIfExists(enabledConfig);`
   > * Suggested fix: Nit: this `finally` only deletes the config files. The 
restored streaming job (10M rows) is left running until `node.shutdown()` in 
`afterEach`, and so is the initial job if an await fails before the savepoint.
   > 
   > A best-effort `cancelJob()` here would keep teardown quiet when an 
assertion fails. The two `createTempFile`/`writeString` calls also sit outside 
the `try`, so a failure there leaves the already-created file behind; moving 
them inside the `try` covers that.
   > 
   > * Priority: P2 — optional
   > * I traced this in the code.
   > * When it happens: Run 
`testRestoreUsesCurrentRealtimeObservabilityConfiguration` to completion. At 
method exit the restored job is still RUNNING, since the method only awaits 
RUNNING at `:295-300` and never calls `cancelJob`. It is torn down only by 
`node.shutdown()` in `afterEach`. Alternatively, make 
`Files.writeString(enabledConfig, ...)` at `:262` throw an `IOException`: both 
temp files stay in the temp directory because the `try/finally` has not started.
   > 
   > # On points raised earlier in this thread
   > * This looks addressed at the current head: At this head the 
distributed-vs-history unit test can detect a precedence regression. 
`testGetJobInfoPrefersDistributedJobInfoOverFinishedHistory` seeds a real 
serialized `JobInfo` with `enabled=true`, `bucket_ms=2000` and a history mock 
with `enabled=false`, `bucket_ms=1000`, then asserts the resolved config is 
enabled with 2000. A history-first order would return the mock and fail the 
assertion. A different test, 
`testGetJobInfoReturnsHistoryWhenDistributedAndCurrentAttemptsMatch`, still has 
no such power (PR13136-F5).
   > * I read this differently: The sub-claim that the reworked distributed 
test fails under history-first is correct (lines 1576 and 1584), and CI is now 
green on this head. The conclusion that CI is the only thing left is wrong: the 
production reorder makes `getJobInfo()` return a rebuilt DAG with an empty 
`historyExecutionPlan` for every finished job during `state-cleanup-delay-ms`, 
and no test covers that state with a non-zero delay.
   > * I read this differently: The precedence at 
`CoordinatorService.java:1910-1936` is not correct for terminal jobs. The 
retained distributed `JobInfo` of a finished attempt beats that attempt's own 
archived history, so client and REST callers lose `historyExecutionPlan` for 
the cleanup-delay window and the realtime collector rebuilds the DAG on every 
poll. That is a non-CI blocker. The CI statements about the fork cannot be 
checked here; CI is reported green on this head.
   > * I read this differently: The green Build matches the CI status supplied 
for this head, but it only shows that the code compiles and existing tests 
pass. The approval conclusion that no blockers remain is wrong. The reorder 
regresses `getJobInfo()` for finished jobs while their `JobInfo` is retained 
(default 60 s). The cited regression test (lines 1511-1590) covers only the 
differing-attempt case with a mocked history; it never checks worker addresses 
for a same-attempt terminal job. Server tests run with `state-cleanup-delay-ms: 
0`, so CI cannot see the window.
   > * +1 — I checked this independently: The reported behaviour follows 
necessarily from the code at this head: during the cleanup-delay window the 
client gets a rebuilt DAG with an empty worker set, while the merge base 
returned the archived DAG. The proposed local fix is feasible. 
`resolveObservabilityConfig()` already reads the current attempt's `JobInfo` 
(RealtimeMetricsService.java:304-309), and 
`JobImmutableInformation.getJobConfig().getEnvOptions()` is readable after a 
plain `toObject` without plugin class loaders, as CoordinatorService.java:1962 
and :1995 already do.
   > 
   > # Review conclusion
   > ### Conclusion: can merge after the blocking items are fixed
   > **1. Blocking items**
   > 
   > * Issue 1: The reorder is unconditional: `getJobInfo()` cannot tell a 
restored attempt's `JobInfo` from the retained `JobInfo` of an attempt that has 
already finished, so the finished attempt's distributed entry now shadows its 
own archived history. The branch needs an attempt-ownership check.
   > * Issue 2: For every finished job, `getJobInfo()` now returns a 
reconstructed DAG with an empty execution-address history and the current 
master address during the `state-cleanup-delay-ms` window, and the new code 
comment wrongly describes that DAG as equivalent to history.
   > 
   > **2. Remaining follow-ups**
   > 
   > * Issue 3: The new doc note does not name the settings that follow the 
current attempt and does not say that changing `bucket_ms` or 
`retention_minutes` on restore restarts the in-memory realtime window. Whether 
the client-visible `getJobInfo()` change needs documenting depends on how the 
line 1930 concern is resolved.
   > * Issue 4: 
`testGetJobInfoReturnsHistoryWhenDistributedAndCurrentAttemptsMatch` does not 
test what its name says: it passes whichever source `getJobInfo()` picks and 
never checks which DAG was returned.
   > * Issue 5: The restore IT cannot fail on the bug it is named after: in the 
e2e configuration the archived attempt-1 DAG expires after one minute, inside 
the two-minute await windows, so the old history-first order also ends up 
reading the running JobMaster.
   > * Issue 6: `awaitAllTasksReady` reads `CheckpointManager.coordinatorMap` 
through reflection by field name although 
`CheckpointManager.getCheckpointCoordinator(pipelineId)` is public and already 
used by other ITs. The IT's missing regression coverage is covered in the 
comment on line 282.
   > * Issue 7: `awaitAllTasksReady` uses bare `orElseThrow()` on its 
reflective reads, so a renamed field surfaces as an uninformative 
`NoSuchElementException`. `SavepointPreconditionRecoveryIT` already has an 
`isAllTaskReady(CheckpointCoordinator)` helper with a descriptive assertion.
   > * Issue 8: The restore IT never cancels the jobs it starts and creates its 
temp files outside the `try`; teardown relies entirely on `node.shutdown()` in 
`afterEach`.
   > 
   > Thanks for the updates so far. Happy to discuss the remaining points.
   
   Thanks @SEZ9 for the detailed review. I pushed a rework (head 2801b15). 
Issues 1, 2 and 4 are moot after the revert; 3 and 5-8 are addressed.
   
   - **Issues 1 and 2:** I reverted the `getJobInfo()` reorder, and 
`CoordinatorService.java` now has no diff against the base. Finished jobs 
return their archived DAG during `state-cleanup-delay-ms`, and the misleading 
comment is gone with the code. The #13130 fix now lives in 
`RealtimeMetricsService.resolveObservabilityConfig()` and reads the current 
attempt's `JobInfo`.
   - **Issue 3:** both docs name `enabled`, `bucket_ms` and 
`retention_minutes`, and say that changing `bucket_ms` or `retention_minutes` 
on restore restarts the in-memory window. There is no client-visible change, so 
`incompatible-changes.md` is untouched.
   - **Issue 4:** I removed the reorder-only tests, including 
`testGetJobInfoReturnsHistoryWhenDistributedAndCurrentAttemptsMatch`, which 
could not tell the two sources apart. The precedence is now covered by 
`RealtimeMetricsServiceTest`, where the current attempt must beat conflicting 
history.
   - **Issue 5:** the IT raises history retention above its await budget and 
asserts the attempt-1 history entry still exists before it checks 
`enabled=true` and `bucketMs=2000`. Reverting the fix makes it fail.
   - **Issues 6-8:** the IT uses the public 
`getCheckpointCoordinator(pipelineId)`. The remaining reflective 
`isAllTaskReady` read throws a descriptive `AssertionError`. Temp files are 
created inside the `try`, and running jobs are cancelled best-effort in 
`finally`.
   
   Local results are in the PR description. The apache-side Build still needs 
workflow approval. Please re-review when you can. #13133 overlaps on the lookup 
fix, so the maintainers can decide which one 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to