Struct Storage

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

Anda DB storage layer implementation based on object_store.

Implementations§

Source§

impl Storage

Source

pub async fn connect( path: String, object_store: Arc<dyn ObjectStore>, config: StorageConfig, ) -> Result<Storage, DBError>

Connects to or initializes the storage at the given path.

Attempts to load existing metadata. If not found, initializes with the provided config.

§Arguments
  • path - The base path for this storage instance within the object store.
  • object_store - The underlying object store implementation.
  • config - The configuration for the storage layer.
§Errors

Returns DBError if metadata loading fails (other than NotFound) or initialization fails.

Source

pub async fn store_metadata( &self, check_point: u64, now_ms: u64, ) -> Result<(), DBError>

Stores the current storage metadata (config and stats) to the object store.

This operation is rate-limited by last_saved timestamp to avoid frequent writes. It increments the internal version counter upon successful save.

§Arguments
  • check_point - The current checkpoint value, used for check_point.
  • now_ms - The current timestamp in milliseconds, used for last_saved.
§Errors

Returns DBError if writing the metadata fails.

Source

pub fn metadata(&self) -> StorageMetadata

Returns a copy of the current storage metadata.

Source

pub fn base_path(&self) -> &Path

Returns the base path of this storage instance.

Source

pub fn object_chunk_size(&self) -> usize

Returns the configured object chunk size.

Source

pub fn stats(&self) -> StorageStats

Returns a copy of the current storage statistics.

Source

pub async fn fetch<T>( &self, doc_path: &str, ) -> Result<(T, ObjectVersion), DBError>

Fetches and deserializes a document directly from the object store, bypassing the cache.

§Arguments
  • doc_path - The relative path of the document within the storage base path.
§Errors

Returns DBError if the object is not found, fetching fails, or deserialization fails.

Source

pub async fn fetch_bytes( &self, doc_path: &str, ) -> Result<(Bytes, ObjectVersion), DBError>

Fetches the raw bytes of a document directly from the object store, bypassing the cache.

§Arguments
  • doc_path - The relative path of the document within the storage base path.
§Errors

Returns DBError if the object is not found or fetching fails.

Source

pub async fn get<T>( &self, doc_path: &str, ) -> Result<(T, ObjectVersion), DBError>

Gets and deserializes a document, potentially using the cache.

If the cache is enabled and the object is found and considered “small”, it will be served from the cache. Otherwise, it fetches from the object store and potentially caches it if small enough.

§Arguments
  • doc_path - The relative path of the document within the storage base path.
§Errors

Returns DBError if the object is not found, fetching fails, or deserialization fails.

Source

pub async fn stream_reader( &self, doc_path: &str, ) -> Result<Pin<Box<dyn AsyncRead>>, DBError>

Creates an asynchronous reader (AsyncRead) for streaming a document’s content. Handles decompression automatically if enabled.

§Arguments
  • doc_path - The relative path of the document.
§Errors

Returns DBError if fetching the object metadata fails.

Source

pub async fn create<T>( &self, doc_path: &str, doc: &T, ) -> Result<ObjectVersion, DBError>
where T: Serialize,

Creates a new document in the object store. Fails if the document already exists.

Serializes the document using ciborium and compresses it if enabled. This method is suitable only for objects smaller than max_small_object_size.

§Arguments
  • doc_path - The relative path for the new document.
  • doc - The document to serialize and store.
§Errors

Returns DBError if serialization fails, the object is too large, or the put operation fails (e.g., object already exists).

Source

pub async fn put<T>( &self, doc_path: &str, doc: &T, version: Option<ObjectVersion>, ) -> Result<ObjectVersion, DBError>
where T: Serialize,

Puts (creates or overwrites/updates) a document in the object store.

Serializes the document using ciborium and compresses it if enabled. This method is suitable only for objects smaller than max_small_object_size. Use stream_writer for larger objects.

§Arguments
  • doc_path - The relative path of the document.
  • doc - The document to serialize and store.
  • version - If Some, performs a conditional update based on the provided ObjectVersion (e.g., ETag match). If None, overwrites unconditionally.
§Errors

Returns DBError if serialization fails, the object is too large, or the put operation fails (e.g., conditional update fails).

Source

pub async fn put_bytes( &self, doc_path: &str, data: Bytes, mode: PutMode, ) -> Result<ObjectVersion, DBError>

Puts raw bytes into the object store.

Compresses the data if enabled. This method is suitable only for data smaller than max_small_object_size. Use stream_writer for larger data.

§Arguments
  • doc_path - The relative path of the object.
  • data - The raw bytes to store.
  • mode - The PutMode (Create, Overwrite, Update).
§Errors

Returns DBError if the data is too large or the put operation fails.

Source

pub fn to_writer(&self, doc_path: &str, mode: PutMode) -> SingleWriter

Creates an asynchronous writer (AsyncWrite) for writing small objects (< max_small_object_size).

Data is buffered in memory and written in a single put operation on poll_flush or poll_close. Use stream_writer for large objects.

§Arguments
  • doc_path - The relative path of the object.
  • mode - The PutMode (Create, Overwrite, Update).
Source

pub fn stream_writer(&self, doc_path: &str) -> Pin<Box<dyn AsyncWrite>>

Creates an asynchronous writer (AsyncWrite) for streaming large objects.

Data is written in chunks using the underlying object store’s multipart upload or equivalent. Handles compression automatically if enabled.

§Arguments
  • doc_path - The relative path of the object.
Source

pub async fn delete(&self, doc_path: &str) -> Result<(), DBError>

Deletes a document from the object store and removes it from the cache if present.

§Arguments
  • doc_path - The relative path of the document to delete.
§Errors

Returns DBError if the delete operation fails.

Source

pub fn list<T>( &self, prefix: Option<&str>, offset: Option<&str>, ) -> BoxStream<'_, Result<(T, ObjectVersion), DBError>>

Lists documents in the storage, optionally filtering by prefix and starting from an offset.

Fetches and deserializes each listed object. This can be inefficient for large listings. Consider using object_store.list directly if only metadata is needed.

§Arguments
  • prefix - Optional path prefix to filter the listing.
  • offset - Optional path to start the listing after.
§Returns

A stream of Result<(T, ObjectVersion), DBError>.

Trait Implementations§

Source§

impl Clone for Storage

Source§

fn clone(&self) -> Storage

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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<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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn pipe<F, R>(self, f: F) -> R
where F: FnOnce(T) -> R,

Passes the value through a function. 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> 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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Fruit for T
where T: Send + Downcast,