Skip to content

Commit d7c1fb7

Browse files
committed
overwrite Lmax in size tiered compaction
1 parent ecec40c commit d7c1fb7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/compaction/tiered.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// (found in the LICENSE-* files in the repository)
44

55
use super::{Choice, CompactionStrategy, Input as CompactionInput};
6-
use crate::{level_manifest::LevelManifest, Config, Segment};
6+
use crate::{level_manifest::LevelManifest, Config, HashSet, Segment};
77

88
fn desired_level_size_in_bytes(level_idx: u8, ratio: u8, base_size: u32) -> usize {
99
(ratio as usize).pow(u32::from(level_idx + 1)) * (base_size as usize)
@@ -102,7 +102,29 @@ impl CompactionStrategy for Strategy {
102102
segments_to_compact.push(segment);
103103
}
104104

105-
let segment_ids = segments_to_compact.iter().map(Segment::id).collect();
105+
let mut segment_ids: HashSet<_> =
106+
segments_to_compact.iter().map(Segment::id).collect();
107+
108+
// NOTE: If dest level is the last level, just overwrite it
109+
//
110+
// If we didn't overwrite Lmax, it would end up amassing more and more
111+
// segments
112+
// Also, because it's the last level, the frequency of overwiting it is
113+
// amortized because of the LSM-tree's level structure
114+
if next_level_index == 6 {
115+
// Wait for L6 to be non-busy
116+
if levels.busy_levels().contains(&next_level_index) {
117+
continue;
118+
}
119+
120+
segment_ids.extend(
121+
levels
122+
.levels
123+
.last()
124+
.expect("last level should always exist")
125+
.list_ids(),
126+
);
127+
}
106128

107129
return Choice::Merge(CompactionInput {
108130
segment_ids,

0 commit comments

Comments
 (0)