Skip to main content

FileStorage

Struct 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 Debug for FileStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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>

Copies the storage to a new name.
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>,

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.