Struct agdb::FileStorage

source ·
pub struct FileStorage { /* private fields */ }
Expand description

Single file based storage with write ahead log (WAL) for resiliency implementing StorageData. It uses the storage name as the file name (.{name} for WAL). It allows multiple readers from the file by opening additional temporary file handles if the single member file handle is being used (read). The StorageData::read() always returns owning buffer.

The StorageData::backup() is implemented so that it copes the file to the new name.

The StorageData::flush() merely clears the WAL. This implementation relies on the OS to flush the content to the disk. It is specifically not using manual calls to File::sync_data() / File::sync_all() because they result in extreme slowdown.

Trait Implementations§

source§

impl Drop for FileStorage

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl StorageData for FileStorage

source§

fn backup(&self, name: &str) -> Result<(), DbError>

Copy the underlying data storage to a new name. The default implementation does nothing. File implementations might need to copy the underlying file(s).
source§

fn copy(&self, name: &str) -> Result<Self, DbError>

source§

fn flush(&mut self) -> Result<(), DbError>

Flushes any buffers to the underlying storage (e.g. file). The default implementation does nothing.
source§

fn len(&self) -> u64

Returns the length of the underlying storage in bytes.
source§

fn name(&self) -> &str

Returns the name this storage was constructed with.
source§

fn new(name: &str) -> Result<Self, DbError>

Constructs or loads the storage name. The name might be a file name or other identifier.
source§

fn read(&self, pos: u64, value_len: u64) -> Result<StorageSlice<'_>, DbError>

Reads value_len bytes starting at pos. Returns StorageSlice (COW).
source§

fn rename(&mut self, new_name: &str) -> Result<(), DbError>

Changes the name of the storage changing also the names of the files (if the storage is file based).
source§

fn resize(&mut self, new_len: u64) -> Result<(), DbError>

Resizes the underlying storage to new_len. If the storage is enlarged as a result the new bytes should be initialized to 0_u8.
source§

fn write(&mut self, pos: u64, bytes: &[u8]) -> Result<(), DbError>

Writes the bytes to the underlying storage at pos. The implementation must handle the case where the pos + bytes.len() exceeds the current len().
source§

fn is_empty(&self) -> bool

Convenience method that returns len() == 0.

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<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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.