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

   ### What changes were proposed in this PR?
   
   Problem. `ExecutionStatsService` queues each `RuntimeStatisticsPersist` on 
its own persist thread, but closes the runtime statistics writer directly on 
the callback thread when the execution reaches a terminal state. The engine 
reports the final statistics right before the terminal state, so `close()` can 
flush and commit before that last snapshot is written. The snapshot then sits 
in the writer's buffer and is never committed. The persist executor is also 
never shut down, so every execution leaves an idle thread behind.
   
   Fix. The terminal-state callback now runs `close()` on the persist thread, 
behind anything still queued, and waits for it, so the commit stays synchronous 
as before. It then shuts the executor down. Statistics or terminal states that 
arrive after that are ignored instead of being rejected by the shut-down 
executor.
   
   ```
   Before:  final persist -> queued | terminal state -> close() now   -> commit 
-> final snapshot never committed
   After:   final persist -> queued | terminal state -> close() queued -> final 
snapshot committed -> executor shut down
   ```
   
   ### Any related issues, documentation, discussions?
   
   Closes #9627. Found while reviewing #9594.
   
   ### How was this PR tested?
   
   Three tests were added to `ExecutionStatsServiceSpec`. The first holds the 
persist thread so the final snapshot is still queued when the terminal state 
arrives, then checks that the snapshot is committed. The second checks that the 
persist executor is shut down after the commit. The third sends statistics and 
another terminal state after the commit and checks that nothing throws and 
nothing more is persisted. All three fail without the fix; the first reads back 
no rows. The existing persistence tests waited for the persist thread before 
sending the terminal state, which is why they passed.
   
   ```
   sbt "WorkflowExecutionService/testOnly 
org.apache.texera.web.service.ExecutionStatsServiceSpec 
org.apache.texera.web.service.WorkflowExecutionServiceSpec"
   ```
   
   That runs 28 tests, and all pass.
   
   ### 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