pub struct ObjectVersionStore {
pub config: VersionStoreConfig,
pub versions: HashMap<u64, OvsObjectVersion>,
pub branches: HashMap<String, VersionBranch>,
pub next_version: u64,
pub total_bytes: u64,
pub deleted_versions: u64,
}Expand description
Versioned object store with branch management and configurable GC.
§Lifecycle
- Create with
ObjectVersionStore::new. - Commit new content with
ObjectVersionStore::putorObjectVersionStore::put_on_branch. - Retrieve historical content with
ObjectVersionStore::get. - Create branches with
ObjectVersionStore::create_branchand merge them back withObjectVersionStore::merge_branch. - Run GC explicitly with
ObjectVersionStore::gcor letputtrigger it automatically whenmax_versionsis reached.
Fields§
§config: VersionStoreConfigRuntime configuration.
versions: HashMap<u64, OvsObjectVersion>Live version storage, keyed by version number.
branches: HashMap<String, VersionBranch>Branch registry, keyed by branch name.
next_version: u64Counter for the next version number to assign.
total_bytes: u64Cumulative byte count for all live versions.
deleted_versions: u64Total number of versions that have been garbage-collected.
Implementations§
Source§impl ObjectVersionStore
impl ObjectVersionStore
Sourcepub fn new(config: VersionStoreConfig) -> Self
pub fn new(config: VersionStoreConfig) -> Self
Create a new store and initialise the “main” branch at version 0.
Version 0 is a sentinel – it is not inserted into versions. The
“main” branch’s head_version starts at 0, meaning “no versions yet”.
Sourcepub fn put(&mut self, data: Vec<u8>, tags: Vec<String>, now: u64) -> u64
pub fn put(&mut self, data: Vec<u8>, tags: Vec<String>, now: u64) -> u64
Commit data on the “main” branch and return the new version number.
If the version count would exceed config.max_versions, GC is run
before inserting. CID is computed as the FNV-1a 64-bit hex hash of
data.
Sourcepub fn put_on_branch(
&mut self,
branch: String,
data: Vec<u8>,
tags: Vec<String>,
now: u64,
) -> Result<u64, VsError>
pub fn put_on_branch( &mut self, branch: String, data: Vec<u8>, tags: Vec<String>, now: u64, ) -> Result<u64, VsError>
Commit data on a named branch and return the new version number.
Returns VsError::BranchNotFound if the branch does not exist.
Sourcepub fn get(&self, query: VersionQuery) -> Result<&OvsObjectVersion, VsError>
pub fn get(&self, query: VersionQuery) -> Result<&OvsObjectVersion, VsError>
Retrieve a version according to the given VersionQuery.
Sourcepub fn create_branch(
&mut self,
name: String,
from_version: u64,
now: u64,
) -> Result<(), VsError>
pub fn create_branch( &mut self, name: String, from_version: u64, now: u64, ) -> Result<(), VsError>
Create a new branch starting at from_version.
§Errors
VsError::BranchAlreadyExistsifnameis taken.VsError::VersionNotFoundiffrom_versionis not in the store.VsError::MaxBranchesReachedif the branch limit is hit.
Sourcepub fn merge_branch(
&mut self,
source: &str,
target: &str,
now: u64,
) -> Result<u64, VsError>
pub fn merge_branch( &mut self, source: &str, target: &str, now: u64, ) -> Result<u64, VsError>
Merge the head of source into target by creating a new version on
target that is a copy of the source head, with parent_version set
to the source head version number.
Returns the new version number.
Sourcepub fn history(&self, branch: &str) -> Result<Vec<&OvsObjectVersion>, VsError>
pub fn history(&self, branch: &str) -> Result<Vec<&OvsObjectVersion>, VsError>
Walk the parent-version chain from the head of branch and return
versions in reverse-chronological order (newest first).
Sourcepub fn reachable_from_heads(&self) -> HashSet<u64>
pub fn reachable_from_heads(&self) -> HashSet<u64>
Compute the set of version numbers reachable from any branch head via
parent_version links.
Sourcepub fn gc(&mut self) -> usize
pub fn gc(&mut self) -> usize
Run garbage collection according to config.gc_policy.
Returns the number of versions deleted.
Sourcepub fn version_count(&self) -> usize
pub fn version_count(&self) -> usize
Number of live versions currently in the store.
Sourcepub fn total_size_bytes(&self) -> u64
pub fn total_size_bytes(&self) -> u64
Total bytes occupied by all live version payloads.
Auto Trait Implementations§
impl Freeze for ObjectVersionStore
impl RefUnwindSafe for ObjectVersionStore
impl Send for ObjectVersionStore
impl Sync for ObjectVersionStore
impl Unpin for ObjectVersionStore
impl UnsafeUnpin for ObjectVersionStore
impl UnwindSafe for ObjectVersionStore
Blanket Implementations§
impl<T> Allocation for T
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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