CaroFernando opened a new pull request, #9371:
URL: https://github.com/apache/texera/pull/9371

   ### 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 #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)
   


-- 
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