[Bug] Fix dead lock in olap scan node and refactor some code in FE profile (#5713)

* [Bug] Fix dead lock in olap scan node and refactor some code in FE profile

* Add some comment
This commit is contained in:
HappenLee
2021-04-30 10:12:18 +08:00
committed by GitHub
parent 8ff87409cb
commit 6ad1bf7d7e
3 changed files with 8 additions and 6 deletions

View File

@ -1470,12 +1470,16 @@ void OlapScanNode::scanner_thread(OlapScanner* scanner) {
_scan_cpu_timer->update(cpu_watch.elapsed_time());
_scanner_wait_worker_timer->update(wait_time);
_scan_batch_added_cv.notify_one();
// The transfer thead will wait for `_running_thread==0`, to make sure all scanner threads won't access class members.
// Do not access class members after this code.
std::unique_lock<std::mutex> l(_scan_batches_lock);
_running_thread--;
// Both cv of _scan_batch_added_cv and _scan_thread_exit_cv should be notify after
// change the value of _running_thread, because transfer thread lock will check the value
// of _running_thread after be notify. Otherwise there could be dead lock between scanner_thread
// and transfer thread
_scan_batch_added_cv.notify_one();
_scan_thread_exit_cv.notify_one();
}

View File

@ -344,15 +344,15 @@ public class RuntimeProfile {
// Because the profile of summary and child fragment is not a real parent-child relationship
// Each child profile needs to calculate the time proportion consumed by itself
public void computeTimeInChildProfile() {
childMap.values().stream().
forEach(child -> child.computeTimeInProfile());
childMap.values().
forEach(RuntimeProfile::computeTimeInProfile);
}
public void computeTimeInProfile() {
computeTimeInProfile(this.counterTotalTime.getValue());
}
public void computeTimeInProfile(long total) {
private void computeTimeInProfile(long total) {
if (total == 0) {
return;
}

View File

@ -416,8 +416,6 @@ public class StmtExecutor {
private void writeProfile() {
initProfile(plannerProfile);
profile.computeTimeInChildProfile();
StringBuilder builder = new StringBuilder();
profile.prettyPrint(builder, "");
ProfileManager.getInstance().pushProfile(profile);
}