github-actions[bot] commented on code in PR #62646:
URL: https://github.com/apache/doris/pull/62646#discussion_r3124063690


##########
be/src/exec/scan/scanner_scheduler.cpp:
##########
@@ -156,29 +156,30 @@ void 
ScannerScheduler::_scanner_scan(std::shared_ptr<ScannerContext> ctx,
     // we set and get counter according below order, to make sure the counter 
is updated before get_block, and the time of get_block is recorded in the 
counter.
     // 1. update_wait_worker_timer to make sure the time of waiting for worker 
thread is recorded in the timer
     // 2. start_scan_cpu_timer to make sure the cpu timer include the time of 
open and get_block, which is the real cpu time of scanner
-    // 3. update_scan_cpu_timer when defer, to make sure the cpu timer include 
the time of open and get_block, which is the real cpu time of scanner
+    // 3. update_scan_cpu_timer at exit (in the Defer below for the non-eos 
yield path,
+    //    in the explicit eos block at the end of this function for the eos / 
error path),
+    //    to make sure the cpu timer includes the time of open and get_block, 
which is the real cpu time of scanner
     // 4. start_wait_worker_timer when defer, to make sure the time of waiting 
for worker thread is recorded in the timer
 
     MonotonicStopWatch max_run_time_watch;
     max_run_time_watch.start();
     scanner->update_wait_worker_timer();
     scanner->start_scan_cpu_timer();
 
-    bool need_update_profile = true;
     auto update_scanner_profile = [&]() {
-        if (need_update_profile) {
-            scanner->update_scan_cpu_timer();
-            scanner->update_realtime_counters();
-            need_update_profile = false;
-        }
+        scanner->update_scan_cpu_timer();
+        scanner->update_realtime_counters();
     };
 
     Status status = Status::OK();
     bool eos = false;
     Defer defer_scanner([&] {
         if (status.ok() && !eos) {
-            // if status is not ok, it means the scanner is failed, and the 
counter may be not updated correctly, so no need to update counter again. if 
eos is true, it means the scanner is finished successfully, and the counter is 
updated correctly, so no need to update counter again.
+            // Only start wait worker timer when the scanner will be 
re-submitted to the thread
+            // pool. When status is not ok or eos is true, the scanner is done 
and won't be
+            // re-scheduled, so there is no "waiting for worker" phase to 
track.
             scanner->start_wait_worker_timer();
+            update_scanner_profile();

Review Comment:
   Blocking: `defer_scanner` runs only when `_scanner_scan()` exits, but the 
last statement in this function is `ctx->push_back_scan_task(scan_task);`. That 
makes the non-EOS task visible for rescheduling before this 
`update_scanner_profile()` executes.
   
   On zero-block yield paths such as `max_run_time_ms`, reserve-memory failure, 
or `get_free_block() == nullptr`, the consumer can immediately resubmit the 
same `ScanTask`, and the next worker may call `start_scan_cpu_timer()` on the 
shared `Scanner` first. Because `_cpu_watch` is a `ThreadCpuStopWatch` 
(`CLOCK_THREAD_CPUTIME_ID`), reading it afterward from the old thread is again 
a cross-thread measurement and can produce bogus CPU accounting. 
`update_realtime_counters()` has the same ordering problem because it 
flushes/resets shared per-round stats after the next round may already have 
started mutating them.
   
   That is why master #62258 moved `update_scanner_profile()` before the task 
is re-queued. Can we do the same here instead of calling it from the scope 
`Defer`?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to