Struct pearl::Storage[][src]

pub struct Storage<K: Key> { /* fields omitted */ }
Expand description

A main storage struct.

This type is clonable, cloning it will only create a new reference, not a new storage. Storage has a type kindeter 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

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 kinds are missed.

init_lazy() used to prepare all environment to further work, but unlike init doesn’t set active blob, which means that first write may take time..

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.

Checks if there is a pending async operation Returns boolean value (true - if there is, false otherwise) Never falls

FIXME: maybe it would be better to add check of is_pending state of observer for all sync operations and return result in more appropriate way for that case (change Result on Result, where OpRes = Pending|Done|NotDone for example) Checks if active blob is set Returns boolean value Never falls

Creates active blob NOTICE! This function works in current thread, so it may take time. To perform this asyncronously, use [create_active_blob_in_background()] Returns true if new blob was created else false

Errors

Fails if it’s not possible to create new blob [create_active_blob_in_background()]: struct.Storage.html#method.create_active_blob_async

Creates active blob NOTICE! This function returns immediately, so you can’t check result of operation. If you want be sure about operation’s result, use [try_create_active_blob()] [try_create_active_blob()]: struct.Storage.html#method.try_create_active_blob

Dumps active blob NOTICE! This function works in current thread, so it may take time. To perform this asyncronously, use [close_active_blob_in_background()] Returns true if blob was really dumped else false

Errors

Fails if there are some errors during dump [close_active_blob_in_background()]: struct.Storage.html#method.create_active_blob_async

Dumps active blob NOTICE! This function returns immediately, so you can’t check result of operation. If you want be sure about operation’s result, use [try_close_active_blob()]

Sets last blob from closed blobs as active if there is no active blobs NOTICE! This function works in current thread, so it may take time. To perform this asyncronously, use [restore_active_blob_in_background()] Returns true if last blob was set as active as false

Errors

Fails if active blob is set or there is no closed blobs [restore_active_blob_in_background()]: struct.Storage.html#method.restore_active_blob_async

Sets last blob from closed blobs as active if there is no active blobs NOTICE! This function returns immediately, so you can’t check result of operation. If you want be sure about operation’s result, use [try_restore_active_blob()] [try_restore_active_blob()]: struct.Storage.html#method.try_restore_active_blob

Writes data to active blob asyncronously. If active blob reaches it limit, creates new and closes old. NOTICE! First write into storage without active blob may take more time due to active blob creation

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

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.

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

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.

Returns entries with matching key

Errors

Fails after any disk IO errors.

Stop blob updater and release lock file

Errors

Fails because of any IO errors

blob_count returns exact number of closed blobs plus one active, if there is some. It locks on inner structure, so it much slower than next_blob_id.

Examples
use pearl::Builder;

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

index_memory returns the amount of memory used by blob to store indices

Returns next blob ID. If pearl dir structure wasn’t changed from the outside, returned number is equal to blobs_count. But this method doesn’t require lock. So it is much faster than blobs_count.

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

check_filters is used to check whether a key is in storage. Range (min-max test) and bloom filters are used. If bloom filter opt out and range filter passes, returns None. False positive results are possible, but false negatives are not. In other words, check_filters returns either “possibly in storage” or “definitely not”.

Total records count in storage.

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

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

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.

Force updates active blob on new one to dump index of old one on disk and free RAM. This function was used previously instead of [close_active_blob_in_background()] Creates new active blob.

Errors

Fails because of any IO errors. Or if there are some problems with syncronization. [close_active_blob_in_background()]: struct.Storage.html#method.close_active_blob_async

Trait Implementations

Inner filter type

Check if element in filter

Check if element in filter

Returns freed memory

Returns overall filter

Returns overall filter

Returns allocated memory

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Attempts to convert self into T using TryInto<T>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.