From c6a7a4dc8ba9a438c05492c3041f8ce964515f58 Mon Sep 17 00:00:00 2001 From: tsy Date: Thu, 15 Aug 2024 16:56:31 +0800 Subject: [PATCH] unify compaction score calculation --- .../http/action/compaction_score_action.cpp | 26 ++++++------------- be/src/olap/base_tablet.cpp | 9 +++++++ be/src/olap/base_tablet.h | 4 +++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/be/src/http/action/compaction_score_action.cpp b/be/src/http/action/compaction_score_action.cpp index c0e506e90c9d857..ab660656bcab650 100644 --- a/be/src/http/action/compaction_score_action.cpp +++ b/be/src/http/action/compaction_score_action.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -34,15 +33,13 @@ #include "http/http_headers.h" #include "http/http_request.h" #include "http/http_status.h" -#include "olap/olap_common.h" #include "olap/tablet_fwd.h" #include "olap/tablet_manager.h" namespace doris { constexpr std::string_view TABLET_ID = "tablet_id"; -constexpr std::string_view BASE_COMPACTION_SCORE = "base_compaction_score"; -constexpr std::string_view CUMULATIVE_COMPACTION_SCORE = "cumu_compaction_score"; +constexpr std::string_view COMPACTION_SCORE = "compaction_score"; CompactionScoreAction::CompactionScoreAction(ExecEnv* exec_env, TPrivilegeHier::type hier, TPrivilegeType::type type, @@ -60,22 +57,15 @@ static rapidjson::Value jsonfy_tablet_compaction_score( auto tablet_id_str = std::to_string(tablet->tablet_id()); tablet_id_val.SetString(tablet_id_str.c_str(), tablet_id_str.length(), allocator); - auto add_compaction_score = [&tablet, &allocator, &node](std::string_view key_name, - CompactionType type) { - rapidjson::Value score_key; - score_key.SetString(key_name.data(), key_name.size()); - - rapidjson::Value score_val; - auto score = - tablet->calc_compaction_score(type, tablet->get_cumulative_compaction_policy()); - auto score_str = std::to_string(score); - score_val.SetString(score_str.c_str(), score_str.length(), allocator); - node.AddMember(score_key, score_val, allocator); - }; + rapidjson::Value score_key; + score_key.SetString(COMPACTION_SCORE.data(), COMPACTION_SCORE.size()); + rapidjson::Value score_val; + auto score = tablet->get_real_compaction_score(); + auto score_str = std::to_string(score); + score_val.SetString(score_str.c_str(), score_str.length(), allocator); + node.AddMember(score_key, score_val, allocator); node.AddMember(tablet_id_key, tablet_id_val, allocator); - add_compaction_score(BASE_COMPACTION_SCORE, CompactionType::BASE_COMPACTION); - add_compaction_score(CUMULATIVE_COMPACTION_SCORE, CompactionType::CUMULATIVE_COMPACTION); return node; } diff --git a/be/src/olap/base_tablet.cpp b/be/src/olap/base_tablet.cpp index 22940b40206de42..1e3e7bfc3aa1a05 100644 --- a/be/src/olap/base_tablet.cpp +++ b/be/src/olap/base_tablet.cpp @@ -28,6 +28,7 @@ #include "olap/rowid_conversion.h" #include "olap/rowset/beta_rowset.h" #include "olap/rowset/rowset.h" +#include "olap/rowset/rowset_fwd.h" #include "olap/rowset/rowset_reader.h" #include "olap/tablet_fwd.h" #include "olap/txn_manager.h" @@ -225,6 +226,14 @@ Status BaseTablet::update_by_least_common_schema(const TabletSchemaSPtr& update_ return Status::OK(); } +uint32_t BaseTablet::get_real_compaction_score() const { + const auto& rs_metas = _tablet_meta->all_rs_metas(); + return std::accumulate(rs_metas.begin(), rs_metas.end(), 0, + [](uint32_t score, const RowsetMetaSharedPtr& rs_meta) { + return score + rs_meta->get_compaction_score(); + }); +} + Status BaseTablet::capture_rs_readers_unlocked(const Versions& version_path, std::vector* rs_splits) const { DCHECK(rs_splits != nullptr && rs_splits->empty()); diff --git a/be/src/olap/base_tablet.h b/be/src/olap/base_tablet.h index f958d398fd5d00f..5553839440a5b74 100644 --- a/be/src/olap/base_tablet.h +++ b/be/src/olap/base_tablet.h @@ -104,6 +104,10 @@ class BaseTablet { virtual size_t tablet_footprint() = 0; + // this method just return the compaction sum on each rowset + // note(tsy): we should unify the compaction score calculation finally + uint32_t get_real_compaction_score() const; + // MUST hold shared meta lock Status capture_rs_readers_unlocked(const Versions& version_path, std::vector* rs_splits) const;