You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by li...@apache.org on 2020/04/13 03:18:45 UTC

[incubator-doris] branch master updated: Use read lock when iterate tablet_map in TabletManager::start_trash_sweep (#3294)

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

lichaoyong 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 be090f5  Use read lock when iterate tablet_map in TabletManager::start_trash_sweep (#3294)
be090f5 is described below

commit be090f5929c3ed866af9a8789b2008ae4dc7e921
Author: Lijia Liu <li...@yeah.net>
AuthorDate: Sun Apr 12 22:18:33 2020 -0500

    Use read lock when iterate tablet_map in TabletManager::start_trash_sweep (#3294)
---
 be/src/olap/tablet_manager.cpp | 46 +++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/be/src/olap/tablet_manager.cpp b/be/src/olap/tablet_manager.cpp
index 7367a20..ca78d05 100644
--- a/be/src/olap/tablet_manager.cpp
+++ b/be/src/olap/tablet_manager.cpp
@@ -959,29 +959,43 @@ OLAPStatus TabletManager::report_all_tablets_info(std::map<TTabletId, TTablet>*
 OLAPStatus TabletManager::start_trash_sweep() {
     {
         std::vector<int64_t> tablets_to_clean;
+        std::vector<TabletSharedPtr> all_tablets; // we use this vector to save all tablet ptr for saving lock time.
         for (int32 i = 0; i < _tablet_map_lock_shard_size; i++) {
-            WriteLock rlock(&_tablet_map_lock_array[i]);
             tablet_map_t& tablet_map = _tablet_map_array[i];
-            for (auto& item : tablet_map) {
-                // try to clean empty item
-                if (item.second.table_arr.empty()) {
-                    // try to get schema change lock if could get schema change lock, then nobody
-                    // own the lock could remove the item
-                    // it will core if schema change thread may hold the lock and this thread will deconstruct lock
-                    if (item.second.schema_change_lock.trylock() == OLAP_SUCCESS) {
-                        item.second.schema_change_lock.unlock();
+            {
+                ReadLock r_lock(&_tablet_map_lock_array[i]);
+                for (auto& item : tablet_map) {
+                    // try to clean empty item
+                    if (item.second.table_arr.empty()) {
                         tablets_to_clean.push_back(item.first);
                     }
-                }
-                for (TabletSharedPtr tablet : item.second.table_arr) {
-                    tablet->delete_expired_inc_rowsets();
+                    for (TabletSharedPtr tablet : item.second.table_arr) {
+                        all_tablets.push_back(tablet);
+                    }
                 }
             }
-            // clean empty tablet id item
-            for (const auto& tablet_id_to_clean : tablets_to_clean) {
-                if (tablet_map[tablet_id_to_clean].table_arr.empty()) {
-                    tablet_map.erase(tablet_id_to_clean);
+
+            for (const auto& tablet : all_tablets) {
+                tablet->delete_expired_inc_rowsets();
+            }
+            all_tablets.clear();
+
+            if (!tablets_to_clean.empty()) {
+                WriteLock w_lock(&_tablet_map_lock_array[i]);
+                // clean empty tablet id item
+                for (const auto& tablet_id_to_clean : tablets_to_clean) {
+                    auto& item = tablet_map[tablet_id_to_clean];
+                    if (item.table_arr.empty()) {
+                        // try to get schema change lock if could get schema change lock, then nobody
+                        // own the lock could remove the item
+                        // it will core if schema change thread may hold the lock and this thread will deconstruct lock
+                        if (item.schema_change_lock.trylock() == OLAP_SUCCESS) {
+                            item.schema_change_lock.unlock();
+                            tablet_map.erase(tablet_id_to_clean);
+                        }
+                    }
                 }
+                tablets_to_clean.clear(); // We should clear the vector before next loop
             }
         }
     }


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