From f7146cbccb8ce258cfe7cee853b4eaf3175d99b6 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Wed, 2 Dec 2026 22:22:37 +0530 Subject: [PATCH 1/2] Clarify checkpoint and prepared query guarantees --- README.md | 2 +- src/db.rs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2a0c8212bc..d44e8c24bb 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ db.execute("(rule [(reachable ?a ?b) [?a :friend ?b]])")?; db.execute("(rule [(reachable ?a ?b) [?a :friend ?m] (reachable ?m ?b)])")?; db.execute("(query [:find ?friend :where (reachable :alice ?friend)])")?; -// Prepared statement — parse + plan once, execute many times +// Parse once, then execute with different bind values use minigraf::{BindValue, EntityId}; // Keywords map to UUIDv5 IDs in the OID namespace, including the leading colon. let alice_id = EntityId::new_v5(&EntityId::NAMESPACE_OID, b":alice"); diff --git a/src/db.rs b/src/db.rs index 03254fd78e..24395fcac0 100644 --- a/src/db.rs +++ b/src/db.rs @@ -708,9 +708,13 @@ impl Minigraf { /// Manually trigger a checkpoint: flush all in-memory facts to the main file /// and delete the WAL sidecar. /// - /// A checkpoint is **not** a durability boundary: committed writes are already - /// crash-durable in the `.wal` sidecar and are replayed on the next open. - /// Checkpointing less often only makes that replay (reopen) slower. + /// In [`SyncMode::Full`], the write syncs the WAL before applying facts + /// in memory. In [`SyncMode::Normal`], the write appends its entry without + /// syncing it. Syncing that WAL file also forces earlier entries to disk. + /// A successful checkpoint syncs the main file in either mode. Reopen + /// replays WAL entries not yet checkpointed. In 2.x a checkpoint + /// interrupted by a crash is + /// [not crash-atomic](https://github.com/project-minigraf/minigraf/issues/374). /// /// Cost: every checkpoint rewrites the four covering indexes after the fact /// pages, so it copies pages in proportion to the total index size; only the @@ -722,6 +726,9 @@ impl Minigraf { /// # Errors /// /// Returns an error if the write lock is poisoned or the checkpoint I/O fails. + /// An automatic checkpoint can fail after the write has applied its facts + /// in memory. A checkpoint error does not mean the write was rolled back. + /// Check the recovered database before retrying the write. pub fn checkpoint(&self) -> Result<(), MinigrafError> { self.checkpoint_inner().map_err(MinigrafError::from) } @@ -811,7 +818,8 @@ impl Minigraf { Ok(()) } - /// Parse and plan a query once; bind slots (`$name`) are left unresolved. + /// Parse and validate a query once. Bind slots (`$name`) are filled on + /// each execution, before the query is planned. /// /// Returns a [`crate::query::datalog::prepared::PreparedQuery`] that can be executed /// many times with different bind values via From 18eb365afba220c04d4bf484143a9287625dce76 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 3 Dec 2026 01:01:00 +0530 Subject: [PATCH 2/2] Retrigger CI after GitHub Actions incident