pub struct Builder { /* private fields */ }
Expand description
Is used to initialize a Storage
.
Required params:
work_dir
- whereStorage
will keep blob and index filesmax_blob_size
- upper limit of blob file sizemax_data_in_blob
- maximum number of records in one blobblob_file_name_prefix
- prefix in blob file name pattern: {prefix}.{id}.{ext}key_size
- const key size in bytes
Example
use pearl::{Builder, Storage, ArrayKey};
let storage: Storage<ArrayKey<8>> = Builder::new()
.blob_file_name_prefix("benchmark")
.max_blob_size(10_000_000)
.max_data_in_blob(1_000)
.work_dir(std::env::temp_dir().join("pearl_benchmark"))
.build()
.unwrap();
Implementations§
source§impl Builder
impl Builder
sourcepub fn build<K>(self) -> Result<Storage<K>>where
for<'a> K: Key<'a> + 'static,
pub fn build<K>(self) -> Result<Storage<K>>where
for<'a> K: Key<'a> + 'static,
Creates Storage
based on given configuration,
returns error if not all params are set.
Errors
Return error if some of the required params is missed or wrong
sourcepub fn work_dir<S: Into<PathBuf>>(self, work_dir: S) -> Self
pub fn work_dir<S: Into<PathBuf>>(self, work_dir: S) -> Self
Sets working directory. If path doesn’t exists, Storage will try to create it at initialization stage.
sourcepub fn corrupted_dir_name(self, name: impl Into<String>) -> Self
pub fn corrupted_dir_name(self, name: impl Into<String>) -> Self
Sets directory name for corrupted files. If path doesn’t exists, Storage will try to create it at initialization stage.
sourcepub fn max_blob_size(self, max_blob_size: u64) -> Self
pub fn max_blob_size(self, max_blob_size: u64) -> Self
Sets blob file size approximate limit. When the file size exceeds it, active blob update is activated. Must be greater than zero
sourcepub fn max_data_in_blob(self, max_data_in_blob: u64) -> Self
pub fn max_data_in_blob(self, max_data_in_blob: u64) -> Self
Limits max number of records in a single blob. Must be greater than zero
sourcepub fn blob_file_name_prefix<U: Into<String>>(
self,
blob_file_name_prefix: U
) -> Self
pub fn blob_file_name_prefix<U: Into<String>>( self, blob_file_name_prefix: U ) -> Self
Sets blob file name prefix, e.g. if prefix set to hellopearl
,
files will be named as hellopearl.[N].blob
.
Where N - index number of file
If the prefix is empty, param won’t be set.
sourcepub fn allow_duplicates(self) -> Self
pub fn allow_duplicates(self) -> Self
Disables check existence of the record on write. Writing becomes faster because there is no additional disk access for searching for duplicates.
sourcepub fn ignore_corrupted(self) -> Self
pub fn ignore_corrupted(self) -> Self
Ignores blobs with corrupted header for index file and continues work with normal ones (also leaves error logs for bad blobs). It’s worth noticing that index file maybe corrupted likely in case of irregular stop of the storage: either the disk disconnected or server crashed. In these cases blob file is likely either corrupted, so there is no a try to restore indices from blob file.
sourcepub fn set_filter_config(self, config: BloomConfig) -> Self
pub fn set_filter_config(self, config: BloomConfig) -> Self
Sets custom bloom filter config, if not set, use default values.
sourcepub fn set_validate_data_during_index_regen(self, value: bool) -> Self
pub fn set_validate_data_during_index_regen(self, value: bool) -> Self
Enables or disables data checksum validation during index regeneration
sourcepub fn create_work_dir(self, create: bool) -> Self
pub fn create_work_dir(self, create: bool) -> Self
[Optional]
Sets whether to create work directory if its missing on storage initialization.
Default value is true
sourcepub fn set_io_driver(self, iodriver: IoDriver) -> Self
pub fn set_io_driver(self, iodriver: IoDriver) -> Self
Set io driver to be used during file io operations. If the driver is not set, then sync
is used as the default
sourcepub fn set_dump_sem(self, dump_sem: Arc<Semaphore>) -> Self
pub fn set_dump_sem(self, dump_sem: Arc<Semaphore>) -> Self
Sets semaphore for index dumping on blob change. Parallel saving of indexes onto the disk will be limited by this semaphore. This can prevent disk overusage in systems with multiple pearls.
sourcepub fn set_bloom_filter_group_size(self, size: usize) -> Self
pub fn set_bloom_filter_group_size(self, size: usize) -> Self
Sets bloom filter group size
sourcepub fn set_deferred_index_dump_times(self, min: Duration, max: Duration) -> Self
pub fn set_deferred_index_dump_times(self, min: Duration, max: Duration) -> Self
Set min and max waiting time for deferred index dump
sourcepub fn set_max_dirty_bytes_before_sync(self, bytes: u64) -> Self
pub fn set_max_dirty_bytes_before_sync(self, bytes: u64) -> Self
Set max dirty bytes before filesync will be performed in background