8000 Clarify checkpoint and prepared query guarantees (v2.x) by adityamukho · Pull Request #983 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
16 changes: 12 additions & 4 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<db>.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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
Loading
0