[][src]Struct pearl::Storage

pub struct Storage<K> { /* fields omitted */ }

A main storage struct.

This type is clonable, cloning it will only create a new reference, not a new storage. Storage has a type parameter K. To perform read/write operations K must implement Key trait.

Examples

use pearl::{Storage, Builder, Key};

#[tokio::main]
async fn main() {
    let mut storage: Storage<String> = Builder::new()
        .work_dir("/tmp/pearl/")
        .max_blob_size(1_000_000)
        .max_data_in_blob(1_000_000_000)
        .blob_file_name_prefix("pearl-test")
        .build()
        .unwrap();
    storage.init().await.unwrap();
}

Implementations

impl<K> Storage<K>[src]

pub async fn init<'_>(&'_ mut self) -> Result<()>[src]

init() used to prepare all environment to further work.

Storage works in directory provided to builder. If directory don't exist, storage creates it, otherwise tries to init existing storage.

Errors

Returns error in case of failures with IO operations or if some of the required params are missed.

pub async fn write<'_>(&'_ self, key: impl Key, value: Vec<u8>) -> Result<()>[src]

Writes data to active blob asyncronously. If active blob reaches it limit, creates new and closes old.

Examples

async fn write_data() {
    let key = 42u64.to_be_bytes().to_vec();
    let data = b"async written to blob".to_vec();
    storage.write(key, data).await
}

Errors

Fails with the same errors as write_with

pub async fn write_with<'_>(
    &'_ self,
    key: impl Key,
    value: Vec<u8>,
    meta: Meta
) -> Result<()>
[src]

Similar to write but with metadata

Examples

async fn write_data() {
    let key = 42u64.to_be_bytes().to_vec();
    let data = b"async written to blob".to_vec();
    let meta = Meta::new();
    meta.insert("version".to_string(), b"1.0".to_vec());
    storage.write_with(&key, data, meta).await
}

Errors

Fails if duplicates are not allowed and record already exists.

pub async fn read<'_>(&'_ self, key: impl Key) -> Result<Vec<u8>>[src]

Reads the first found data matching given key.

Examples

async fn read_data() {
    let key = 42u64.to_be_bytes().to_vec();
    let data = storage.read(key).await;
}

Errors

Same as read_with

pub async fn read_with<'_, '_>(
    &'_ self,
    key: impl Key,
    meta: &'_ Meta
) -> Result<Vec<u8>>
[src]

Reads data matching given key and metadata

Examples

async fn read_data() {
    let key = 42u64.to_be_bytes().to_vec();
    let meta = Meta::new();
    meta.insert("version".to_string(), b"1.0".to_vec());
    let data = storage.read(&key, &meta).await;
}

Errors

Return error if record is not found.

pub async fn read_all<'_, '_>(&'_ self, key: &'_ impl Key) -> Result<Vec<Entry>>[src]

Returns entries with matching key

Errors

Fails after any disk IO errors.

pub async fn close<'_>(&'_ self) -> Result<()>[src]

Stop blob updater and release lock file

Errors

Fails because of any IO errors

#[must_use]pub fn blobs_count(&self) -> usize[src]

blob_count returns number of closed blobs plus one active, if there is some.

Examples

use pearl::Builder;

let mut storage = Builder::new().work_dir("/tmp/pearl/").build::<f64>();
storage.init().await;
assert_eq!(storage.blobs_count(), 1);

pub async fn contains<'_>(&'_ self, key: impl Key) -> Result<bool>[src]

contains is used to check whether a key is in storage. Slower than check_bloom, because doesn't prevent disk IO operations. contains returns either "definitely in storage" or "definitely not".

Errors

Fails because of any IO errors

pub async fn check_bloom<'_>(&'_ self, key: impl Key) -> Option<bool>[src]

check_bloom is used to check whether a key is in storage. If bloom filter opt out, returns None. Uses bloom filter under the hood, so false positive results are possible, but false negatives are not. In other words, check_bloom returns either "possibly in storage" or "definitely not".

pub async fn records_count<'_>(&'_ self) -> usize[src]

Total records count in storage.

pub async fn records_count_detailed<'_>(&'_ self) -> Vec<(usize, usize)>[src]

Records count per blob. Format: (blob_id, count). Last value is from active blob.

pub async fn records_count_in_active_blob<'_>(&'_ self) -> Option<usize>[src]

Records count in active blob. Returns None if active blob not set or any IO error occured.

pub async fn fsyncdata<'_>(&'_ self) -> IOResult<()>[src]

Syncronizes data and metadata of the active blob with the filesystem. Like tokio::std::fs::File::sync_data, this function will attempt to ensure that in-core data reaches the filesystem before returning. May not syncronize file metadata to the file system.

Errors

Fails because of any IO errors

Trait Implementations

impl<K> Clone for Storage<K>[src]

impl<K: Debug> Debug for Storage<K>[src]

impl<K> Drop for Storage<K>[src]

Auto Trait Implementations

impl<K> !RefUnwindSafe for Storage<K>

impl<K> Send for Storage<K> where
    K: Send

impl<K> Sync for Storage<K> where
    K: Sync

impl<K> Unpin for Storage<K> where
    K: Unpin

impl<K> !UnwindSafe for Storage<K>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,