Repository navigation
fix(amber): order worker state by version, not timestamp - #6011
Conversation
Worker state was reconciled at the controller by last-nanoTime-wins. A fast source's startWorker response carries a stale RUNNING snapshot that can arrive after COMPLETED was recorded, clobbering it and leaving the operator stuck orange. Order state causally instead: WorkerStateManager now stamps every transition with a monotonic per-worker version, carried on all state reports (WorkerStateResponse, WorkerStateUpdatedRequest, WorkerMetrics). The controller applies a state only if its version is newer, and treats COMPLETED/TERMINATED as absorbing. Stats keep timestamp ordering. Closes apache#6010
Automated Reviewer SuggestionsBased on the
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6011 +/- ##
============================================
- Coverage 76.84% 75.19% -1.66%
- Complexity 3497 3525 +28
============================================
Files 1161 777 -384
Lines 45922 21438 -24484
Branches 5101 2014 -3087
============================================
- Hits 35290 16120 -19170
+ Misses 9067 4446 -4621
+ Partials 1565 872 -693
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
| config | throughput | MB/s | latency | max Δ latest / 7d | |
|---|---|---|---|---|---|
| 🔴 | bs=10 sw=10 sl=64 | 378 | 0.231 | 25,354/32,965/32,965 us | 🟢 -7.6% / 🔴 +98.7% |
| ⚪ | bs=100 sw=10 sl=64 | 795 | 0.485 | 123,621/145,785/145,785 us | ⚪ within ±5% / 🔴 +33.6% |
| ⚪ | bs=1000 sw=10 sl=64 | 913 | 0.558 | 1,089,518/1,190,528/1,190,528 us | ⚪ within ±5% / 🔴 +13.8% |
Baseline details
Latest main 053d8fb from same runner
| config | metric | PR | latest main | 7d avg | Δ latest | Δ 7d |
|---|---|---|---|---|---|---|
| bs=10 sw=10 sl=64 | throughput | 378 tuples/sec | 393 tuples/sec | 754.55 tuples/sec | -3.8% | -49.9% |
| bs=10 sw=10 sl=64 | MB/s | 0.231 MB/s | 0.24 MB/s | 0.461 MB/s | -3.7% | -49.8% |
| bs=10 sw=10 sl=64 | p50 | 25,354 us | 24,039 us | 12,816 us | +5.5% | +97.8% |
| bs=10 sw=10 sl=64 | p95 | 32,965 us | 35,659 us | 16,594 us | -7.6% | +98.7% |
| bs=10 sw=10 sl=64 | p99 | 32,965 us | 35,659 us | 19,806 us | -7.6% | +66.4% |
| bs=100 sw=10 sl=64 | throughput | 795 tuples/sec | 815 tuples/sec | 969.38 tuples/sec | -2.5% | -18.0% |
| bs=100 sw=10 sl=64 | MB/s | 0.485 MB/s | 0.498 MB/s | 0.592 MB/s | -2.6% | -18.0% |
| bs=100 sw=10 sl=64 | p50 | 123,621 us | 121,154 us | 103,584 us | +2.0% | +19.3% |
| bs=100 sw=10 sl=64 | p95 | 145,785 us | 148,228 us | 109,097 us | -1.6% | +33.6% |
| bs=100 sw=10 sl=64 | p99 | 145,785 us | 148,228 us | 117,304 us | -1.6% | +24.3% |
| bs=1000 sw=10 sl=64 | throughput | 913 tuples/sec | 909 tuples/sec | 1,004 tuples/sec | +0.4% | -9.0% |
| bs=1000 sw=10 sl=64 | MB/s | 0.558 MB/s | 0.555 MB/s | 0.613 MB/s | +0.5% | -8.9% |
| bs=1000 sw=10 sl=64 | p50 | 1,089,518 us | 1,102,275 us | 1,002,357 us | -1.2% | +8.7% |
| bs=1000 sw=10 sl=64 | p95 | 1,190,528 us | 1,136,933 us | 1,046,463 us | +4.7% | +13.8% |
| bs=1000 sw=10 sl=64 | p99 | 1,190,528 us | 1,136,933 us | 1,073,661 us | +4.7% | +10.9% |
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,528.93,200,128000,378,0.231,25354.25,32965.07,32965.07
1,100,10,64,20,2516.59,2000,1280000,795,0.485,123620.64,145784.68,145784.68
2,1000,10,64,20,21895.52,20000,12800000,913,0.558,1089518.47,1190527.60,1190527.60The pyamber worker reports its state to the controller via start/pause/ resume responses and query-statistics metrics. Without a version these defaulted to 0, so after the first report the controller's version gate dropped every later state change — breaking reconfiguration, which waits to observe RUNNING -> PAUSED -> RUNNING (ReconfigurationIntegrationSpec timed out). Mirror the Scala change in pyamber: StateManager bumps a monotonic state version on each transition, and the four state-reporting handlers include it.
The pause/resume/query-statistics assertions compared full messages against literals that defaulted state_version to 0; read the actual version from the report (as the stats sizes already are) so the equality holds while StateManager tests cover the version itself.
There was a problem hiding this comment.
Pull request overview
Fixes a race in Amber’s controller-side worker-state reconstruction where late-arriving RUNNING snapshots (e.g., from startWorker) could overwrite a newer terminal state (COMPLETED), causing operators to remain visually “RUNNING” after completion. The PR replaces receipt-time ordering with causal ordering via a per-worker logical stateVersion reported by the worker state machine, and makes terminal states absorbing.
Changes:
- Introduce a monotonic per-worker
stateVersion(Scala + Python) and propagate it through RPC/proto messages that report state. - Update controller-side reconciliation to apply worker state only when
stateVersionis strictly newer; keep worker statistics ordered by timestamp independently. - Add/adjust Scala and Python tests to cover version ordering, stale/equal-version rejection, terminal absorption, and regression for #6010.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| amber/src/main/scala/org/apache/texera/amber/engine/common/statetransition/StateManager.scala | Adds a monotonic stateVersion logical clock bumped on successful transitions. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/layer/WorkerExecution.scala | Replaces timestamp-based state updates with updateState(stateVersion, state); adds terminal-state absorption and separate updateStats. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/scheduling/RegionExecutionCoordinator.scala | Applies startWorker state using stateVersion; switches termination path to forceTerminate(). |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/controller/promisehandlers/WorkerStateUpdatedHandler.scala | Orders pushed state updates by stateVersion instead of controller receipt time. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/controller/promisehandlers/ResumeHandler.scala | Applies resume responses using stateVersion. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/controller/promisehandlers/PauseHandler.scala | Applies pause responses using stateVersion; updates stats via updateStats. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/controller/promisehandlers/QueryWorkerStatisticsHandler.scala | Splits metrics application into updateState(stateVersion, ...) and updateStats(timestamp, ...). |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/promisehandlers/StartHandler.scala | Includes stateVersion in WorkerStateResponse for start responses. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/promisehandlers/ResumeHandler.scala | Includes stateVersion in WorkerStateResponse for resume responses. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/promisehandlers/PauseHandler.scala | Includes stateVersion in WorkerStateResponse for pause responses. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/promisehandlers/QueryStatisticsHandler.scala | Includes stateVersion in WorkerMetrics returned by queryStatistics. |
| amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/DataProcessor.scala | Includes stateVersion in WorkerStateUpdatedRequest push events. |
| amber/src/main/protobuf/org/apache/texera/amber/engine/architecture/worker/statistics.proto | Adds state_version to WorkerMetrics for causal state ordering. |
| amber/src/main/protobuf/org/apache/texera/amber/engine/architecture/rpc/controlreturns.proto | Adds state_version to WorkerStateResponse. |
| amber/src/main/protobuf/org/apache/texera/amber/engine/architecture/rpc/controlcommands.proto | Adds state_version to WorkerStateUpdatedRequest. |
| amber/src/main/python/core/architecture/managers/state_manager.py | Adds a monotonic _state_version and get_state_version(); bumps on transitions. |
| amber/src/main/python/core/architecture/handlers/control/start_worker_handler.py | Returns WorkerStateResponse with state_version. |
| amber/src/main/python/core/architecture/handlers/control/pause_worker_handler.py | Returns WorkerStateResponse with state_version. |
| amber/src/main/python/core/architecture/handlers/control/resume_worker_handler.py | Returns WorkerStateResponse with state_version. |
| amber/src/main/python/core/architecture/handlers/control/query_statistics_handler.py | Includes state_version in WorkerMetrics. |
| amber/src/test/scala/org/apache/texera/amber/engine/common/statetransition/WorkerStateManagerSpec.scala | Adds unit tests for initial version, bumping rules, and no-op/rejected transitions. |
| amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/RegionCoordinatorTestSupport.scala | Updates test stub StartWorker response to include stateVersion. |
| amber/src/test/scala/org/apache/texera/amber/engine/architecture/deploysemantics/layer/WorkerExecutionSpec.scala | Adds coverage for version-based ordering, terminal absorption, and #6010 regression. |
| amber/src/test/scala/org/apache/texera/amber/engine/architecture/controller/execution/OperatorExecutionSpec.scala | Updates test helper to use updateState + updateStats with a monotonic surrogate. |
| amber/src/test/python/core/architecture/managers/test_state_manager.py | Adds Python unit tests mirroring Scala version semantics. |
| amber/src/test/python/core/runnables/test_main_loop.py | Updates expectations to carry through the reported state_version instead of hardcoding counts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @Yicong-Huang, it seems this PR cannot be directly backported. Do we still need to backport this change? I noticed that OperatorExecutionSpec.scala does not exist on the release branch. |
|
I think it will be good if we can include the fix in release v1.2, I will do a separate pr to fix v1.2. But I want to first this PR reviewed. cc @Xiao-zhen-Liu can you help take a look as well? |
oh sorry I misread. If |
Xiao-zhen-Liu
left a comment
There was a problem hiding this comment.
LGTM. Version-based causal ordering is the right model here. Worker state is single-writer and causally ordered, so a per-worker logical clock beats wall-clock time and needs no cross-process clock sync. I checked all the state-report sites (six Scala, four Python) and they all pass the version through, the version gate and terminal absorption read correctly, and the tests are solid.
One thing before merge: the PR is conflicting with main, since controller/promisehandlers was renamed to coordinator/promisehandlers and RegionExecutionCoordinator to RegionExecutionManager after it was opened. It needs a rebase onto those files.
Optional, not blocking: the bug is visual (border stuck orange), so a quick before/after of the border, or a note confirming the manual repro, would be a nice touch. The unit-level regression already covers the ordering logic well.
…ts Python twin, add proto trailing newline Co-Authored-By: Claude Fable 5 <[email protected]>
…usal-order # Conflicts: # amber/src/main/scala/org/apache/texera/amber/engine/architecture/deploysemantics/layer/WorkerExecution.scala # amber/src/main/scala/org/apache/texera/amber/engine/architecture/worker/DataProcessor.scala
…() calls to updateState() Co-Authored-By: Claude Fable 5 <[email protected]>
…+version atomically at report sites; fix receipt-time comments - ExecutionUtils.aggregateStates: a mixed COMPLETED/TERMINATED set is a routine end-of-region shape under terminal absorption (forceTerminate preserves confirmed-COMPLETED workers); aggregate it as COMPLETED instead of UNKNOWN so post-termination operators display correctly and stay skipped by the stats query (no RPCs to stopped workers). Updated the pinned ExecutionUtilsSpec case. - StateManager (Scala+Python): add getStateWithVersion/get_state_with_version and use it at all 10 state-report sites, so a report can never pair a state with another transition's version (review suggestion by Xiao-zhen-Liu). - WorkerExecution: call the stats timestamp receipt time, not wall-clock — System.nanoTime is a monotonic elapsed clock. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Backport PR opened: draft#7106 (#7106) to |
### What changes were proposed in this PR? A fast **source** operator stayed **orange (RUNNING)** in the editor after the run finished (issue apache#6010). **Why it's a bug.** The controller reconstructs each worker's state from several unordered channels (source `RUNNING` via the `startWorker` response, non-source `RUNNING` via `workerStateUpdated`, `COMPLETED`/`PAUSED` via `queryStatistics`/`pauseWorker` responses) and reconciled them with **last-`System.nanoTime()`-wins** in `WorkerExecution`. Worker state, however, is single-writer and strictly ordered causally. For a tiny source the run finishes almost instantly, so the `startWorker` response — carrying the stale `RUNNING` it sampled at launch — can reach the controller *after* `COMPLETED` was recorded; its later receipt timestamp wins and clobbers `COMPLETED`. Results render fine (separate path), so only the border is stuck. This PR orders worker state **causally** instead of by wall clock: | Before | After | | --- | --- | | `WorkerExecution.update(nanoTime, state)` — last-write-wins by receipt time | `updateState(version, state)` — newest **logical version** wins | | stale late RUNNING clobbers COMPLETED | RUNNING (v2) < COMPLETED (v3) ⇒ COMPLETED kept | | — | terminal states (COMPLETED/TERMINATED) are absorbing | - `WorkerStateManager` bumps a monotonic `stateVersion` on every `transitTo` (its state-machine logical clock). - The version rides on every state report: `WorkerStateResponse`, `WorkerStateUpdatedRequest`, `WorkerMetrics` (3 new proto fields). - The controller applies a state only when its version is newer. Stats stay timestamp-ordered (monotonic snapshots can share a state version). - A single per-worker counter ⇒ no cross-process clock-sync assumptions (why not worker timestamps). - **pyamber parity:** the Python worker also reports state (start/pause/resume + query-statistics). Its `StateManager` now bumps the same monotonic version and the four handlers include it; otherwise version-0 reports would be dropped after the first and reconfiguration (RUNNING→PAUSED→RUNNING) would hang. ### Any related issues, documentation, discussions? Closes apache#6010. The timestamp-based `update` was introduced in apache#3557. ### How was this PR tested? JDK 17. Scala unit + Scala/Python integration + Python unit: ``` sbt "WorkflowExecutionService/testOnly \ *WorkerExecutionSpec *WorkerStateManagerSpec *OperatorExecutionSpec \ *RegionExecutionCoordinatorSpec *WorkflowExecutionCoordinatorSpec \ *RegionExecutionSpec *WorkflowExecutionSpec" # Scala-Python reconfiguration end-to-end (spawns Python UDF workers): sbt "WorkflowExecutionService/testOnly *ReconfigurationIntegrationSpec" # 3 passed # Python unit: cd amber && pytest src/test/python/core/architecture/managers/test_state_manager.py # 9 passed ``` - `WorkerExecutionSpec`: version ordering (positive + stale/equal-version negatives), terminal-state absorption, `forceTerminate`, independent stats-vs-state ordering, and a named regression for apache#6010 (`COMPLETED` survives a late `RUNNING`). Verified the regression goes **red** when `updateState` is reverted to last-write-wins. - `WorkerStateManagerSpec` / `test_state_manager.py`: version starts at 0, bumps per successful transition, no bump on no-op self-transition or rejected transition. - `ReconfigurationIntegrationSpec` reproduced the failure (timeout) before the pyamber fix and passes after. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Opus 4.8 (1M context), via Claude Code --------- (backported from commit f521750) Co-authored-by: Claude Fable 5 <[email protected]>
### What changes were proposed in this PR? Backport of #6011 to `release/v1.2`, cherry-picked from f521750. Follows the Direct Backport Push convention; opened as a PR (rather than a direct push) as part of a backport-coverage audit for fixes merged to `main` since early June that were never labeled for backport. ### Any related issues, documentation, discussions? Backport of #6011. Originally linked #6010. ### How was this PR tested? Release-branch CI runs once the conflicts are resolved and this PR is marked ready for review. The cherry-pick **conflicted** and was committed with conflict markers. ### Was this PR authored or co-authored using generative AI tooling? Yes — backport prepared with Claude Code (mechanical cherry-pick; conflicts left as markers for the original author to resolve; the change itself is #6011 by its original author). Co-authored-by: Claude Fable 5 <[email protected]>
…7610) ### What changes were proposed in this PR? This PR adds `WorkerStateUpdatedHandlerSpec`, the first unit coverage for `amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/WorkerStateUpdatedHandler.scala`. The handler had no references anywhere in the test tree. The version-ordered state model it feeds was fixed and tested in apache#6011, which gave `WorkerExecution` a spec, but the handler wiring itself was unpinned. No production code is changed; this is a test-only PR. The spec drives a real `CoordinatorProcessor` with no ActorSystem and captures the dispatched client events through the coordinator's output handler. The 20 tests pin the handler's lookup, the update it applies, and the broadcasts it emits: - the physical operator is derived from `ctx.sender`, and the update lands on that worker alone rather than on the operator's other workers or on another operator; - reports are ordered by the request's `stateVersion`, so a stale or re-delivered version is ignored while a strictly newer one applies, and the version each worker carries is its own rather than shared across the operator; - a terminal state absorbs every later report, reached both through a COMPLETED report and through a TERMINATED one, and the reports refused this way are still broadcast; - only running region executions are consulted, and only the first one owning the operator, while the broadcast statistics span every region execution including completed ones; - the skip branch this coverage exists for: when no running region execution owns the sender's operator the report is dropped, yet `ExecutionStatsUpdate` and `RuntimeStatisticsPersist` still fire and the reply is still an empty success; - both boundaries of the version guard, since `lastStateVersion` starts at `-1` and the comparison is strictly-greater: a first report at `-1` is dropped as if stale, and a report at `Long.MaxValue` freezes a worker even when its state is not terminal. Two of these record current behavior that a reader may find surprising, and each says so in a comment rather than implying endorsement. An unknown worker of a known operator throws a `NullPointerException`, because `getWorkerExecution` is a `ConcurrentHashMap.get` whose `null` is dereferenced immediately, and on that path both client broadcasts are lost, which is the opposite of how an unknown operator is handled one branch away. A report carrying the proto default `UNINITIALIZED` at version 0 is applied invisibly and consumes the first real version, so the worker's genuine first transition is then dropped without a trace. If either is later changed deliberately, the corresponding test turns red and forces that decision to be explicit. ### Any related issues, documentation, discussions? Closes apache#7607 Related: apache#6011 introduced the version-ordered state model this handler feeds. ### How was this PR tested? The 20 new tests were run locally, together with the six pre-existing specs in the same package and the wider coordinator package: ``` sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.coordinator.promisehandlers.WorkerStateUpdatedHandlerSpec" -> Tests: succeeded 20, failed 0 sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.coordinator.promisehandlers.*" -> Suites: completed 7, Tests: succeeded 48, failed 0 sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.coordinator.*" -> Suites: completed 19, Tests: succeeded 171, failed 0 sbt "WorkflowExecutionService/Test/scalafmtCheck" -> success ``` Both positive and negative directions are covered, along with the empty and boundary cases: an applied update and a skipped one, a workflow execution with no region execution at all, the `-1` version sentinel, and the `Long.MaxValue` ceiling. The assertions were mutation-checked rather than assumed to be meaningful. Mutations were applied one at a time to `WorkerStateUpdatedHandler.scala`, `WorkerExecution.scala` and `OperatorExecution.scala`, and each turned the spec red: dropping either `sendToClient` call, swapping their order, guarding them behind a non-empty statistics map, replacing `getRunningRegionExecutions` with all region executions, widening `find` to `filter`, deriving the operator from `ctx.receiver` instead of `ctx.sender`, computing the statistics snapshot before applying the update, forwarding a constant version to `updateState`, moving the sentinel off `-1`, changing the version comparison to `<=` or `!=`, adding a state-equality condition to the guard, removing `TERMINATED` from the terminal check, and returning one shared `WorkerExecution` for every worker. The production files were restored and verified byte-identical to `HEAD` afterwards. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5)
What changes were proposed in this PR?
A fast source operator stayed orange (RUNNING) in the editor after the run finished (issue #6010).
Why it's a bug. The controller reconstructs each worker's state from several unordered channels (source
RUNNINGvia thestartWorkerresponse, non-sourceRUNNINGviaworkerStateUpdated,COMPLETED/PAUSEDviaqueryStatistics/pauseWorkerresponses) and reconciled them with last-System.nanoTime()-wins inWorkerExecution. Worker state, however, is single-writer and strictly ordered causally. For a tiny source the run finishes almost instantly, so thestartWorkerresponse — carrying the staleRUNNINGit sampled at launch — can reach the controller afterCOMPLETEDwas recorded; its later receipt timestamp wins and clobbersCOMPLETED. Results render fine (separate path), so only the border is stuck.This PR orders worker state causally instead of by wall clock:
WorkerExecution.update(nanoTime, state)— last-write-wins by receipt timeupdateState(version, state)— newest logical version winsWorkerStateManagerbumps a monotonicstateVersionon everytransitTo(its state-machine logical clock).WorkerStateResponse,WorkerStateUpdatedRequest,WorkerMetrics(3 new proto fields).StateManagernow bumps the same monotonic version and the four handlers include it; otherwise version-0 reports would be dropped after the first and reconfiguration (RUNNING→PAUSED→RUNNING) would hang.Any related issues, documentation, discussions?
Closes #6010. The timestamp-based
updatewas introduced in #3557.How was this PR tested?
JDK 17. Scala unit + Scala/Python integration + Python unit:
WorkerExecutionSpec: version ordering (positive + stale/equal-version negatives), terminal-state absorption,forceTerminate, independent stats-vs-state ordering, and a named regression for Fast source operator stays orange (RUNNING) after the workflow completes #6010 (COMPLETEDsurvives a lateRUNNING). Verified the regression goes red whenupdateStateis reverted to last-write-wins.WorkerStateManagerSpec/test_state_manager.py: version starts at 0, bumps per successful transition, no bump on no-op self-transition or rejected transition.ReconfigurationIntegrationSpecreproduced the failure (timeout) before the pyamber fix and passes after.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.8 (1M context), via Claude Code