From cd2abf414f2d0c37e0719ff2ef58ac62e58250a1 Mon Sep 17 00:00:00 2001 From: Kould Date: Tue, 30 Jul 2024 14:34:26 +0800 Subject: [PATCH] fix: blocking at cleaner --- src/compaction/mod.rs | 1 - src/lib.rs | 18 +++++++++--------- src/version/cleaner.rs | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/compaction/mod.rs b/src/compaction/mod.rs index 219a7b37..8cec7861 100644 --- a/src/compaction/mod.rs +++ b/src/compaction/mod.rs @@ -69,7 +69,6 @@ where let mut guard = self.schema.write().await; if guard.mutable.is_empty() { - println!("WWWWWW"); return Ok(()) } let mutable = mem::replace(&mut guard.mutable, Mutable::new(&self.option).await?); diff --git a/src/lib.rs b/src/lib.rs index 3d41c874..97fcd02d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -938,7 +938,7 @@ pub(crate) mod tests { ] } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn read_from_disk() { let temp_dir = TempDir::new().unwrap(); @@ -955,14 +955,14 @@ pub(crate) mod tests { db.write(item, 0.into()).await.unwrap(); } - // let tx = db.transaction().await; - // let key = 20.to_string(); - // let option1 = tx.get(&key, Projection::All).await.unwrap().unwrap(); - // - // assert_eq!(option1.get().map(|test_ref| test_ref.vstring), Some("20")); - // assert_eq!(option1.get().map(|test_ref| test_ref.vu32), Some(Some(0))); - // assert_eq!(option1.get().map(|test_ref| test_ref.vbool), Some(Some(true))); + let tx = db.transaction().await; + let key = 20.to_string(); + let option1 = tx.get(&key, Projection::All).await.unwrap().unwrap(); - // dbg!(db.version_set.current().await); + assert_eq!(option1.get().map(|test_ref| test_ref.vstring), Some("20")); + assert_eq!(option1.get().map(|test_ref| test_ref.vu32), Some(Some(0))); + assert_eq!(option1.get().map(|test_ref| test_ref.vbool), Some(Some(true))); + + dbg!(db.version_set.current().await); } } diff --git a/src/version/cleaner.rs b/src/version/cleaner.rs index d854e5d5..0da9de05 100644 --- a/src/version/cleaner.rs +++ b/src/version/cleaner.rs @@ -1,7 +1,7 @@ -use std::{collections::BTreeMap, fs, io, sync::Arc}; +use std::{collections::BTreeMap, io, sync::Arc}; use flume::{Receiver, Sender}; - +use tokio::fs; use crate::{fs::FileId, timestamp::Timestamp, DbOption}; pub enum CleanTag { @@ -42,10 +42,10 @@ impl Cleaner { while let Some((first_version, (gens, dropped))) = self.gens_map.pop_first() { if !dropped { let _ = self.gens_map.insert(first_version, (gens, false)); - continue; + break; } for gen in gens { - fs::remove_file(self.option.table_path(&gen))?; + fs::remove_file(self.option.table_path(&gen)).await?; } } }