Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion atomic-core/src/pristine/txn/pristine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -222,6 +225,7 @@ impl Pristine {

Ok(Self {
db: PristineDatabase::Writable(db),
durability: redb::Durability::Immediate,
next_node_id,
next_view_id,
next_inode,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
23 changes: 19 additions & 4 deletions atomic-repository/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ impl Repository {
pub fn init_with_view<P: AsRef<Path>>(
path: P,
view_name: &str,
) -> Result<Self, RepositoryError> {
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<P: AsRef<Path>>(
path: P,
view_name: &str,
durability: redb::Durability,
) -> Result<Self, RepositoryError> {
let root = path.as_ref().to_path_buf();
let dot_dir = root.join(DOT_DIR);
Expand Down Expand Up @@ -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
{
Expand Down
9 changes: 8 additions & 1 deletion atomic-repository/src/repository/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading