Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Dec 24, 2024
1 parent 2c475b5 commit 621196e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ DEFINE_mBool(enable_sleep_between_delete_cumu_compaction, "false");
DEFINE_mInt32(compaction_num_per_round, "1");

// the max length of segments key bounds, in bytes
DEFINE_mInt32(segments_key_bounds_truncation_threshold, "100");
DEFINE_mInt32(segments_key_bounds_truncation_threshold, "-1");

// clang-format off
#ifdef BE_TEST
Expand Down
8 changes: 4 additions & 4 deletions be/src/olap/base_tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ bool BaseTablet::key_is_not_in_segment(Slice key, const KeyBoundsPB& segment_key
bool is_segments_key_bounds_truncated) {
Slice maybe_truncated_min_key {segment_key_bounds.min_key()};
Slice maybe_truncated_max_key {segment_key_bounds.max_key()};
return Slice::origin_is_strictly_less_than(key, false, maybe_truncated_min_key,
is_segments_key_bounds_truncated) ||
Slice::origin_is_strictly_less_than(maybe_truncated_max_key,
is_segments_key_bounds_truncated, key, false);
return Slice::lhs_is_strictly_less_than_rhs(key, false, maybe_truncated_min_key,
is_segments_key_bounds_truncated) ||
Slice::lhs_is_strictly_less_than_rhs(maybe_truncated_max_key,
is_segments_key_bounds_truncated, key, false);
}

Status BaseTablet::lookup_row_key(const Slice& encoded_key, TabletSchema* latest_schema,
Expand Down
4 changes: 2 additions & 2 deletions be/src/olap/compaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ bool is_rowset_tidy(std::string& pre_max_key, bool& pre_rs_key_bounds_truncated,
return false;
}
bool cur_rs_key_bounds_truncated {rhs->is_segments_key_bounds_truncated()};
if (!Slice::origin_is_strictly_less_than(Slice {pre_max_key}, pre_rs_key_bounds_truncated,
Slice {min_key}, cur_rs_key_bounds_truncated)) {
if (!Slice::lhs_is_strictly_less_than_rhs(Slice {pre_max_key}, pre_rs_key_bounds_truncated,
Slice {min_key}, cur_rs_key_bounds_truncated)) {
return false;
}
CHECK(rhs->last_key(&pre_max_key));
Expand Down
13 changes: 6 additions & 7 deletions be/src/olap/rowset/rowset_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,17 @@ void RowsetMeta::set_segments_key_bounds(const std::vector<KeyBoundsPB>& segment
*new_key_bounds = key_bounds;
}

bool enable_truncated {config::segments_key_bounds_truncation_threshold > 0};
int32_t truncation_threshold = config::segments_key_bounds_truncation_threshold;
bool really_do_truncation {false};
if (enable_truncated) {
int32_t threshold = config::segments_key_bounds_truncation_threshold;
if (truncation_threshold > 0) {
for (auto& segment_key_bounds : *_rowset_meta_pb.mutable_segments_key_bounds()) {
if (segment_key_bounds.min_key().size() > threshold) {
if (segment_key_bounds.min_key().size() > truncation_threshold) {
really_do_truncation = true;
segment_key_bounds.mutable_min_key()->resize(threshold);
segment_key_bounds.mutable_min_key()->resize(truncation_threshold);
}
if (segment_key_bounds.max_key().size() > threshold) {
if (segment_key_bounds.max_key().size() > truncation_threshold) {
really_do_truncation = true;
segment_key_bounds.mutable_max_key()->resize(threshold);
segment_key_bounds.mutable_max_key()->resize(truncation_threshold);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions be/src/util/slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Slice::Slice(const faststring& s)
data((char*)(s.data())),
size(s.size()) {}

bool Slice::origin_is_strictly_less_than(Slice X, bool X_is_truncated, Slice Y,
bool Y_is_truncated) {
bool Slice::lhs_is_strictly_less_than_rhs(Slice X, bool X_is_truncated, Slice Y,
[[maybe_unused]] bool Y_is_truncated) {
// suppose X is a prefix of X', Y is a prefix of Y'
if (!X_is_truncated) {
// (X_is_truncated == false) means X' == X
Expand Down
4 changes: 2 additions & 2 deletions be/src/util/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ struct Slice {
// Y is (maybe) a truncated prefix of string Y'
// return true only if we can determine that X' is strictly less than Y'
// based on these maybe truncated prefixes
static bool origin_is_strictly_less_than(Slice X, bool X_is_truncated, Slice Y,
bool Y_is_truncated);
static bool lhs_is_strictly_less_than_rhs(Slice X, bool X_is_truncated, Slice Y,
bool Y_is_truncated);
};

inline std::ostream& operator<<(std::ostream& os, const Slice& slice) {
Expand Down
6 changes: 3 additions & 3 deletions be/src/vec/olap/block_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ bool BlockReader::_rowsets_not_mono_asc_disjoint(const ReaderParams& read_params
}
bool cur_rs_key_bounds_truncated {
rs_split.rs_reader->rowset()->is_segments_key_bounds_truncated()};
if (!Slice::origin_is_strictly_less_than(Slice {pre_rs_last_key},
pre_rs_key_bounds_truncated, Slice {rs_first_key},
cur_rs_key_bounds_truncated)) {
if (!Slice::lhs_is_strictly_less_than_rhs(Slice {pre_rs_last_key},
pre_rs_key_bounds_truncated, Slice {rs_first_key},
cur_rs_key_bounds_truncated)) {
return true;
}
bool has_last_key = rs_split.rs_reader->rowset()->last_key(&pre_rs_last_key);
Expand Down
6 changes: 3 additions & 3 deletions be/test/olap/segments_key_bounds_truncation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class SegmentsKeyBoundsTruncationTest : public testing::Test {
};

TEST_F(SegmentsKeyBoundsTruncationTest, CompareFuncTest) {
// test `Slice::origin_is_strictly_less_than`
// test `Slice::lhs_is_strictly_less_than_rhs`
// enumerating all possible combinations
// this test is reduntant, n = 3 is enough
constexpr int n = 8;
Expand Down Expand Up @@ -363,8 +363,8 @@ TEST_F(SegmentsKeyBoundsTruncationTest, CompareFuncTest) {
b.truncate(l2);
}

bool res1 = Slice::origin_is_strictly_less_than(a, X_is_truncated, b,
Y_is_truncated);
bool res1 = Slice::lhs_is_strictly_less_than_rhs(a, X_is_truncated, b,
Y_is_truncated);
bool res2 = (X.compare(Y) < 0);
++total;
if (res1 && res2) {
Expand Down

0 comments on commit 621196e

Please sign in to comment.