This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit ff89306e0d83fd7140d430a82def759068a265a7
Author: Yongqiang YANG <[email protected]>
AuthorDate: Tue Mar 21 12:52:48 2023 +0800

    [fix](quit) be can not quit cleanly due to deadlock (#17971)
---
 be/src/olap/data_dir.cpp | 9 ++++++++-
 be/src/olap/data_dir.h   | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/be/src/olap/data_dir.cpp b/be/src/olap/data_dir.cpp
index 10056b1917..a47aab55d3 100644
--- a/be/src/olap/data_dir.cpp
+++ b/be/src/olap/data_dir.cpp
@@ -119,8 +119,8 @@ Status DataDir::init() {
 }
 
 void DataDir::stop_bg_worker() {
-    std::unique_lock<std::mutex> lck(_check_path_mutex);
     _stop_bg_worker = true;
+    std::unique_lock<std::mutex> lck(_check_path_mutex);
     _check_path_cv.notify_one();
 }
 
@@ -668,6 +668,10 @@ void DataDir::perform_path_scan() {
             continue;
         }
         for (const auto& tablet_id : tablet_ids) {
+            if (_stop_bg_worker) {
+                break;
+            }
+
             auto tablet_id_path = fmt::format("{}/{}", shard_path, tablet_id);
             std::set<std::string> schema_hashes;
             ret = FileUtils::list_dirs_files(tablet_id_path, &schema_hashes, 
nullptr,
@@ -680,6 +684,9 @@ void DataDir::perform_path_scan() {
 
             for (const auto& schema_hash : schema_hashes) {
                 int32_t interval_ms = config::path_scan_step_interval_ms;
+                if (_stop_bg_worker) {
+                    break;
+                }
                 if (interval_ms > 0) {
                     
std::this_thread::sleep_for(std::chrono::milliseconds(interval_ms));
                 }
diff --git a/be/src/olap/data_dir.h b/be/src/olap/data_dir.h
index 20b23c1405..895c1088c4 100644
--- a/be/src/olap/data_dir.h
+++ b/be/src/olap/data_dir.h
@@ -164,7 +164,7 @@ private:
     bool _check_pending_ids(const std::string& id);
 
 private:
-    bool _stop_bg_worker = false;
+    std::atomic<bool> _stop_bg_worker = false;
 
     std::string _path;
     size_t _path_hash;


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

Reply via email to