pub struct SegmentStore { /* private fields */ }Expand description
Append-only, content-addressed packed object store with an in-memory index.
Implementations§
Source§impl SegmentStore
impl SegmentStore
Sourcepub fn open(objects_root: &Path) -> Result<Self>
pub fn open(objects_root: &Path) -> Result<Self>
Open (or create) the segment store under {objects_root}/segments.
Sourcepub fn open_with_max(
objects_root: &Path,
max_segment_bytes: u64,
) -> Result<Self>
pub fn open_with_max( objects_root: &Path, max_segment_bytes: u64, ) -> Result<Self>
Like open, with an explicit rollover size (used by tests).
Sourcepub fn put(&self, hash: &str, content: &[u8]) -> Result<()>
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).
Sourcepub fn get(&self, hash: &str) -> Result<Option<Vec<u8>>>
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.
Sourcepub fn all_hashes(&self) -> Vec<String>
pub fn all_hashes(&self) -> Vec<String>
All hashes currently stored in segments.
Sourcepub fn sync(&self) -> Result<()>
pub fn sync(&self) -> Result<()>
Flush + fsync the active segment. One durability point per batch.
Sourcepub fn compact(&self, live: &HashSet<String>) -> Result<CompactStats>
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§
impl !Freeze for SegmentStore
impl !RefUnwindSafe for SegmentStore
impl Send for SegmentStore
impl Sync for SegmentStore
impl Unpin for SegmentStore
impl UnsafeUnpin for SegmentStore
impl UnwindSafe for SegmentStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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