diff --git a/atomic-core/src/pristine/txn/pristine.rs b/atomic-core/src/pristine/txn/pristine.rs index 566ef487..9981f81f 100644 --- a/atomic-core/src/pristine/txn/pristine.rs +++ b/atomic-core/src/pristine/txn/pristine.rs @@ -91,6 +91,9 @@ fn open_database(path: &Path, create: bool, cache_bytes: usize) -> PristineResul /// ``` pub struct Pristine { db: PristineDatabase, + /// Redb commit durability. Tests lower this to skip fsync per commit, + /// which dominates the runtime of filesystem-heavy suites on Windows. + durability: redb::Durability, /// Counter for allocating node IDs pub(crate) next_node_id: AtomicU64, /// Counter for allocating view IDs @@ -222,6 +225,7 @@ impl Pristine { Ok(Self { db: PristineDatabase::Writable(db), + durability: redb::Durability::Immediate, next_node_id, next_view_id, next_inode, @@ -328,12 +332,19 @@ impl Pristine { Ok(Self { db, + durability: redb::Durability::Immediate, next_node_id, next_view_id, next_inode, }) } + /// Override the redb commit durability for this handle. Tests use this + /// to skip per-commit fsync; production keeps the durable default. + pub fn set_durability(&mut self, durability: redb::Durability) { + self.durability = durability; + } + /// Begin a read-only transaction /// /// Read transactions can run concurrently with other read transactions @@ -355,7 +366,9 @@ impl Pristine { "cannot write through a read-only pristine handle", ))); }; - let txn = db.begin_write()?; + let mut txn = db.begin_write()?; + txn.set_durability(self.durability) + .map_err(|e| PristineError::Io(std::io::Error::other(e.to_string())))?; Ok(WriteTxn::new( txn, &self.next_node_id, diff --git a/atomic-repository/src/repository/mod.rs b/atomic-repository/src/repository/mod.rs index 4c98e8fe..2ddd65b6 100644 --- a/atomic-repository/src/repository/mod.rs +++ b/atomic-repository/src/repository/mod.rs @@ -274,6 +274,19 @@ impl Repository { pub fn init_with_view>( path: P, view_name: &str, + ) -> Result { + Self::init_with_view_durability(path, view_name, redb::Durability::Immediate) + } + + /// Like [`Self::init_with_view`], with an explicit redb commit durability. + /// + /// Tests pass [`redb::Durability::None`] to skip per-commit fsync, which + /// dominates the runtime of filesystem-heavy repository suites (notably + /// on Windows). Production callers keep the durable default. + pub fn init_with_view_durability>( + path: P, + view_name: &str, + durability: redb::Durability, ) -> Result { let root = path.as_ref().to_path_buf(); let dot_dir = root.join(DOT_DIR); @@ -307,10 +320,12 @@ default = "{}" std::fs::write(&wc_id_path, "")?; // Initialize the pristine database (redb creates the file) - let pristine = Arc::new( - Pristine::open(dot_dir.join("pristine.redb")) - .map_err(|e| RepositoryError::Database(e.to_string()))?, - ); + let pristine = { + let mut pristine = Pristine::open(dot_dir.join("pristine.redb")) + .map_err(|e| RepositoryError::Database(e.to_string()))?; + pristine.set_durability(durability); + Arc::new(pristine) + }; // Create the default view and its workspace directory { diff --git a/atomic-repository/src/repository/tests/mod.rs b/atomic-repository/src/repository/tests/mod.rs index 3ef5342a..07c0dce6 100644 --- a/atomic-repository/src/repository/tests/mod.rs +++ b/atomic-repository/src/repository/tests/mod.rs @@ -28,7 +28,14 @@ mod view_tests; pub(super) fn create_temp_repo() -> (TempDir, Repository) { let temp_dir = TempDir::new().unwrap(); - let repo = Repository::init(temp_dir.path()).unwrap(); + // Durability::None skips per-commit fsync, which dominates these + // filesystem-heavy tests (especially on Windows). Redb still makes + // commits visible to later handles through the OS page cache, so + // reopen-style tests remain correct; only crash-durability is lost, + // which tests never need. + let repo = + Repository::init_with_view_durability(temp_dir.path(), "dev", redb::Durability::None) + .unwrap(); (temp_dir, repo) }