Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
Signed-off-by: Little-Wallace <[email protected]>
  • Loading branch information
Little-Wallace committed Apr 24, 2024
1 parent 19e6fb9 commit 145875e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ pub mod default {
const DEFAULT_LEVEL_MULTIPLIER: u64 = 5;
const DEFAULT_MAX_SPACE_RECLAIM_BYTES: u64 = 512 * 1024 * 1024; // 512MB;
const DEFAULT_LEVEL0_STOP_WRITE_THRESHOLD_SUB_LEVEL_NUMBER: u64 = 300;
const DEFAULT_MAX_COMPACTION_FILE_COUNT: u64 = 100;
const DEFAULT_MAX_COMPACTION_FILE_COUNT: u64 = 300;
const DEFAULT_MIN_SUB_LEVEL_COMPACT_LEVEL_COUNT: u32 = 3;
const DEFAULT_MIN_OVERLAPPING_SUB_LEVEL_COMPACT_LEVEL_COUNT: u32 = 12;
const DEFAULT_TOMBSTONE_RATIO_PERCENT: u32 = 40;
Expand Down
2 changes: 1 addition & 1 deletion src/config/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This page is automatically generated by `./risedev generate-example-config`
|--------|-------------|---------|
| compaction_filter_mask | | 6 |
| enable_emergency_picker | | true |
| level0_max_compact_file_number | | 100 |
| level0_max_compact_file_number | | 300 |
| level0_overlapping_sub_level_compact_level_count | | 12 |
| level0_stop_write_threshold_sub_level_number | | 300 |
| level0_sub_level_compact_level_count | | 3 |
Expand Down
2 changes: 1 addition & 1 deletion src/config/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ level0_stop_write_threshold_sub_level_number = 300
level0_sub_level_compact_level_count = 3
level0_overlapping_sub_level_compact_level_count = 12
max_space_reclaim_bytes = 536870912
level0_max_compact_file_number = 100
level0_max_compact_file_number = 300
tombstone_reclaim_ratio = 40
enable_emergency_picker = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl LevelCompactionPicker {
// divide by 2 because we need to select files of base level and it need use the other
// half quota.
std::cmp::max(
self.config.max_bytes_for_level_base,
target_level.total_file_size,
self.config.max_compaction_bytes / 2,
)
};
Expand Down
30 changes: 11 additions & 19 deletions src/meta/src/hummock/compaction/selector/level_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl DynamicLevelSelectorCore {
base_bytes_min + 1
} else {
ctx.base_level = first_non_empty_level;
while ctx.base_level > 1 && cur_level_size > base_bytes_max * 2 {
while ctx.base_level > 1 && cur_level_size > base_bytes_max {
ctx.base_level -= 1;
cur_level_size /= self.config.max_bytes_for_level_multiplier;
}
Expand Down Expand Up @@ -485,6 +485,7 @@ pub mod tests {
use risingwave_common::constants::hummock::CompactionFilterFlag;
use risingwave_pb::hummock::compaction_config::CompactionMode;
use risingwave_pb::hummock::hummock_version::Levels;
use risingwave_pb::hummock::OverlappingLevel;

use crate::hummock::compaction::compaction_config::CompactionConfigBuilder;
use crate::hummock::compaction::selector::tests::{
Expand Down Expand Up @@ -739,17 +740,17 @@ pub mod tests {
assert_eq!(15000, levels.levels.get(2).unwrap().total_file_size); // l3
assert_eq!(10000, levels.levels.get(3).unwrap().total_file_size); // l4

assert_eq!(100, ctx.level_max_bytes[1]); // l1
assert_eq!(500, ctx.level_max_bytes[2]); // l2
assert_eq!(2500, ctx.level_max_bytes[3]); // l3
assert_eq!(12500, ctx.level_max_bytes[4]); // l4
assert_eq!(200, ctx.level_max_bytes[1]); // l1
assert_eq!(1000, ctx.level_max_bytes[2]); // l2
assert_eq!(5000, ctx.level_max_bytes[3]); // l3
assert_eq!(25000, ctx.level_max_bytes[4]); // l4

// l1 pending = (0 + 1000 - 100) * ((25000 / 1000) + 1) + 1000 = 24400
// l2 pending = (25000 + 900 - 500) * ((15000 / (25000 + 900)) + 1) = 40110
// l3 pending = (15000 + 25400 - 2500) * ((10000 / (15000 + 25400) + 1)) = 47281
// l1 pending = (0 + 1000 - 200) * ((25000 / 1000) + 1) + 1000 = 21800
// l2 pending = (25000 + 800 - 1000) * ((15000 / (25000 + 800)) + 1) = 39218
// l3 pending = (15000 + 24800 - 5000) * ((10000 / (15000 + 24800) + 1)) = 43543

let compact_pending_bytes = dynamic_level_core.compact_pending_bytes_needed(&levels);
assert_eq!(24400 + 40110 + 47281, compact_pending_bytes);
assert_eq!(21800 + 39218 + 43543, compact_pending_bytes);
}

#[test]
Expand All @@ -771,12 +772,7 @@ pub mod tests {
levels[5].total_file_size = 3125 * 2048 * 1024 * 1024;
let levels = Levels {
levels,
l0: Some(generate_l0_nonoverlapping_sublevels(generate_tables(
15..25,
0..600,
3,
100,
))),
l0: Some(OverlappingLevel::default()),
..Default::default()
};
let config = Arc::new(config);
Expand All @@ -786,14 +782,10 @@ pub mod tests {
);
let ctx = dynamic_level_core.calculate_level_base_size(&levels);
assert!(ctx.level_max_bytes[0] > config.max_bytes_for_level_base);
for (idx, sz) in ctx.level_max_bytes.iter().enumerate() {
println!("level[{}]: {}MB", idx, *sz / 1024 / 1024);
}
let levels_handlers = (0..7).map(LevelHandler::new).collect_vec();
let ctx = dynamic_level_core.get_priority_levels(&levels, &levels_handlers);
for info in &ctx.score_levels {
assert_eq!(info.score, 100);
}

}
}

0 comments on commit 145875e

Please sign in to comment.