Skip to content

fix(amber): end worker statistics queries at a deadline - #9371

Open
CaroFernando wants to merge 2 commits into
apache:mainfrom
CaroFernando:feat/stats-query-wedge
Open

CaroFernando wants to merge 2 commits into
apache:mainfrom
CaroFernando:feat/stats-query-wedge

Conversation

@CaroFernando

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Root cause. A worker statistics query waited for every reply with no timeout, and its in-flight flag (globalQueryStatsOngoing) was cleared only on success. A reply can be lost (e.g. a worker stopped during region teardown), and the coordinator never fails a pending request — it just waits. One lost reply therefore stalled the query forever, and with it everything chained on it:

Before:  lost queryStatistics reply -> query never completes
           -> portCompleted bookkeeping never runs          -> region never advances
           -> workerExecutionCompleted never continues      -> workflow never reported finished, timers never stop
           -> in-flight flag stays set                      -> every later poll serves stale stats
After:   lost queryStatistics reply -> query ends at its deadline -> all of the above proceed
Change Where
Each query gets a deadline: a CoordinatorStatisticsQueryDeadline request the coordinator schedules to itself, the same way its status timer schedules polls, so it is handled on the actor thread. Withdrawn when the query ends first, so a healthy query sends no extra message. QueryWorkerStatisticsHandler, coordinatorservice.proto, controlcommands.proto
Replies are applied as they arrive, not in one batch at the end, so a worker slower than the deadline still gets its statistics updated. Past the deadline, the remaining layers are still asked, not waited for. QueryWorkerStatisticsHandler
The in-flight flag is released however the query ends (ensure), and only by the full-graph query that holds it. QueryWorkerStatisticsHandler
portCompleted treats the statistics refresh as best-effort, so a coordinator-side failure in it cannot block the port bookkeeping. Failures in the bookkeeping itself are still reported to the worker. PortCompletedHandler
New setting constants.statistics-query-reply-timeout (default 10000 ms, env CONSTANTS_STATISTICS_QUERY_REPLY_TIMEOUT). application.conf, ApplicationConfig

Design note: deviation from the issue's suggestion. #6924 suggests a .within(...) per layer. .within completes the future from a timer thread, so the continuation (the next layer, applying replies, the flag) would run off the coordinator's actor thread and race with it — the problem #6923 describes. The deadline is instead a request the coordinator sends itself, processed on the actor thread like any other input. One deadline per query, rather than per layer, also bounds the total wait to one timeout regardless of the number of layers.

Behavior notes for reviewers

  • Worker states and statistics are now applied as each reply arrives rather than at the end of the query. State updates stay ordered by the worker's state version, so a late reply cannot regress a newer state (a forceTerminate is Long.MaxValue).
  • While a worker is stuck, a poll waits up to the timeout, so the UI refreshes about every 10 s instead of 500 ms, and a port completion with that worker upstream waits up to 10 s (instead of forever). Each such query leaves one unanswered request to that worker.
  • A healthy run is unchanged: the deadline is withdrawn as soon as the query ends.

Any related issues, documentation, discussions?

Closes #6924.

Of the three defects listed there, the third (mixed COMPLETED/TERMINATED operators being re-queried) was already fixed on main by ExecutionUtils.aggregateStates; this PR addresses the first two. Related: #6916 (closed in favor of #6960, which reordered portCompleted's reply and the region advance but left the statistics chain unchanged), and #6923 (timer-thread races — the deadline here deliberately avoids completing anything from a timer thread).

How was this PR tested?

