Skip to content

Commit 7268240

Browse files
committed
fix wrong count of scan wait worker timer
1 parent 5ba0753 commit 7268240

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

be/src/exec/scan/olap_scanner.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,11 @@ Status OlapScanner::close(RuntimeState* state) {
665665
}
666666

667667
void OlapScanner::update_realtime_counters() {
668+
if (!_has_prepared) {
669+
// Counter update need prepare successfully, or it maybe core. For example, olap scanner
670+
// will open tablet reader during prepare, if not prepare successfully, tablet reader == nullptr.
671+
return;
672+
}
668673
pipeline::OlapScanLocalState* local_state =
669674
static_cast<pipeline::OlapScanLocalState*>(_local_state);
670675
const OlapReaderStatistics& stats = _tablet_reader->stats();

be/src/exec/scan/scanner_scheduler.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,34 @@ void ScannerScheduler::_scanner_scan(std::shared_ptr<ScannerContext> ctx,
152152
Thread::set_thread_nice_value();
153153
}
154154
#endif
155+
156+
// 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.
157+
// 1. update_wait_worker_timer to make sure the time of waiting for worker thread is recorded in the timer
158+
// 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
159+
// 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
160+
// 4. start_wait_worker_timer when defer, to make sure the time of waiting for worker thread is recorded in the timer
161+
155162
MonotonicStopWatch max_run_time_watch;
156163
max_run_time_watch.start();
157164
scanner->update_wait_worker_timer();
158165
scanner->start_scan_cpu_timer();
159166

160-
// Counter update need prepare successfully, or it maybe core. For example, olap scanner
161-
// will open tablet reader during prepare, if not prepare successfully, tablet reader == nullptr.
162-
bool need_update_profile = scanner->has_prepared();
167+
bool need_update_profile = true;
163168
auto update_scanner_profile = [&]() {
164169
if (need_update_profile) {
165170
scanner->update_scan_cpu_timer();
166171
scanner->update_realtime_counters();
167172
need_update_profile = false;
168173
}
169174
};
175+
Status status = Status::OK();
176+
bool eos = false;
177+
170178
Defer defer_scanner([&] {
171-
// WorkloadGroup Policy will check cputime realtime, so that should update the counter
172-
// as soon as possible, could not update it on close.
173-
update_scanner_profile();
179+
if (status.ok() && !eos) {
180+
// 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.
181+
scanner->start_wait_worker_timer();
182+
}
174183
});
175184
Status status = Status::OK();
176185
bool eos = false;

0 commit comments

Comments
 (0)