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

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new d7e7c8040e5 [improve](tablet_lock) do not hold tablet lock when 
clearing cache (#39040)
d7e7c8040e5 is described below

commit d7e7c8040e5955d2631a1104bfc83901f6ea4ea7
Author: Yongqiang YANG <98214048+dataroar...@users.noreply.github.com>
AuthorDate: Wed Aug 7 21:28:28 2024 +0800

    [improve](tablet_lock) do not hold tablet lock when clearing cache (#39040)
    
    We found that clearing cache sometimes consums a lot time, so do not
    hold lock when clearing cache and trace time-consuming cache clearing.
---
 be/src/olap/rowset/rowset.cpp | 11 +++++++++--
 be/src/olap/tablet.cpp        | 22 ++++++++++++++--------
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/be/src/olap/rowset/rowset.cpp b/be/src/olap/rowset/rowset.cpp
index 8a4a25c2158..256f4d35313 100644
--- a/be/src/olap/rowset/rowset.cpp
+++ b/be/src/olap/rowset/rowset.cpp
@@ -23,6 +23,7 @@
 #include "olap/segment_loader.h"
 #include "olap/tablet_schema.h"
 #include "util/time.h"
+#include "util/trace.h"
 
 namespace doris {
 
@@ -118,8 +119,14 @@ std::string Rowset::get_rowset_info_str() {
 }
 
 void Rowset::clear_cache() {
-    SegmentLoader::instance()->erase_segments(rowset_id(), num_segments());
-    clear_inverted_index_cache();
+    {
+        SCOPED_SIMPLE_TRACE_IF_TIMEOUT(std::chrono::seconds(1));
+        SegmentLoader::instance()->erase_segments(rowset_id(), num_segments());
+    }
+    {
+        SCOPED_SIMPLE_TRACE_IF_TIMEOUT(std::chrono::seconds(1));
+        clear_inverted_index_cache();
+    }
 }
 
 Result<std::string> Rowset::segment_path(int64_t seg_id) {
diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp
index 5018c70be11..f159dc6f576 100644
--- a/be/src/olap/tablet.cpp
+++ b/be/src/olap/tablet.cpp
@@ -2641,15 +2641,21 @@ Status Tablet::ingest_binlog_metas(RowsetBinlogMetasPB* 
metas_pb) {
 }
 
 void Tablet::clear_cache() {
-    std::shared_lock rlock(get_header_lock());
-    SCOPED_SIMPLE_TRACE_IF_TIMEOUT(TRACE_TABLET_LOCK_THRESHOLD);
-    static auto recycle_segment_cache = [](const auto& rowset_map) {
-        for (auto& [_, rowset] : rowset_map) {
-            rowset->clear_cache();
+    std::vector<RowsetSharedPtr> rowsets;
+    {
+        std::shared_lock rlock(get_header_lock());
+        SCOPED_SIMPLE_TRACE_IF_TIMEOUT(TRACE_TABLET_LOCK_THRESHOLD);
+
+        for (auto& [_, rowset] : rowset_map()) {
+            rowsets.push_back(rowset);
         }
-    };
-    recycle_segment_cache(rowset_map());
-    recycle_segment_cache(stale_rowset_map());
+        for (auto& [_, rowset] : stale_rowset_map()) {
+            rowsets.push_back(rowset);
+        }
+    }
+    for (auto& rowset : rowsets) {
+        rowset->clear_cache();
+    }
 }
 
 } // namespace doris


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

Reply via email to