Skip to main content

SegmentStore

Struct SegmentStore 

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

Append-only, content-addressed packed object store with an in-memory index.

Implementations§

Source§

impl SegmentStore

Source

pub fn open(objects_root: &Path) -> Result<Self>

Open (or create) the segment store under {objects_root}/segments.

Source

pub fn open_with_max( objects_root: &Path, max_segment_bytes: u64, ) -> Result<Self>

Like open, with an explicit rollover size (used by tests).

Source

pub fn contains(&self, hash: &str) -> bool

True if this hash is already stored in a segment.

Source

pub fn put(&self, hash: &str, content: &[u8]) -> Result<()>

Append content under hash (idempotent). hash must equal BLAKE2b(content); the caller computes it (parallel, outside the lock).

Source

pub fn get(&self, hash: &str) -> Result<Option<Vec<u8>>>

Read the raw content bytes for hash, or None if not stored in any segment (caller then falls back to the loose-object path). Re-verifies.

Source

pub fn all_hashes(&self) -> Vec<String>

All hashes currently stored in segments.

Source

pub fn sync(&self) -> Result<()>

Flush + fsync the active segment. One durability point per batch.

Source

pub fn compact(&self, live: &HashSet<String>) -> Result<CompactStats>

Rewrite the live object set into fresh segments and drop everything else, reclaiming dead (superseded/spent/pruned) records.

live is the set of hashes to KEEP — typically the current version of every document (from the id-index). Hashes not in live are pruned, so historical versions / AS OF / TRACE for dropped objects are discarded by design (that is what reclaims space).

Crash-safe: new segments are written + fsynced BEFORE any old segment is deleted, so live data is never lost. A crash mid-compaction leaves both the old and new segments (a re-open re-indexes the union — dead objects merely linger until the next compaction); it never loses a live object.

Must be called when the store is quiescent (no concurrent reads): writes are blocked for the duration via the active lock, and the in-memory index is swapped in place.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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<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