Skip to main content

ObjectStore

Struct ObjectStore 

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

Local content-addressed object store backed by the filesystem.

Implementations§

Source§

impl ObjectStore

Source

pub fn open(layout: &RepoLayout) -> StoreResult<Self>

Open the existing repository described by layout. Returns StoreError::NotAMkitRepository if the layout’s objects/ directory does not exist. The object store is common-dir (shared) state — see crate::layout.

Source

pub fn init(layout: &RepoLayout) -> StoreResult<Self>

Initialise a fresh common dir for the repository described by layout. Returns StoreError::AlreadyInitialized if the common dir already exists.

Source

pub fn set_sync_policy(&mut self, policy: SyncPolicy)

Select the SyncPolicy that Self::batch hands out. The CLI wires the repo config key durability.objects here so deployments on filesystems where they prefer the strict per-object schedule can opt into it (SPEC-OBJECTS §10.1).

Source

pub fn batch(&self) -> WriteBatch<'_>

Start a batched write with the store’s configured policy (default SyncPolicy::Batch): objects staged by the batch become durable and visible together at WriteBatch::commit, with O(1) full flushes per batch instead of per object.

Source

pub fn batch_with_policy(&self, policy: SyncPolicy) -> WriteBatch<'_>

Start a batched write with an explicit SyncPolicy.

Source

pub fn is_repo_root(root: &Path) -> bool

Returns true when root contains a .mkit/objects directory.

Source

pub fn objects_root(&self) -> &Path

Absolute path to the objects/ directory.

Source

pub fn contains(&self, h: &Hash) -> bool

Returns true when the object h is present in the store. Does not verify integrity — use Self::read for that.

Source

pub fn write(&self, bytes: &[u8]) -> StoreResult<Hash>

Write bytes to the store, returning their BLAKE3 hash. Atomic: writes to a sibling temp file, fsyncs, then renames into place. Idempotent — re-writing the same bytes is a no-op (the temp file is unlinked on the early-return path).

§Panics

Panics only if the internal hash-to-path mapping produces a path without a parent directory, which is impossible by construction.

Source

pub fn bulk_writer(&self) -> BulkWriter<'_>

Begin a bulk-write session: each new object is written durable-before-visible (contents fsynced, then renamed), and BulkWriter::commit batches the directory fsyncs (rename durability) plus a content fsync of any re-used pre-existing objects once at the end, instead of fsyncing a dir per write.

Because content is durable before the rename, the session upholds the store’s global invariant even under concurrent readers: an object another process can contains()-dedup against is always backed by durable bytes.

Crash-safety contract (deliberately weaker than Self::write only for the rename/dirent half, for callers whose whole operation is idempotent — e.g. the deterministic git-import, which re-runs from a retained source mirror): after a crash BEFORE commit, a just-renamed object’s dirent may be lost (the shard dir is not yet fsynced), so objects may be missing — never torn, since contents were fsynced first. Existing paths are VERIFIED (byte compare) rather than blindly rewritten or blindly trusted: a matching file is left untouched (it may be durable and referenced by native history — replacing it with an unsynced inode would put it at risk), a torn one is healed by rewrite, and reads always BLAKE3-verify. Callers MUST gate bulk sessions behind their own crash marker and re-run on detection.

Source

pub fn read(&self, h: &Hash) -> StoreResult<Vec<u8>>

Read raw bytes for h. Verifies that BLAKE3 of the on-disk bytes equals h and returns StoreError::HashMismatch on failure (the bytes are still discarded so callers cannot accidentally use corrupt data).

Source

pub fn read_unverified(&self, h: &Hash) -> StoreResult<Vec<u8>>

Read raw bytes for h WITHOUT the BLAKE3 integrity check that Self::read performs — a StoreError::HashMismatch can therefore never come out of this path.

