|
3 | 3 | // (found in the LICENSE-* files in the repository)
|
4 | 4 |
|
5 | 5 | use super::{Choice, CompactionStrategy, Input as CompactionInput};
|
6 |
| -use crate::{level_manifest::LevelManifest, Config, Segment}; |
| 6 | +use crate::{level_manifest::LevelManifest, Config, HashSet, Segment}; |
7 | 7 |
|
8 | 8 | fn desired_level_size_in_bytes(level_idx: u8, ratio: u8, base_size: u32) -> usize {
|
9 | 9 | (ratio as usize).pow(u32::from(level_idx + 1)) * (base_size as usize)
|
@@ -102,7 +102,29 @@ impl CompactionStrategy for Strategy {
|
102 | 102 | segments_to_compact.push(segment);
|
103 | 103 | }
|
104 | 104 |
|
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 | + } |
106 | 128 |
|
107 | 129 | return Choice::Merge(CompactionInput {
|
108 | 130 | segment_ids,
|
|
0 commit comments