New and changed unit tests (each fails with its corresponding change reverted):

  • QueryWorkerStatisticsHandlerSpec (new): a query completes at its deadline when a worker never replies; a reply arriving after the deadline is still applied; upstream layers are still asked after the deadline; a worker answering with an error keeps its last statistics; the flag is released when the coordinator fails mid-query; a filtered query does not release the full-graph query's flag; the deadline is withdrawn once every worker answered; no deadline for a query that asks no worker.
  • WorkerExecutionCompletedHandlerSpec (new): the final refresh completes and forwards statistics to persistence when the worker never answers.
  • PortCompletedHandlerSpec: the port completes and the region advances when the worker never answers the refresh (the Statistics collection can wedge permanently: no timeout on layered query chains and a one-way in-flight flag #6924 scenario) or the refresh fails; a failure in the bookkeeping itself still returns an error reply. The previous test asserting that a failed refresh fails the port is replaced, since that is the behavior being fixed.
  • ApplicationConfigSpec: default of the new setting.

Coverage of the two changed handlers (JaCoCo, over the coordinator handler specs):

File Lines before Lines after
QueryWorkerStatisticsHandler.scala 7/45 (15.6%) 84/86 (97.7%) — all changed lines covered
PortCompletedHandler.scala 7/7 15/15

Full Required Checks passed on the fork (workflow dispatch, all stacks), including the real-workflow specs in the amber job (DataProcessingSpec, PauseSpec, BatchSizePropagationSpec, ReconfigurationSpec) and amber-integration against Postgres/RustFS/Lakekeeper: https://github.com/CaroFernando/texera/actions/runs/42549302228 (run on the pre-rebase commit; the branch was then rebased onto main without conflicts and the coordinator specs re-run locally). Those runs use the default timeout; the forced-timeout path is covered by the unit tests above.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

Add `newCoordinatorInFlight`, a real `CoordinatorProcessor` with one region
in flight, and `SelfMessageCapturingActorService`, which records messages the
coordinator schedules to itself (and their cancellation) instead of
scheduling them, so a spec can fire them when it chooses. Purely additive:
existing helpers are unchanged.

Generated-by: Claude Code (Claude Opus 5.5)
A statistics query waited for every worker's reply with no timeout, and its
in-flight flag was cleared only on success. One lost reply therefore stalled
the query forever, and with it whatever awaited it: `portCompleted` (the
region never advanced), `workerExecutionCompleted` (the workflow was never
reported finished), and every later poll (stats froze). See apache#6924.

- Each query gets a deadline: a `CoordinatorStatisticsQueryDeadline` request
  the coordinator schedules to itself, the same way its status timer
  schedules polls, so it is handled on the actor thread. It is withdrawn when
  the query ends first, so a healthy query sends no extra message.
- Replies are applied as they arrive instead of in one batch at the end, so a
  worker slower than the deadline still gets its statistics updated.
- Past the deadline, the remaining layers are still asked, without waiting.
- The in-flight flag is released however the query ends, and only by the
  full-graph query that holds it.
- `portCompleted` treats the statistics refresh as best-effort, so a failure
  in it cannot block the port bookkeeping.

The timeout is `constants.statistics-query-reply-timeout` (default 10s).

Generated-by: Claude Code (Claude Opus 5.5)
@Yicong-Huang Yicong-Huang added release/v1.3 back porting to release/v1.3 release/v1.2 back porting to release/v1.2 labels Nov 9, 2026
@github-actions
github-actions Bot requested review from mengw15 and xuang7 November 9, 2026 03:04
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. A release/* label nominates a backport target; the branch's release manager approving this PR is what sends the fix there. The required Backport Approvals check stays red until every label below is approved, so each manager either approves or removes their own label — which is why the labels left on a merged PR are exactly the branches it reached.

Release branch Analysis
✅ release/v1.3 Change detected on this branch — label added; this fix is queued to backport here. @mengw15 decides: approving sends the fix here, removing this label declines it. The merge waits on one or the other. Review requested.
✅ release/v1.2 Change detected on this branch — label added; this fix is queued to backport here. @xuang7 decides: approving sends the fix here, removing this label declines it. The merge waits on one or the other. Review requested.

Auto-label run.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @aglinxinyuan, @aicam, @Yicong-Huang
    You can notify them by mentioning @aglinxinyuan, @aicam, @Yicong-Huang in a comment.

@codecov-commenter

codecov-commenter commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.27273% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.94%. Comparing base (b4b0648) to head (fd6c35d).
⚠️ Report is 48 commits behind head on main.

Files with missing lines Patch % Lines
...promisehandlers/QueryWorkerStatisticsHandler.scala 89.13% 0 Missing and 5 partials ⚠️
...dinator/promisehandlers/PortCompletedHandler.scala 71.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9371      +/-   ##
============================================
+ Coverage     91.79%   91.94%   +0.14%     
- Complexity     5019     6422    +1403     
============================================
  Files          1274     1314      +40     
  Lines         56301    62795    +6494     
  Branches       7352     8419    +1067     
============================================
+ Hits          51680    57734    +6054     
- Misses         2766     3057     +291     
- Partials       1855     2004     +149     
Flag Coverage Δ *Carryforward flag
access-control-service 79.55% <ø> (+2.10%) ⬆️
agent-service 99.53% <ø> (ø) Carriedforward from b4b0648
amber 87.73% <87.27%> (+1.98%) ⬆️
computing-unit-managing-service 66.03% <ø> (+1.97%) ⬆️
config-service 88.69% <ø> (+1.07%) ⬆️
file-service 83.20% <ø> (+0.90%) ⬆️
frontend 96.53% <ø> (ø) Carriedforward from b4b0648
notebook-migration-service 85.84% <ø> (+2.06%) ⬆️
pyamber 98.46% <ø> (ø) Carriedforward from b4b0648
workflow-compiling-service 78.57% <ø> (+0.61%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 4 better · 🔴 6 worse · ⚪ 5 noise (<±5%) · 0 without baseline

Compared against main b4b0648 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 354 0.216 26,173/41,486/41,486 us 🟢 -23.5% / 🔴 +186.9%
🔴 bs=100 sw=10 sl=64 806 0.492 122,333/153,905/153,905 us 🟢 -8.6% / 🔴 +65.1%
🔴 bs=1000 sw=10 sl=64 956 0.583 1,029,455/1,182,330/1,182,330 us 🔴 +8.7% / 🔴 +34.7%
Baseline details

Latest main b4b0648 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 354 tuples/sec 411 tuples/sec 927.28 tuples/sec -13.9% -61.8%
bs=10 sw=10 sl=64 MB/s 0.216 MB/s 0.251 MB/s 0.566 MB/s -13.9% -61.8%
bs=10 sw=10 sl=64 p50 26,173 us 22,498 us 10,932 us +16.3% +139.4%
bs=10 sw=10 sl=64 p95 41,486 us 54,196 us 14,458 us -23.5% +186.9%
bs=10 sw=10 sl=64 p99 41,486 us 54,196 us 17,274 us -23.5% +140.2%
bs=100 sw=10 sl=64 throughput 806 tuples/sec 820 tuples/sec 1,240 tuples/sec -1.7% -35.0%
bs=100 sw=10 sl=64 MB/s 0.492 MB/s 0.501 MB/s 0.757 MB/s -1.8% -35.0%
bs=100 sw=10 sl=64 p50 122,333 us 114,861 us 85,781 us +6.5% +42.6%
bs=100 sw=10 sl=64 p95 153,905 us 168,470 us 93,231 us -8.6% +65.1%
bs=100 sw=10 sl=64 p99 153,905 us 168,470 us 116,160 us -8.6% +32.5%
bs=1000 sw=10 sl=64 throughput 956 tuples/sec 972 tuples/sec 1,278 tuples/sec -1.6% -25.2%
bs=1000 sw=10 sl=64 MB/s 0.583 MB/s 0.593 MB/s 0.78 MB/s -1.7% -25.3%
bs=1000 sw=10 sl=64 p50 1,029,455 us 1,028,340 us 835,630 us +0.1% +23.2%
bs=1000 sw=10 sl=64 p95 1,182,330 us 1,087,250 us 877,570 us +8.7% +34.7%
bs=1000 sw=10 sl=64 p99 1,182,330 us 1,087,250 us 922,624 us +8.7% +28.1%
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,565.41,200,128000,354,0.216,26173.43,41485.80,41485.80
1,100,10,64,20,2482.44,2000,1280000,806,0.492,122333.45,153905.20,153905.20
2,1000,10,64,20,20928.38,20000,12800000,956,0.583,1029455.30,1182329.90,1182329.90

@xuang7

xuang7 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Removing release/v1.2: kill and rerun works around it, and the change is too large for a patch release.

@xuang7 xuang7 removed the release/v1.2 back porting to release/v1.2 label Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common engine feature release/v1.3 back porting to release/v1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Statistics collection can wedge permanently: no timeout on layered query chains and a one-way in-flight flag

4 participants