@@ -70,6 +70,12 @@ pub struct MockStorage {
|
||||
total_writes: usize,
|
||||
}
|
||||
|
||||
impl Default for MockStorage {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl MockStorage {
|
||||
pub fn new() -> Self {
|
||||
let snapshot = LsmStorageState {
|
||||
@@ -206,8 +212,8 @@ fn generate_random_split(
|
||||
let ne = begin + len * (i + 1) / split - 1;
|
||||
let mut begin_bytes = BytesMut::new();
|
||||
let mut end_bytes = BytesMut::new();
|
||||
begin_bytes.put_u64(nb as u64);
|
||||
end_bytes.put_u64(ne as u64);
|
||||
begin_bytes.put_u64(nb);
|
||||
end_bytes.put_u64(ne);
|
||||
result.push((begin_bytes.into(), end_bytes.into()));
|
||||
}
|
||||
result
|
||||
|
@@ -51,13 +51,13 @@ impl CompactionController {
|
||||
pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> {
|
||||
match self {
|
||||
CompactionController::Leveled(ctrl) => ctrl
|
||||
.generate_compaction_task(&snapshot)
|
||||
.generate_compaction_task(snapshot)
|
||||
.map(CompactionTask::Leveled),
|
||||
CompactionController::Simple(ctrl) => ctrl
|
||||
.generate_compaction_task(&snapshot)
|
||||
.generate_compaction_task(snapshot)
|
||||
.map(CompactionTask::Simple),
|
||||
CompactionController::Tiered(ctrl) => ctrl
|
||||
.generate_compaction_task(&snapshot)
|
||||
.generate_compaction_task(snapshot)
|
||||
.map(CompactionTask::Tiered),
|
||||
CompactionController::NoCompaction => unreachable!(),
|
||||
}
|
||||
@@ -71,13 +71,13 @@ impl CompactionController {
|
||||
) -> (LsmStorageState, Vec<usize>) {
|
||||
match (self, task) {
|
||||
(CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => {
|
||||
ctrl.apply_compaction_result(&snapshot, task, output)
|
||||
ctrl.apply_compaction_result(snapshot, task, output)
|
||||
}
|
||||
(CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => {
|
||||
ctrl.apply_compaction_result(&snapshot, task, output)
|
||||
ctrl.apply_compaction_result(snapshot, task, output)
|
||||
}
|
||||
(CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => {
|
||||
ctrl.apply_compaction_result(&snapshot, task, output)
|
||||
ctrl.apply_compaction_result(snapshot, task, output)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -86,11 +86,10 @@ impl CompactionController {
|
||||
|
||||
impl CompactionController {
|
||||
pub fn flush_to_l0(&self) -> bool {
|
||||
if let Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(
|
||||
self,
|
||||
Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +163,6 @@ impl LsmStorageInner {
|
||||
}
|
||||
}
|
||||
});
|
||||
return Ok(Some(handle));
|
||||
Ok(Some(handle))
|
||||
}
|
||||
}
|
||||
|
@@ -57,13 +57,13 @@ impl CompactionController {
|
||||
pub fn generate_compaction_task(&self, snapshot: &LsmStorageState) -> Option<CompactionTask> {
|
||||
match self {
|
||||
CompactionController::Leveled(ctrl) => ctrl
|
||||
.generate_compaction_task(&snapshot)
|
||||
.generate_compaction_task(snapshot)
|
||||
.map(CompactionTask::Leveled),
|
||||
CompactionController::Simple(ctrl) => ctrl
|
||||
.generate_compaction_task(&snapshot)
|
||||
.generate_compaction_task(snapshot)
|
||||
.map(CompactionTask::Simple),
|
||||
CompactionController::Tiered(ctrl) => ctrl
|
||||
.generate_compaction_task(&snapshot)
|
||||
.generate_compaction_task(snapshot)
|
||||
.map(CompactionTask::Tiered),
|
||||
CompactionController::NoCompaction => unreachable!(),
|
||||
}
|
||||
@@ -77,13 +77,13 @@ impl CompactionController {
|
||||
) -> (LsmStorageState, Vec<usize>) {
|
||||
match (self, task) {
|
||||
(CompactionController::Leveled(ctrl), CompactionTask::Leveled(task)) => {
|
||||
ctrl.apply_compaction_result(&snapshot, task, output)
|
||||
ctrl.apply_compaction_result(snapshot, task, output)
|
||||
}
|
||||
(CompactionController::Simple(ctrl), CompactionTask::Simple(task)) => {
|
||||
ctrl.apply_compaction_result(&snapshot, task, output)
|
||||
ctrl.apply_compaction_result(snapshot, task, output)
|
||||
}
|
||||
(CompactionController::Tiered(ctrl), CompactionTask::Tiered(task)) => {
|
||||
ctrl.apply_compaction_result(&snapshot, task, output)
|
||||
ctrl.apply_compaction_result(snapshot, task, output)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -92,11 +92,10 @@ impl CompactionController {
|
||||
|
||||
impl CompactionController {
|
||||
pub fn flush_to_l0(&self) -> bool {
|
||||
if let Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(
|
||||
self,
|
||||
Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,10 +378,11 @@ impl LsmStorageInner {
|
||||
}
|
||||
|
||||
fn trigger_flush(&self) -> Result<()> {
|
||||
if {
|
||||
let res = {
|
||||
let state = self.state.read();
|
||||
state.imm_memtables.len() >= self.options.num_memtable_limit
|
||||
} {
|
||||
};
|
||||
if res {
|
||||
self.force_flush_next_imm_memtable()?;
|
||||
}
|
||||
|
||||
@@ -405,6 +405,6 @@ impl LsmStorageInner {
|
||||
}
|
||||
}
|
||||
});
|
||||
return Ok(Some(handle));
|
||||
Ok(Some(handle))
|
||||
}
|
||||
}
|
||||
|
@@ -78,7 +78,7 @@ impl LeveledCompactionController {
|
||||
.sum::<u64>() as usize,
|
||||
);
|
||||
}
|
||||
let base_level_size_bytes = self.options.base_level_size_mb as usize * 1024 * 1024;
|
||||
let base_level_size_bytes = self.options.base_level_size_mb * 1024 * 1024;
|
||||
|
||||
// select base level and compute target level size
|
||||
target_level_size[self.options.max_levels - 1] =
|
||||
|
@@ -71,22 +71,18 @@ impl SstConcatIterator {
|
||||
}
|
||||
|
||||
fn move_until_valid(&mut self) -> Result<()> {
|
||||
loop {
|
||||
if let Some(iter) = self.current.as_mut() {
|
||||
if iter.is_valid() {
|
||||
break;
|
||||
}
|
||||
if self.next_sst_idx >= self.sstables.len() {
|
||||
self.current = None;
|
||||
} else {
|
||||
self.current = Some(SsTableIterator::create_and_seek_to_first(
|
||||
self.sstables[self.next_sst_idx].clone(),
|
||||
)?);
|
||||
self.next_sst_idx += 1;
|
||||
}
|
||||
} else {
|
||||
while let Some(iter) = self.current.as_mut() {
|
||||
if iter.is_valid() {
|
||||
break;
|
||||
}
|
||||
if self.next_sst_idx >= self.sstables.len() {
|
||||
self.current = None;
|
||||
} else {
|
||||
self.current = Some(SsTableIterator::create_and_seek_to_first(
|
||||
self.sstables[self.next_sst_idx].clone(),
|
||||
)?);
|
||||
self.next_sst_idx += 1;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -22,10 +22,8 @@ impl<A: StorageIterator, B: StorageIterator> TwoMergeIterator<A, B> {
|
||||
}
|
||||
|
||||
fn skip_b(&mut self) -> Result<()> {
|
||||
if self.a.is_valid() {
|
||||
if self.b.is_valid() && self.b.key() == self.a.key() {
|
||||
self.b.next()?;
|
||||
}
|
||||
if self.a.is_valid() && self.b.is_valid() && self.b.key() == self.a.key() {
|
||||
self.b.next()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -336,7 +336,7 @@ impl LsmStorageInner {
|
||||
for table_id in state
|
||||
.l0_sstables
|
||||
.iter()
|
||||
.chain(state.levels.iter().map(|(_, files)| files).flatten())
|
||||
.chain(state.levels.iter().flat_map(|(_, files)| files))
|
||||
{
|
||||
let table_id = *table_id;
|
||||
let sst = SsTable::open(
|
||||
|
@@ -43,9 +43,9 @@ impl Manifest {
|
||||
.context("failed to recover manifest")?;
|
||||
let mut buf = Vec::new();
|
||||
file.read_to_end(&mut buf)?;
|
||||
let mut stream = Deserializer::from_slice(&buf).into_iter::<ManifestRecord>();
|
||||
let stream = Deserializer::from_slice(&buf).into_iter::<ManifestRecord>();
|
||||
let mut records = Vec::new();
|
||||
while let Some(x) = stream.next() {
|
||||
for x in stream {
|
||||
records.push(x?);
|
||||
}
|
||||
Ok((
|
||||
|
@@ -71,7 +71,7 @@ fn test_task3_block_key_compression() {
|
||||
}
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("1.sst");
|
||||
let sst = builder.build_for_test(&path).unwrap();
|
||||
let sst = builder.build_for_test(path).unwrap();
|
||||
assert!(
|
||||
sst.block_meta.len() <= 25,
|
||||
"you have {} blocks, expect 25",
|
||||
|
Reference in New Issue
Block a user