#![allow(dead_code)]
use std::fs;
use std::path::Path;
use regolith::{Db, Options};
use tempfile::TempDir;
pub fn small_opts() -> Options {
Options {
write_buffer_size: 4 * 1024,
..Options::default()
}
}
pub fn open(dir: &TempDir) -> Db {
Db::open(dir.path(), small_opts()).unwrap()
}
pub fn fill_sequential(db: &Db, count: usize) {
for i in 0..count {
let k = format!("key_{:06}", i);
let v = format!("val_{:06}", i);
db.put(k.as_bytes(), v.as_bytes()).unwrap();
}
}
pub fn verify_sequential_keys(db: &Db, count: usize) {
for i in 0..count {
let k = format!("key_{:06}", i);
let v = format!("val_{:06}", i);
assert_eq!(
db.get(k.as_bytes()).unwrap(),
Some(v.as_bytes().to_vec()),
"key {:?} missing or wrong value",
k,
);
}
}
pub fn count_sst_files(db_dir: &Path) -> usize {
count_with_extension(&db_dir.join("sst"), "sst")
}
pub fn count_wal_files(db_dir: &Path) -> usize {
count_with_extension(&db_dir.join("wal"), "log")
}
fn count_with_extension(dir: &Path, ext: &str) -> usize {
if !dir.is_dir() {
return 0;
}
fs::read_dir(dir)
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| e.path().extension().and_then(|s| s.to_str()) == Some(ext))
.count()
}
pub fn force_compaction(db: &Db) {
db.compact_range(None, None).unwrap();
}
pub mod fault;