risingwave_meta/hummock/model/
compaction_group_config.rs1use std::sync::Arc;
16
17use risingwave_hummock_sdk::CompactionGroupId;
18use risingwave_pb::hummock::CompactionConfig;
19
20#[derive(Debug, Default, Clone, PartialEq)]
21pub struct CompactionGroup {
22 pub group_id: CompactionGroupId,
23 pub compaction_config: Arc<CompactionConfig>,
24}
25
26impl CompactionGroup {
27 pub fn new(group_id: CompactionGroupId, compaction_config: CompactionConfig) -> Self {
28 Self {
29 group_id,
30 compaction_config: Arc::new(compaction_config),
31 }
32 }
33
34 pub fn group_id(&self) -> CompactionGroupId {
35 self.group_id
36 }
37
38 pub fn compaction_config(&self) -> Arc<CompactionConfig> {
39 self.compaction_config.clone()
40 }
41}
42
43impl From<&risingwave_pb::hummock::CompactionGroup> for CompactionGroup {
44 fn from(compaction_group: &risingwave_pb::hummock::CompactionGroup) -> Self {
45 Self {
46 group_id: compaction_group.id,
47 compaction_config: Arc::new(
48 compaction_group
49 .compaction_config
50 .as_ref()
51 .cloned()
52 .unwrap(),
53 ),
54 }
55 }
56}
57
58impl From<&CompactionGroup> for risingwave_pb::hummock::CompactionGroup {
59 fn from(compaction_group: &CompactionGroup) -> Self {
60 Self {
61 id: compaction_group.group_id,
62 compaction_config: Some(compaction_group.compaction_config.as_ref().clone()),
63 }
64 }
65}
66
67impl CompactionGroup {
68 pub fn max_estimated_group_size(&self) -> u64 {
69 let max_level = self.compaction_config.max_level as usize;
70 let base_level_size = self.compaction_config.max_bytes_for_level_base;
71 let level_multiplier = self.compaction_config.max_bytes_for_level_multiplier;
72
73 fn size_for_levels(level_index: usize, base_size: u64, multiplier: u64) -> u64 {
74 if level_index == 0 {
75 base_size
76 } else {
77 base_size * multiplier.pow(level_index as u32)
78 }
79 }
80
81 (0..max_level)
82 .map(|level_index| size_for_levels(level_index, base_level_size, level_multiplier))
83 .sum()
84 }
85}