diff --git a/be/src/olap/rowset/rowset.cpp b/be/src/olap/rowset/rowset.cpp index 8a4a25c2158795..256f4d35313d13 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 Rowset::segment_path(int64_t seg_id) { diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp index e3032be259ff7e..9b6ee71fd8413e 100644 --- a/be/src/olap/tablet.cpp +++ b/be/src/olap/tablet.cpp @@ -2649,14 +2649,21 @@ Status Tablet::ingest_binlog_metas(RowsetBinlogMetasPB* metas_pb) { } void Tablet::clear_cache() { - std::shared_lock rlock(get_header_lock()); - static auto recycle_segment_cache = [](const auto& rowset_map) { - for (auto& [_, rowset] : rowset_map) { - rowset->clear_cache(); + std::list 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