§Policy — display-only paths ONLY (#625)

This exists for hot read-only rendering (diff/show/commit summaries formatting a diffstat or patch preview). It is the same “cheap read” tradeoff Self::object_type already makes for shape checks (see its doc and Self::verify_object_type, which is the verifying twin used by tree-publication paths) — extended here to the full object body.

NEVER use this for publication (commit/merge/rebase tree writes), dedup, fetch/apply, or any path whose output is consumed as data rather than displayed and discarded. mkit never feeds unverified bytes into state that mkit itself writes, or into output that mkit’s own tooling round-trips (e.g. format-patch piped into git am). On corruption, callers of read get a loud, typed error before anything downstream can act on bad bytes; callers of read_unverified get whatever a decoder makes of the corrupt bytes — a decode error, or in the worst case garbage in the rendered output — but never durable state, because display paths write nothing back to the store.

Prefer wrapping the source with DisplaySource at the render call site over calling this directly; that keeps the verify/ no-verify choice at the boundary instead of threading a flag through render code.

Source

pub fn object_type(&self, h: &Hash) -> StoreResult<ObjectType>

The object’s type tag, from its 6-byte prologue — without reading or hash-verifying the body. Backs cheap shape checks (e.g. “is this staged hash blob-like?”) that previously paid a full read+BLAKE3 of every staged blob per status/commit; the real read path still integrity-verifies at use time.

§Errors

StoreError::ObjectNotFound if absent; StoreError::Decode for a short file, bad magic/version, or unknown tag.

Source

pub fn read_object(&self, h: &Hash) -> StoreResult<Object>

Convenience: read raw bytes and decode into a typed Object.

Source

pub fn verify_object_type(&self, h: &Hash) -> StoreResult<ObjectType>

Hash-verifying variant of object_type: reads the whole object and confirms its content hashes to h before returning the declared type. This is the integrity guard for tree-publication paths (commit, merge, rebase, …) — object_type alone reads only the 6-byte prologue, so a staged object corrupted after add would otherwise be published into a durable tree and only fail at later read time. Use object_type on hot read-only paths (status/diff snapshots) where nothing durable is published.

Source

pub fn iter_object_hashes(&self) -> StoreResult<Vec<Hash>>

Enumerate every object hash currently in the store by walking objects/<2-hex>/<62-hex>. Entries whose names are not the expected hex shape (stray files, atomic-write temp files, unknown dirs) are skipped — they are not objects. Used by gc to find prune candidates.

§Errors

StoreError::Io if a directory cannot be read (gc must then fail closed rather than prune against a partial enumeration).

Source

pub fn object_metadata(&self, h: &Hash) -> StoreResult<Metadata>

Filesystem metadata for object h (size + mtime), for gc’s grace-window check.

§Errors

StoreError::ObjectNotFound if absent, else StoreError::Io.

Source

pub fn remove_object(&self, h: &Hash) -> StoreResult<()>

Delete object h from the store. Idempotent: a missing object is not an error (it may have been pruned already).

§Errors

StoreError::Io on a filesystem failure other than not-found.

Trait Implementations§

Source§

impl Clone for ObjectStore

Source§

fn clone(&self) -> ObjectStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ObjectStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ObjectSink for ObjectStore

Source§

fn put(&self, bytes: &[u8]) -> StoreResult<Hash>

Store bytes as one object, returning its BLAKE3 hash.
Source§

fn put_parts(&self, parts: &[&[u8]]) -> StoreResult<Hash>

Store the concatenation of parts as one object without the caller having to materialise the concatenated buffer.
Source§

fn has(&self, h: &Hash) -> bool

True when the object is already present (or staged) in this sink.
Source§

impl ObjectSource for ObjectStore

Source§

fn read(&self, h: &Hash) -> StoreResult<Vec<u8>>

Read and integrity-verify the raw bytes of h. Read more
Source§

fn read_unverified(&self, h: &Hash) -> StoreResult<Vec<u8>>

Read h without integrity verification, for display-only rendering — see ObjectStore::read_unverified for the full policy (#625). Defaults to the fully-verifying Self::read, so every existing and third-party ObjectSource stays verifying unless it explicitly opts in by overriding this method. Read more
Source§

fn read_object(&self, h: &Hash) -> StoreResult<Object>

Read and decode h into a typed Object. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more