Skip to content

Commit

Permalink
chore: codefmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Oct 28, 2024
1 parent b4f6136 commit cf742b9
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 223 deletions.
4 changes: 1 addition & 3 deletions examples/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ async fn main() {
// make sure the path exists
let _ = fs::create_dir_all("./db_path/users").await;

let options = DbOption::from_path(Path::from_filesystem_path("./db_path/users").unwrap())
.await
.unwrap();
let options = DbOption::from(Path::from_filesystem_path("./db_path/users").unwrap());
// pluggable async runtime and I/O
let db = DB::new(options, TokioExecutor::default()).await.unwrap();

Expand Down
66 changes: 37 additions & 29 deletions src/compaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,21 @@ where
.await?;

streams.push(ScanStream::SsTable {
inner: SsTable::open(option, file, scope.gen, !is_local)
.await?
.scan(
(Bound::Unbounded, Bound::Unbounded),
u32::MAX.into(),
None,
ProjectionMask::all(),
)
.await?,
inner: SsTable::open(
file,
scope.gen,
!is_local,
version.range_cache(),
version.meta_cache(),
)
.await?
.scan(
(Bound::Unbounded, Bound::Unbounded),
u32::MAX.into(),
None,
ProjectionMask::all(),
)
.await?,
});
}
} else {
Expand Down Expand Up @@ -525,7 +531,7 @@ pub(crate) mod tests {
tests::Test,
timestamp::Timestamp,
trigger::{TriggerFactory, TriggerType},
version::{edit::VersionEdit, Version, MAX_LEVEL},
version::{edit::VersionEdit, set::VersionSet, Version, MAX_LEVEL},
wal::log::LogType,
DbError, DbOption, DB,
};
Expand Down Expand Up @@ -583,9 +589,7 @@ pub(crate) mod tests {
let temp_dir = tempfile::tempdir().unwrap();
let temp_dir_l0 = tempfile::tempdir().unwrap();

let option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap()
let option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap())
.level_path(
0,
Path::from_filesystem_path(temp_dir_l0.path()).unwrap(),
Expand Down Expand Up @@ -699,9 +703,7 @@ pub(crate) mod tests {
Path::from_filesystem_path(temp_dir.path()).unwrap(),
"id".to_string(),
0,
)
.await
.unwrap();
);
manager
.base_fs()
.create_dir_all(&option.wal_dir_path())
Expand Down Expand Up @@ -769,9 +771,7 @@ pub(crate) mod tests {
let temp_dir_l0 = TempDir::new().unwrap();
let temp_dir_l1 = TempDir::new().unwrap();

let mut option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap()
let mut option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap())
.level_path(
0,
Path::from_filesystem_path(temp_dir_l0.path()).unwrap(),
Expand Down Expand Up @@ -1061,8 +1061,14 @@ pub(crate) mod tests {
.unwrap();

let (sender, _) = bounded(1);
let mut version =
Version::<Test>::new(option.clone(), sender, Arc::new(AtomicU32::default()));
let (meta_cache, range_cache) = VersionSet::build_cache(&option).await.unwrap();
let mut version = Version::<Test>::new(
option.clone(),
sender,
Arc::new(AtomicU32::default()),
range_cache,
meta_cache,
);
version.level_slice[0].push(Scope {
min: 1.to_string(),
max: 3.to_string(),
Expand Down Expand Up @@ -1110,9 +1116,7 @@ pub(crate) mod tests {
pub(crate) async fn major_panic() {
let temp_dir = TempDir::new().unwrap();

let mut option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap();
let mut option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap());
option.major_threshold_with_sst_size = 1;
option.level_sst_magnification = 1;
let manager =
Expand Down Expand Up @@ -1181,8 +1185,14 @@ pub(crate) mod tests {

let option = Arc::new(option);
let (sender, _) = bounded(1);
let mut version =
Version::<Test>::new(option.clone(), sender, Arc::new(AtomicU32::default()));
let (meta_cache, range_cache) = VersionSet::build_cache(&option).await.unwrap();
let mut version = Version::<Test>::new(
option.clone(),
sender,
Arc::new(AtomicU32::default()),
range_cache,
meta_cache,
);
version.level_slice[0].push(Scope {
min: 0.to_string(),
max: 4.to_string(),
Expand Down Expand Up @@ -1219,9 +1229,7 @@ pub(crate) mod tests {
async fn test_flush_major_level_sort() {
let temp_dir = TempDir::new().unwrap();

let mut option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap();
let mut option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap());
option.immutable_chunk_num = 1;
option.immutable_chunk_max_num = 0;
option.major_threshold_with_sst_size = 2;
Expand Down
11 changes: 6 additions & 5 deletions src/fs/cache_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub(crate) mod tests {
ondisk::sstable::SsTable,
record::{Record, RecordInstance},
tests::Test,
version::set::VersionSet,
wal::log::LogType,
DbOption,
};
Expand Down Expand Up @@ -137,10 +138,7 @@ pub(crate) mod tests {
#[tokio::test]
async fn test_cache_read() {
let temp_dir = TempDir::new().unwrap();
let option =
DbOption::<Test>::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap();
let option = DbOption::<Test>::from(Path::from_filesystem_path(temp_dir.path()).unwrap());
let fs = option.base_fs.clone().parse().unwrap();
fs.create_dir_all(&option.version_log_dir_path())
.await
Expand Down Expand Up @@ -189,9 +187,10 @@ pub(crate) mod tests {

let read_count = Arc::new(AtomicUsize::new(0));
let table_path = option.table_path(&table_gen, 0);
let (meta_cache, range_cache) = VersionSet::build_cache(&option).await.unwrap();

for _ in 0..1000 {
let mut scan = SsTable::<Test>::open(
&option,
Box::new(CountFile {
inner: fs
.open_options(&table_path, FileType::Parquet.open_options(true))
Expand All @@ -201,6 +200,8 @@ pub(crate) mod tests {
}),
table_gen,
true,
range_cache.clone(),
meta_cache.clone(),
)
.await
.unwrap()
Expand Down
12 changes: 3 additions & 9 deletions src/inmem/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ mod tests {

let temp_dir = tempfile::tempdir().unwrap();
let fs = Arc::new(TokioFs) as Arc<dyn DynFs>;
let option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap();
let option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap());
fs.create_dir_all(&option.wal_dir_path()).await.unwrap();

let trigger = Arc::new(TriggerFactory::create(option.trigger_type));
Expand Down Expand Up @@ -278,9 +276,7 @@ mod tests {
async fn range() {
let temp_dir = tempfile::tempdir().unwrap();
let fs = Arc::new(TokioFs) as Arc<dyn DynFs>;
let option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap();
let option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap());
fs.create_dir_all(&option.wal_dir_path()).await.unwrap();

let trigger = Arc::new(TriggerFactory::create(option.trigger_type));
Expand Down Expand Up @@ -367,9 +363,7 @@ mod tests {
Path::from_filesystem_path(temp_dir.path()).unwrap(),
"age".to_string(),
0,
)
.await
.unwrap();
);
let fs = Arc::new(TokioFs) as Arc<dyn DynFs>;
fs.create_dir_all(&option.wal_dir_path()).await.unwrap();

Expand Down
56 changes: 17 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
//! // make sure the path exists
//! let _ = fs::create_dir_all("./db_path/users").await;
//!
//! let options = DbOption::from_path(Path::from_filesystem_path("./db_path/users").unwrap()).await.unwrap();
//! let options = DbOption::from(Path::from_filesystem_path("./db_path/users").unwrap());
//! // pluggable async runtime and I/O
//! let db = DB::new(options, TokioExecutor::default()).await.unwrap();
//! // insert with owned value
Expand Down Expand Up @@ -1513,9 +1513,7 @@ pub(crate) mod tests {
let path = Path::from_filesystem_path(temp_dir.path()).unwrap();
let path_l0 = Path::from_filesystem_path(temp_dir_l0.path()).unwrap();

let mut option = DbOption::from_path(path)
.await
.unwrap()
let mut option = DbOption::from(path)
.level_path(0, path_l0, FsOptions::Local)
.unwrap();
option.immutable_chunk_num = 1;
Expand Down Expand Up @@ -1553,9 +1551,7 @@ pub(crate) mod tests {
async fn test_flush() {
let temp_dir = TempDir::new().unwrap();

let mut option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap();
let mut option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap());
option.immutable_chunk_num = 1;
option.immutable_chunk_max_num = 1;
option.major_threshold_with_sst_size = 3;
Expand Down Expand Up @@ -1587,11 +1583,9 @@ pub(crate) mod tests {
let temp_dir = TempDir::new().unwrap();
let fs = Arc::new(TokioFs) as Arc<dyn DynFs>;

let option = Arc::new(
DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap(),
);
let option = Arc::new(DbOption::from(
Path::from_filesystem_path(temp_dir.path()).unwrap(),
));
fs.create_dir_all(&option.wal_dir_path()).await.unwrap();

let (task_tx, _task_rx) = bounded(1);
Expand Down Expand Up @@ -1648,15 +1642,11 @@ pub(crate) mod tests {
let manager = StoreManager::new(FsOptions::Local, vec![]).unwrap();

let (desc, primary_key_index) = test_dyn_item_schema();
let option = Arc::new(
DbOption::with_path(
Path::from_filesystem_path(temp_dir.path()).unwrap(),
"id".to_owned(),
primary_key_index,
)
.await
.unwrap(),
);
let option = Arc::new(DbOption::with_path(
Path::from_filesystem_path(temp_dir.path()).unwrap(),
"id".to_owned(),
primary_key_index,
));
manager
.base_fs()
.create_dir_all(&option.wal_dir_path())
Expand Down Expand Up @@ -1690,9 +1680,7 @@ pub(crate) mod tests {
Path::from_filesystem_path(temp_dir.path()).unwrap(),
"id".to_owned(),
primary_key_index,
)
.await
.unwrap();
);
let db: DB<DynRecord, TokioExecutor> =
DB::with_schema(option, TokioExecutor::new(), desc, primary_key_index)
.await
Expand Down Expand Up @@ -1727,9 +1715,7 @@ pub(crate) mod tests {
async fn test_get_removed() {
let temp_dir = TempDir::new().unwrap();

let mut option = DbOption::from_path(Path::from_filesystem_path(temp_dir.path()).unwrap())
.await
.unwrap();
let mut option = DbOption::from(Path::from_filesystem_path(temp_dir.path()).unwrap());
option.immutable_chunk_num = 1;
option.immutable_chunk_max_num = 1;
option.major_threshold_with_sst_size = 3;
Expand Down Expand Up @@ -1768,9 +1754,7 @@ pub(crate) mod tests {
Path::from_filesystem_path(temp_dir.path()).unwrap(),
"id".to_string(),
primary_key_index,
)
.await
.unwrap();
);
option.immutable_chunk_num = 1;
option.immutable_chunk_max_num = 1;
option.major_threshold_with_sst_size = 3;
Expand Down Expand Up @@ -1978,9 +1962,7 @@ pub(crate) mod tests {
Path::from_filesystem_path(temp_dir1.path()).unwrap(),
"id".to_string(),
primary_key_index,
)
.await
.unwrap();
);
option.immutable_chunk_num = 1;
option.immutable_chunk_max_num = 1;
option.major_threshold_with_sst_size = 3;
Expand All @@ -1992,9 +1974,7 @@ pub(crate) mod tests {
Path::from_filesystem_path(temp_dir2.path()).unwrap(),
"id".to_string(),
primary_key_index,
)
.await
.unwrap();
);
option2.immutable_chunk_num = 1;
option2.immutable_chunk_max_num = 1;
option2.major_threshold_with_sst_size = 3;
Expand All @@ -2006,9 +1986,7 @@ pub(crate) mod tests {
Path::from_filesystem_path(temp_dir3.path()).unwrap(),
"id".to_string(),
primary_key_index,
)
.await
.unwrap();
);
option3.immutable_chunk_num = 1;
option3.immutable_chunk_max_num = 1;
option3.major_threshold_with_sst_size = 3;
Expand Down
Loading

0 comments on commit cf742b9

Please sign in to comment.