Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion be/src/olap/base_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ OLAPStatus BaseCompaction::compact() {
TRACE_COUNTER_INCREMENT("input_rowsets_count", _input_rowsets.size());

// 2. do base compaction, merge rowsets
int64_t permits = _tablet->calc_base_compaction_score();
int64_t permits = _tablet->calc_compaction_score(CompactionType::BASE_COMPACTION);
RETURN_NOT_OK(do_compaction(permits));
TRACE("compaction finished");

Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/cumulative_compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ OLAPStatus CumulativeCompaction::compact() {
TRACE_COUNTER_INCREMENT("input_rowsets_count", _input_rowsets.size());

// 3. do cumulative compaction, merge rowsets
int64_t permits = _tablet->calc_cumulative_compaction_score();
int64_t permits = _tablet->calc_compaction_score(CompactionType::CUMULATIVE_COMPACTION);
RETURN_NOT_OK(do_compaction(permits));
TRACE("compaction finished");

Expand Down
10 changes: 6 additions & 4 deletions be/src/olap/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,22 +751,24 @@ bool Tablet::can_do_compaction() {
}

const uint32_t Tablet::calc_compaction_score(CompactionType compaction_type) const {
// Need meta lock, because it will iterator "all_rs_metas" of tablet meta.
ReadLock rdlock(&_meta_lock);
if (compaction_type == CompactionType::CUMULATIVE_COMPACTION) {
return calc_cumulative_compaction_score();
return _calc_cumulative_compaction_score();
} else {
DCHECK_EQ(compaction_type, CompactionType::BASE_COMPACTION);
return calc_base_compaction_score();
return _calc_base_compaction_score();
}
}

const uint32_t Tablet::calc_cumulative_compaction_score() const {
const uint32_t Tablet::_calc_cumulative_compaction_score() const {
uint32_t score = 0;
_cumulative_compaction_policy->calc_cumulative_compaction_score(
_tablet_meta->all_rs_metas(), cumulative_layer_point(), &score);
return score;
}

const uint32_t Tablet::calc_base_compaction_score() const {
const uint32_t Tablet::_calc_base_compaction_score() const {
uint32_t score = 0;
const int64_t point = cumulative_layer_point();
bool base_rowset_exist = false;
Expand Down
5 changes: 3 additions & 2 deletions be/src/olap/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ class Tablet : public BaseTablet {
// operation for compaction
bool can_do_compaction();
const uint32_t calc_compaction_score(CompactionType compaction_type) const;
const uint32_t calc_cumulative_compaction_score() const;
const uint32_t calc_base_compaction_score() const;
static void compute_version_hash_from_rowsets(const std::vector<RowsetSharedPtr>& rowsets,
VersionHash* version_hash);

Expand Down Expand Up @@ -249,6 +247,9 @@ class Tablet : public BaseTablet {
OLAPStatus _capture_consistent_rowsets_unlocked(const vector<Version>& version_path,
vector<RowsetSharedPtr>* rowsets) const;

const uint32_t _calc_cumulative_compaction_score() const;
const uint32_t _calc_base_compaction_score() const;

public:
static const int64_t K_INVALID_CUMULATIVE_POINT = -1;

Expand Down
10 changes: 1 addition & 9 deletions be/src/olap/tablet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,7 @@ TabletSharedPtr TabletManager::find_best_tablet_to_compaction(
}
}

uint32_t table_score = 0;
{
ReadLock rdlock(tablet_ptr->get_header_lock_ptr());
if (compaction_type == CompactionType::BASE_COMPACTION) {
table_score = tablet_ptr->calc_base_compaction_score();
} else if (compaction_type == CompactionType::CUMULATIVE_COMPACTION) {
table_score = tablet_ptr->calc_cumulative_compaction_score();
}
}
uint32_t table_score = tablet_ptr->calc_compaction_score(compaction_type);
if (table_score > highest_score) {
highest_score = table_score;
best_tablet = tablet_ptr;
Expand Down
6 changes: 3 additions & 3 deletions be/test/olap/cumulative_compaction_policy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TEST_F(TestNumBasedCumulativeCompactionPolicy, calc_cumulative_compaction_score)
TabletSharedPtr _tablet(new Tablet(_tablet_meta, nullptr, CUMULATIVE_NUM_BASED_POLICY));
_tablet->init();

const uint32_t score = _tablet->calc_cumulative_compaction_score();
const uint32_t score = _tablet->calc_compaction_score(CompactionType::CUMULATIVE_COMPACTION);

ASSERT_EQ(15, score);
}
Expand Down Expand Up @@ -675,7 +675,7 @@ TEST_F(TestSizeBasedCumulativeCompactionPolicy, calc_cumulative_compaction_score
_tablet->init();
_tablet->calculate_cumulative_point();

const uint32_t score = _tablet->calc_cumulative_compaction_score();
const uint32_t score = _tablet->calc_compaction_score(CompactionType::CUMULATIVE_COMPACTION);

ASSERT_EQ(15, score);
}
Expand All @@ -692,7 +692,7 @@ TEST_F(TestSizeBasedCumulativeCompactionPolicy, calc_cumulative_compaction_score
TabletSharedPtr _tablet(new Tablet(_tablet_meta, nullptr, CUMULATIVE_SIZE_BASED_POLICY));
_tablet->init();
_tablet->calculate_cumulative_point();
const uint32_t score = _tablet->calc_cumulative_compaction_score();
const uint32_t score = _tablet->calc_compaction_score(CompactionType::CUMULATIVE_COMPACTION);

ASSERT_EQ(7, score);
}
Expand Down