Skip to content

Commit

Permalink
[improve](tablet_lock) do not hold tablet lock when clearing cache
Browse files Browse the repository at this point in the history
We found that clearing cache sometimes consums a lot time, so do not
hold lock when clearing cache and trace time-consuming cache clearing.
  • Loading branch information
dataroaring committed Aug 7, 2024
1 parent 44ac169 commit e55b74b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 9 additions & 2 deletions be/src/olap/rowset/rowset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "olap/segment_loader.h"
#include "olap/tablet_schema.h"
#include "util/time.h"
#include "util/trace.h"

namespace doris {

Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 14 additions & 7 deletions be/src/olap/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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

0 comments on commit e55b74b

Please sign in to comment.