Skip to main content

Db

Struct Db 

Source
pub struct Db { /* private fields */ }
Expand description

Open OXGDB database handle.

§Performance

Moving a handle is O(1): it moves the current Arc<Snapshot> and the open delta-log handle.

Implementations§

Source§

impl Db

Source

pub const fn checkpoint_policy(&self) -> CheckpointPolicy

Returns the configured auto-checkpoint policy.

§Performance

This method is O(1).

Source

pub const fn set_checkpoint_policy(&mut self, policy: CheckpointPolicy)

Sets the auto-checkpoint policy consulted after each dirty commit.

§Performance

This method is O(1).

Source

pub fn validate(&self) -> Result<(), DbError>

Validates the current handle with the strongest offline check: re-reads the superblock, verifies the live base’s container integrity in full (oxgraph_snapshot::Snapshot::open_checked for the table checksum, then oxgraph_snapshot::Snapshot::verify_all over EVERY section — a mismatch names the failing section kind), and finally attaches the base to run the structural bind checks (format version, property sort order, posting bounds).

§Errors

Returns DbError when the superblock or base fails validation; a checksum failure names the failing section.

§Performance

This method is O(base bytes): one verify_all sweep plus one verify-at-bind attach (two checksum passes over the base).

Source

pub fn validate_path(path: impl AsRef<Path>) -> Result<(), DbError>

Validates an OXGDB database at path.

§Errors

Returns DbError when the store fails to open and recover.

§Performance

This function is O(base bytes + log bytes).

Source

pub fn compact(&mut self) -> Result<(), DbError>

Folds the current base+overlay into a new base generation, rotating the delta-log and republishing the superblock (a manual checkpoint).

This is the checkpoint primitive, exposed here so the existing compact API keeps its “rewrite the store compactly” contract. Auto-triggering is configured separately via Db::set_checkpoint_policy.

§Errors

Returns DbError when encoding, writing, or publishing the new generation fails.

§Performance

This method is O(visible state bytes).

Source§

impl Db

Source

pub fn create(path: impl AsRef<Path>) -> Result<Self, DbError>

Creates a new empty OXGDB database at path.

The create order is base-0 then empty delta-0.log then the writer lock file then the superblock (written LAST as the create-complete marker), so a half-created store is detected on open rather than silently opened empty.

§Errors

Returns [DbError::Storage(crate::error::StorageError::AlreadyExists)] when a store already exists, or [DbError::Io]/[DbError::InvalidStore] when creation fails.

§Performance

This function is O(empty base bytes).

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, DbError>

Opens an existing OXGDB database, recovering the live frontier from the valid prefix of the delta-log replayed over the base named by the superblock.

§Errors

Returns DbError when the store is missing, malformed, or the log is corrupt beyond a torn tail.

§Performance

This function is O(base bytes + log bytes). Base integrity is fused into the bind pass: the container’s table checksum is verified once, then each bound section’s payload CRC-32C is verified as the section is borrowed — there is no separate whole-base CRC scan.

Source§

impl Db

Source

pub const fn live_generation(&self) -> CheckpointGeneration

Returns the live base generation named by the superblock (the count of folds this store has undergone; gen-0 is the freshly created store).

§Performance

This method is O(1).

Source

pub fn stats(&self) -> Stats

Returns operational status for this handle, including the live generation count and the on-disk base/delta-log sizes the auto-checkpoint policy weighs.

§Performance

This method is O(visible state) for the merged counts plus two stat syscalls for the file sizes.

Source

pub fn catalog_summary(&self) -> CatalogSummary

Returns a catalog-size summary.

§Performance

This method is O(catalog entry count).

Source

pub fn reader(&self) -> Reader

Starts a read transaction pinned to the current visible snapshot.

§Performance

This method is O(1): the reader clones the current Arc<Snapshot> and observes a fixed state even across later commits and checkpoints.

Source

pub fn pin(&self) -> ReadPin

Returns the pin identifying the current visible snapshot — the commit sequence and checkpoint generation a Self::reader started now would observe — without starting a read transaction.

§Performance

This method is O(1): it copies the current snapshot’s identity fields.

Source

pub fn read<R>( &self, f: impl FnOnce(&Reader) -> Result<R, DbError>, ) -> Result<R, DbError>

Runs f against a read transaction pinned to the current snapshot. The primary read entry point.

§Errors

Propagates whatever error f returns.

§Performance

Entering is O(1) (an Arc clone); the total cost is f’s cost.

Source

pub fn write<R>( &mut self, f: impl FnOnce(&mut Writer<'_>) -> Result<R, DbError>, ) -> Result<(R, CommitOutcome), DbError>

Runs f against the single write transaction, committing on Ok and rolling back on Err — control flow IS the commit protocol. Returns f’s value with the CommitOutcome (whether a durable frame landed). The primary write entry point.

§Errors

Returns [DbError::Txn(crate::error::TxnError::WriterLockHeld)] when another writer holds the lock, f’s error (after rolling back the staged delta), or a commit error.

§Performance

Begin is O(parent change) — the writer seeds by cloning the parent overlay’s delta map structure (label sets, text values, per-subject property delta maps, and index postings are Arc-shared, so each of the N committed-but-unfolded entries costs O(1); folded away by a checkpoint). Commit is O(change). A triggered auto-fold adds O(visible bytes).

Source

pub fn bind(&self, schema: &Schema) -> Result<Bound, DbError>

Resolves an already-applied Schema against the live catalog WITHOUT writing, returning the Bound handle bag (for a store already bootstrapped with this schema).

§Errors

Returns [DbError::UnknownName] when a declared item is absent.

§Performance

This method is O(declared items × log catalog).

Source

pub fn prepare(&self, query: &str) -> Result<PreparedQuery, DbError>

Prepares a query against the current catalog.

§Errors

Returns DbError when parsing or semantic analysis fails.

§Performance

This method is O(query length + catalog lookup cost).

Auto Trait Implementations§

§

impl Freeze for Db

§

impl RefUnwindSafe for Db

§

impl Send for Db

§

impl Sync for Db

§

impl Unpin for Db

§

impl UnsafeUnpin for Db

§

impl UnwindSafe for Db

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.