Skip to content

Commit f772321

Browse files
committed
Merge branch 'main' into fix/lockless-ranges
2 parents 7c5a2af + b0e10fc commit f772321

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "lsm-tree"
33
description = "A K.I.S.S. implementation of log-structured merge trees (LSM-trees/LSMTs)"
44
license = "MIT OR Apache-2.0"
5-
version = "2.7.0"
5+
version = "2.7.1"
66
edition = "2021"
77
rust-version = "1.75.0"
88
readme = "README.md"

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)