pub struct OpenOptions { /* private fields */ }Expand description
Options used to configured how an Index is opened.
Similar to std::fs::OpenOptions, to use this, first call new, then
chain calls to methods to set each option, finally call open to get
an Index structure.
Implementations§
Source§impl OpenOptions
impl OpenOptions
Sourcepub fn new() -> OpenOptions
pub fn new() -> OpenOptions
Create OpenOptions with default configuration:
- checksum enabled, with 1MB chunk size
- checksum max chain length is
config::INDEX_CHECKSUM_MAX_CHAIN_LEN(default: 10) - no external key buffer
- no fsync
- read root entry from the end of the file
- open as read-write but fallback to read-only
Sourcepub fn checksum_max_chain_len(&mut self, len: u32) -> &mut Self
pub fn checksum_max_chain_len(&mut self, len: u32) -> &mut Self
Set the maximum checksum chain length.
If it is non-zero, and the checksum chain (linked list of checksum
entries needed to verify the entire index) exceeds the specified length,
they will be collapsed into a single checksum entry to make open more
efficient.
Sourcepub fn checksum_chunk_size_logarithm(
&mut self,
checksum_chunk_size_logarithm: u32,
) -> &mut Self
pub fn checksum_chunk_size_logarithm( &mut self, checksum_chunk_size_logarithm: u32, ) -> &mut Self
Set checksum chunk size as 1 << checksum_chunk_size_logarithm.
Sourcepub fn checksum_enabled(&mut self, checksum_enabled: bool) -> &mut Self
pub fn checksum_enabled(&mut self, checksum_enabled: bool) -> &mut Self
Set whether to write checksum entries on flush.
Sourcepub fn fsync(&mut self, fsync: bool) -> &mut Self
pub fn fsync(&mut self, fsync: bool) -> &mut Self
Set fsync behavior.
If true, then Index::flush will use fsync to flush data to the
physical device before returning.
Sourcepub fn write(&mut self, value: Option<bool>) -> &mut Self
pub fn write(&mut self, value: Option<bool>) -> &mut Self
Set whether writing is required:
None: open as read-write but fallback to read-only.flush()may fail.Some(false): open as read-only.flush()will always fail.Some(true): open as read-write.open()fails if read-write is not possible.flush()will not fail due to permission issues.
Note: The index is always mutable in-memory. Only flush() may fail.
Sourcepub fn logical_len(&mut self, len: Option<u64>) -> &mut Self
pub fn logical_len(&mut self, len: Option<u64>) -> &mut Self
Specify the logical length of the file.
If len is None, use the actual file length. Otherwise, use the
length specified by len. Reading the file length requires locking.
This is useful for lock-free reads, or accessing to multiple versions of the index at the same time.
To get a valid logical length, check the return value of Index::flush.
Sourcepub fn key_buf(
&mut self,
buf: Option<Arc<dyn ReadonlyBuffer + Send + Sync>>,
) -> &mut Self
pub fn key_buf( &mut self, buf: Option<Arc<dyn ReadonlyBuffer + Send + Sync>>, ) -> &mut Self
Specify the external key buffer.
With an external key buffer, keys could be stored as references using
index.insert_advanced to save space.
Sourcepub fn open<P: AsRef<Path>>(&self, path: P) -> Result<Index>
pub fn open<P: AsRef<Path>>(&self, path: P) -> Result<Index>
Open the index file with given options.
Driven by the “immutable by default” idea, together with append-only
properties, OpenOptions::open returns a “snapshotted” view of the
index. Changes to the filesystem won’t change instantiated Indexes.
Sourcepub fn create_in_memory(&self) -> Result<Index>
pub fn create_in_memory(&self) -> Result<Index>
Create an in-memory Index that skips flushing to disk.
Return an error if checksum_chunk_size_logarithm is not 0.
Trait Implementations§
Source§impl Clone for OpenOptions
impl Clone for OpenOptions
Source§fn clone(&self) -> OpenOptions
fn clone(&self) -> OpenOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more