-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Chi <iskyzh@gmail.com>
- Loading branch information
Showing
12 changed files
with
206 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ mod week2_day1; | |
mod week2_day2; | ||
mod week2_day3; | ||
mod week2_day4; | ||
mod week2_day5; | ||
mod week2_day6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use tempfile::tempdir; | ||
|
||
use crate::{ | ||
compact::{ | ||
CompactionOptions, LeveledCompactionOptions, SimpleLeveledCompactionOptions, | ||
TieredCompactionOptions, | ||
}, | ||
lsm_storage::{LsmStorageOptions, MiniLsm}, | ||
tests::harness::dump_files_in_dir, | ||
}; | ||
|
||
#[test] | ||
fn test_integration_leveled() { | ||
test_integration(CompactionOptions::Leveled(LeveledCompactionOptions { | ||
level_size_multiplier: 2, | ||
level0_file_num_compaction_trigger: 2, | ||
max_levels: 3, | ||
base_level_size_mb: 1, | ||
})) | ||
} | ||
|
||
#[test] | ||
fn test_integration_tiered() { | ||
test_integration(CompactionOptions::Tiered(TieredCompactionOptions { | ||
num_tiers: 3, | ||
max_size_amplification_percent: 200, | ||
size_ratio: 1, | ||
min_merge_width: 3, | ||
})) | ||
} | ||
|
||
#[test] | ||
fn test_integration_simple() { | ||
test_integration(CompactionOptions::Simple(SimpleLeveledCompactionOptions { | ||
size_ratio_percent: 200, | ||
level0_file_num_compaction_trigger: 2, | ||
max_levels: 3, | ||
})); | ||
} | ||
|
||
fn test_integration(compaction_options: CompactionOptions) { | ||
let dir = tempdir().unwrap(); | ||
let storage = MiniLsm::open( | ||
&dir, | ||
LsmStorageOptions::default_for_week2_test(compaction_options.clone()), | ||
) | ||
.unwrap(); | ||
for i in 0..=20 { | ||
storage.put(b"0", format!("v{}", i).as_bytes()).unwrap(); | ||
if i % 2 == 0 { | ||
storage.put(b"1", format!("v{}", i).as_bytes()).unwrap(); | ||
} else { | ||
storage.delete(b"1").unwrap(); | ||
} | ||
if i % 2 == 1 { | ||
storage.put(b"2", format!("v{}", i).as_bytes()).unwrap(); | ||
} else { | ||
storage.delete(b"2").unwrap(); | ||
} | ||
storage | ||
.inner | ||
.force_freeze_memtable(&storage.inner.state_lock.lock()) | ||
.unwrap(); | ||
} | ||
storage.close().unwrap(); | ||
// ensure all SSTs are flushed | ||
assert!(storage.inner.state.read().memtable.is_empty()); | ||
assert!(storage.inner.state.read().imm_memtables.is_empty()); | ||
storage.dump_structure(); | ||
drop(storage); | ||
dump_files_in_dir(&dir); | ||
|
||
let storage = MiniLsm::open( | ||
&dir, | ||
LsmStorageOptions::default_for_week2_test(compaction_options.clone()), | ||
) | ||
.unwrap(); | ||
assert_eq!(&storage.get(b"0").unwrap().unwrap()[..], b"v20".as_slice()); | ||
assert_eq!(&storage.get(b"1").unwrap().unwrap()[..], b"v20".as_slice()); | ||
assert_eq!(storage.get(b"2").unwrap(), None); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use tempfile::tempdir; | ||
|
||
use crate::{ | ||
compact::{ | ||
CompactionOptions, LeveledCompactionOptions, SimpleLeveledCompactionOptions, | ||
TieredCompactionOptions, | ||
}, | ||
lsm_storage::{LsmStorageOptions, MiniLsm}, | ||
tests::harness::dump_files_in_dir, | ||
}; | ||
|
||
#[test] | ||
fn test_integration_leveled() { | ||
test_integration(CompactionOptions::Leveled(LeveledCompactionOptions { | ||
level_size_multiplier: 2, | ||
level0_file_num_compaction_trigger: 2, | ||
max_levels: 3, | ||
base_level_size_mb: 1, | ||
})) | ||
} | ||
|
||
#[test] | ||
fn test_integration_tiered() { | ||
test_integration(CompactionOptions::Tiered(TieredCompactionOptions { | ||
num_tiers: 3, | ||
max_size_amplification_percent: 200, | ||
size_ratio: 1, | ||
min_merge_width: 3, | ||
})) | ||
} | ||
|
||
#[test] | ||
fn test_integration_simple() { | ||
test_integration(CompactionOptions::Simple(SimpleLeveledCompactionOptions { | ||
size_ratio_percent: 200, | ||
level0_file_num_compaction_trigger: 2, | ||
max_levels: 3, | ||
})); | ||
} | ||
|
||
fn test_integration(compaction_options: CompactionOptions) { | ||
let dir = tempdir().unwrap(); | ||
let mut options = LsmStorageOptions::default_for_week2_test(compaction_options); | ||
options.enable_wal = true; | ||
let storage = MiniLsm::open(&dir, options.clone()).unwrap(); | ||
for i in 0..=20 { | ||
storage.put(b"0", format!("v{}", i).as_bytes()).unwrap(); | ||
if i % 2 == 0 { | ||
storage.put(b"1", format!("v{}", i).as_bytes()).unwrap(); | ||
} else { | ||
storage.delete(b"1").unwrap(); | ||
} | ||
if i % 2 == 1 { | ||
storage.put(b"2", format!("v{}", i).as_bytes()).unwrap(); | ||
} else { | ||
storage.delete(b"2").unwrap(); | ||
} | ||
storage | ||
.inner | ||
.force_freeze_memtable(&storage.inner.state_lock.lock()) | ||
.unwrap(); | ||
} | ||
storage.close().unwrap(); | ||
// ensure some SSTs are not flushed | ||
assert!( | ||
!storage.inner.state.read().memtable.is_empty() | ||
|| !storage.inner.state.read().imm_memtables.is_empty() | ||
); | ||
storage.dump_structure(); | ||
drop(storage); | ||
dump_files_in_dir(&dir); | ||
|
||
let storage = MiniLsm::open(&dir, options).unwrap(); | ||
assert_eq!(&storage.get(b"0").unwrap().unwrap()[..], b"v20".as_slice()); | ||
assert_eq!(&storage.get(b"1").unwrap().unwrap()[..], b"v20".as_slice()); | ||
assert_eq!(storage.get(b"2").unwrap(), None); | ||
} |