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

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


The following commit(s) were added to refs/heads/master by this push:
     new f6881d2  [Bug] Fix coredump bug when create new tablets (#5089)
f6881d2 is described below

commit f6881d2f7b49aca1d0bc90b067eb9e1e73c409d1
Author: Yingchun Lai <405403...@qq.com>
AuthorDate: Thu Dec 17 00:34:31 2020 +0800

    [Bug] Fix coredump bug when create new tablets (#5089)
    
    There is a bug may cause BE coredump when create tablet,
    the accessing of tablet_set of a data dir should be protected by lock.
---
 be/src/olap/data_dir.cpp       | 5 +++++
 be/src/olap/data_dir.h         | 4 ++--
 be/src/olap/storage_engine.cpp | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/be/src/olap/data_dir.cpp b/be/src/olap/data_dir.cpp
index ffb5fc7..d746730 100644
--- a/be/src/olap/data_dir.cpp
+++ b/be/src/olap/data_dir.cpp
@@ -992,6 +992,11 @@ void DataDir::update_user_data_size(int64_t size) {
     disks_data_used_capacity->set_value(size);
 }
 
+size_t DataDir::tablet_size() const {
+    std::lock_guard<std::mutex> l(_mutex);
+    return _tablet_set.size();
+}
+
 bool DataDir::reach_capacity_limit(int64_t incoming_data_size) {
     double used_pct = (_disk_capacity_bytes - _available_bytes + 
incoming_data_size) /
                       (double)_disk_capacity_bytes;
diff --git a/be/src/olap/data_dir.h b/be/src/olap/data_dir.h
index 1a22f9e..a3c2d22 100644
--- a/be/src/olap/data_dir.h
+++ b/be/src/olap/data_dir.h
@@ -126,7 +126,7 @@ public:
 
     void update_user_data_size(int64_t size);
 
-    std::set<TabletInfo> tablet_set() { return _tablet_set; }
+    size_t tablet_size() const;
 
     void disks_compaction_score_increment(int64_t delta);
 
@@ -180,7 +180,7 @@ private:
     bool _to_be_deleted;
 
     // used to protect _current_shard and _tablet_set
-    std::mutex _mutex;
+    mutable std::mutex _mutex;
     uint64_t _current_shard;
     std::set<TabletInfo> _tablet_set;
 
diff --git a/be/src/olap/storage_engine.cpp b/be/src/olap/storage_engine.cpp
index cc1df07..56f2d90 100644
--- a/be/src/olap/storage_engine.cpp
+++ b/be/src/olap/storage_engine.cpp
@@ -434,7 +434,7 @@ std::vector<DataDir*> 
StorageEngine::get_stores_for_create_tablet(
     for (int i = 0; i < stores.size(); i++) {
         int j = i + 1;
         if (j < stores.size()) {
-            if (stores[i]->tablet_set().size() > 
stores[j]->tablet_set().size()) {
+            if (stores[i]->tablet_size() > stores[j]->tablet_size()) {
                 std::swap(stores[i], stores[j]);
             }
             std::random_shuffle(stores.begin() + j, stores.end());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to