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_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
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.
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.
pub async fn force_update_active_blob(
&self,
predicate: fn(_: Option<ActiveBlobStat>) -> bool
)
pub async fn force_update_active_blob(
&self,
predicate: fn(_: Option<ActiveBlobStat>) -> bool
)
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
type Filter = <Blob<K> as BloomProvider<K>>::Filter
type Filter = <Blob<K> as BloomProvider<K>>::Filter
Inner filter type
fn check_filter<'life0, 'life1, 'async_trait>(
&'life0 self,
item: &'life1 K
) -> Pin<Box<dyn Future<Output = FilterResult> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn check_filter<'life0, 'life1, 'async_trait>(
&'life0 self,
item: &'life1 K
) -> Pin<Box<dyn Future<Output = FilterResult> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Check if element in filter
Check if element in filter
Returns freed memory
Returns overall filter
Returns overall filter
Auto Trait Implementations
impl<K> !RefUnwindSafe for Storage<K>
impl<K> !UnwindSafe for Storage<K>
Blanket Implementations
Mutably borrows from an owned value. Read more
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
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
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
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.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more