Skip to main content

ObjectVersionStore

Struct ObjectVersionStore 

Source
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

  1. Create with ObjectVersionStore::new.
  2. Commit new content with ObjectVersionStore::put or ObjectVersionStore::put_on_branch.
  3. Retrieve historical content with ObjectVersionStore::get.
  4. Create branches with ObjectVersionStore::create_branch and merge them back with ObjectVersionStore::merge_branch.
  5. Run GC explicitly with ObjectVersionStore::gc or let put trigger it automatically when max_versions is reached.

Fields§

§config: VersionStoreConfig

Runtime configuration.

§versions: HashMap<u64, OvsObjectVersion>

Live version storage, keyed by version number.

§branches: HashMap<String, VersionBranch>

Branch registry, keyed by branch name.

§next_version: u64

Counter for the next version number to assign.

§total_bytes: u64

Cumulative byte count for all live versions.

§deleted_versions: u64

Total number of versions that have been garbage-collected.

Implementations§

Source§

impl ObjectVersionStore

Source

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”.

Source

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.

Source

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.

Source

pub fn get(&self, query: VersionQuery) -> Result<&OvsObjectVersion, VsError>

Retrieve a version according to the given VersionQuery.

Source

pub fn create_branch( &mut self, name: String, from_version: u64, now: u64, ) -> Result<(), VsError>

Create a new branch starting at from_version.

§Errors
Source

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.

Source

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).

Source

pub fn reachable_from_heads(&self) -> HashSet<u64>

Compute the set of version numbers reachable from any branch head via parent_version links.

Source

pub fn gc(&mut self) -> usize

Run garbage collection according to config.gc_policy.

Returns the number of versions deleted.

Source

pub fn version_count(&self) -> usize

Number of live versions currently in the store.

Source

pub fn total_size_bytes(&self) -> u64

Total bytes occupied by all live version payloads.

Source

pub fn stats(&self) -> VsStats

Return a statistics snapshot.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, 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