Skip to content

Commit

Permalink
unify compaction score calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
TangSiyang2001 committed Aug 15, 2024
1 parent a047be1 commit c6a7a4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
26 changes: 8 additions & 18 deletions be/src/http/action/compaction_score_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <rapidjson/stringbuffer.h>

#include <cstdint>
#include <cstdlib>
#include <exception>
#include <memory>
#include <string>
Expand All @@ -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,
Expand All @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions be/src/olap/base_tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<RowSetSplits>* rs_splits) const {
DCHECK(rs_splits != nullptr && rs_splits->empty());
Expand Down
4 changes: 4 additions & 0 deletions be/src/olap/base_tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RowSetSplits>* rs_splits) const;
Expand Down

0 comments on commit c6a7a4d

Please sign in to comment.