-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor changes. added week 3 day 2 tests. all tests except full compac…
…tion test in week 2 still passing
- Loading branch information
1 parent
31ee0c9
commit 53bfd9d
Showing
4 changed files
with
64 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ mod week2_day4; | |
mod week2_day5; | ||
mod week2_day6; | ||
mod week3_day1; | ||
mod week3_day2; |
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,61 @@ | ||
use std::time::Duration; | ||
|
||
use tempfile::tempdir; | ||
|
||
use crate::{ | ||
compact::CompactionOptions, | ||
lsm_storage::{LsmStorageOptions, MiniLsm}, | ||
tests::harness::dump_files_in_dir, | ||
}; | ||
|
||
#[test] | ||
fn test_task3_compaction_integration() { | ||
let dir = tempdir().unwrap(); | ||
let mut options = LsmStorageOptions::default_for_week2_test(CompactionOptions::NoCompaction); | ||
options.enable_wal = true; | ||
let storage = MiniLsm::open(&dir, options.clone()).unwrap(); | ||
let _txn = storage.new_txn().unwrap(); | ||
for i in 0..=20000 { | ||
storage | ||
.put(b"0", format!("{:02000}", i).as_bytes()) | ||
.unwrap(); | ||
} | ||
std::thread::sleep(Duration::from_secs(1)); // wait until all memtables flush | ||
while { | ||
let snapshot = storage.inner.state.read(); | ||
!snapshot.imm_memtables.is_empty() | ||
} { | ||
storage.inner.force_flush_next_imm_memtable().unwrap(); | ||
} | ||
assert!(storage.inner.state.read().l0_sstables.len() > 1); | ||
storage.force_full_compaction().unwrap(); | ||
storage.dump_structure(); | ||
dump_files_in_dir(&dir); | ||
assert!(storage.inner.state.read().l0_sstables.is_empty()); | ||
assert_eq!(storage.inner.state.read().levels.len(), 1); | ||
// same key in the same SST | ||
assert_eq!(storage.inner.state.read().levels[0].1.len(), 1); | ||
for i in 0..=100 { | ||
storage | ||
.put(b"1", format!("{:02000}", i).as_bytes()) | ||
.unwrap(); | ||
} | ||
storage | ||
.inner | ||
.force_freeze_memtable(&storage.inner.state_lock.lock()) | ||
.unwrap(); | ||
std::thread::sleep(Duration::from_secs(1)); // wait until all memtables flush | ||
while { | ||
let snapshot = storage.inner.state.read(); | ||
!snapshot.imm_memtables.is_empty() | ||
} { | ||
storage.inner.force_flush_next_imm_memtable().unwrap(); | ||
} | ||
storage.force_full_compaction().unwrap(); | ||
storage.dump_structure(); | ||
dump_files_in_dir(&dir); | ||
assert!(storage.inner.state.read().l0_sstables.is_empty()); | ||
assert_eq!(storage.inner.state.read().levels.len(), 1); | ||
// same key in the same SST, now we should split two | ||
assert_eq!(storage.inner.state.read().levels[0].1.len(), 2); | ||
} |