Skip to content

Commit

Permalink
[enhancement](merge-on-write) consider version count on size-based cu…
Browse files Browse the repository at this point in the history
… compaction policy (apache#25352)
  • Loading branch information
zhannngchen authored Oct 13, 2023
1 parent 96f31ae commit 9cc0e95
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ DEFINE_mDouble(compaction_promotion_ratio, "0.05");
// rowset will be not given to base compaction. The unit is m byte.
DEFINE_mInt64(compaction_promotion_min_size_mbytes, "128");

// When output rowset of cumulative compaction total version count (end_version - start_version)
// exceed this config count, the rowset will be moved to base compaction
// NOTE: this config will work for unique key merge-on-write table only, to reduce version count
// related cost on delete bitmap more effectively.
DEFINE_mInt64(compaction_promotion_version_count, "1000");

// The lower bound size to do cumulative compaction. When total disk size of candidate rowsets is less than
// this size, size_based policy may not do to cumulative compaction. The unit is m byte.
DEFINE_mInt64(compaction_min_size_mbytes, "64");
Expand Down
6 changes: 6 additions & 0 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ DECLARE_mDouble(compaction_promotion_ratio);
// rowset will be not given to base compaction. The unit is m byte.
DECLARE_mInt64(compaction_promotion_min_size_mbytes);

// When output rowset of cumulative compaction total version count (end_version - start_version)
// exceed this config count, the rowset will be moved to base compaction
// NOTE: this config will work for unique key merge-on-write table only, to reduce version count
// related cost on delete bitmap more effectively.
DECLARE_mInt64(compaction_promotion_version_count);

// The lower bound size to do cumulative compaction. When total disk size of candidate rowsets is less than
// this size, size_based policy may not do to cumulative compaction. The unit is m byte.
DECLARE_mInt64(compaction_min_size_mbytes);
Expand Down
12 changes: 11 additions & 1 deletion be/src/olap/cumulative_compaction_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ namespace doris {

SizeBasedCumulativeCompactionPolicy::SizeBasedCumulativeCompactionPolicy(
int64_t promotion_size, double promotion_ratio, int64_t promotion_min_size,
int64_t compaction_min_size)
int64_t promotion_version_count, int64_t compaction_min_size)
: _promotion_size(promotion_size),
_promotion_ratio(promotion_ratio),
_promotion_min_size(promotion_min_size),
_promotion_version_count(promotion_version_count),
_compaction_min_size(compaction_min_size) {}

void SizeBasedCumulativeCompactionPolicy::calculate_cumulative_point(
Expand Down Expand Up @@ -152,6 +153,15 @@ void SizeBasedCumulativeCompactionPolicy::update_cumulative_point(
size_t total_size = output_rowset->rowset_meta()->total_disk_size();
if (total_size >= tablet->cumulative_promotion_size()) {
tablet->set_cumulative_layer_point(output_rowset->end_version() + 1);
} else if (tablet->enable_unique_key_merge_on_write() &&
output_rowset->end_version() - output_rowset->start_version() >
_promotion_version_count) {
// for MoW table, if there's too many versions, the delete bitmap will grow to
// a very big size, which may cause the tablet meta too big and the `save_meta`
// operation too slow.
// if the rowset should not promotion according to it's disk size, we should also
// consider it's version count here.
tablet->set_cumulative_layer_point(output_rowset->end_version() + 1);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions be/src/olap/cumulative_compaction_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class SizeBasedCumulativeCompactionPolicy final : public CumulativeCompactionPol
int64_t promotion_size = config::compaction_promotion_size_mbytes * 1024 * 1024,
double promotion_ratio = config::compaction_promotion_ratio,
int64_t promotion_min_size = config::compaction_promotion_min_size_mbytes * 1024 * 1024,
int64_t promotion_version_count = config::compaction_promotion_version_count,
int64_t compaction_min_size = config::compaction_min_size_mbytes * 1024 * 1024);

/// Destructor function of SizeBasedCumulativeCompactionPolicy.
Expand Down Expand Up @@ -169,6 +170,8 @@ class SizeBasedCumulativeCompactionPolicy final : public CumulativeCompactionPol
double _promotion_ratio;
/// cumulative compaction promotion min size, unit is byte.
int64_t _promotion_min_size;
// cululative compaction promotion version count, only works for unique key MoW table
int64_t _promotion_version_count;
/// lower bound size to do compaction compaction.
int64_t _compaction_min_size;
};
Expand Down

0 comments on commit 9cc0e95

Please sign in to comment.