pub struct OpenOptions { /* private fields */ }Expand description
Options used to configured how an Log is opened.
Implementations§
Source§impl OpenOptions
impl OpenOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a blank new set of options ready for configuration.
create is initially false.
fsync is initially false.
index_defs is initially empty.
auto_sync_threshold is initially None.
Sourcepub fn fsync(self, fsync: bool) -> Self
pub fn fsync(self, fsync: bool) -> Self
Set fsync behavior.
If true, then Log::sync will use fsync to flush log and index
data to the physical device before returning.
Sourcepub fn index(
self,
name: &'static str,
func: fn(&[u8]) -> Vec<IndexOutput>,
) -> Self
pub fn index( self, name: &'static str, func: fn(&[u8]) -> Vec<IndexOutput>, ) -> Self
Add an index function.
This is a convenient way to define indexes without using IndexDef
explicitly.
Sourcepub fn index_defs(self, index_defs: Vec<IndexDef>) -> Self
pub fn index_defs(self, index_defs: Vec<IndexDef>) -> Self
Sets index definitions.
See IndexDef::new for details.
Sourcepub fn create(self, create: bool) -> Self
pub fn create(self, create: bool) -> Self
Sets the option for whether creating a new Log if it does not exist.
If set to true, OpenOptions::open will create the Log on demand if
it does not already exist. If set to false, OpenOptions::open will
fail if the log does not exist.
Sourcepub fn auto_sync_threshold(self, threshold: impl Into<Option<u64>>) -> Self
pub fn auto_sync_threshold(self, threshold: impl Into<Option<u64>>) -> Self
Sets whether to call Log::sync automatically when the in-memory
buffer exceeds some size threshold.
None: Do not callsyncautomatically.Some(size): Callsyncwhen the in-memory buffer exceedssize.Some(0): Callsyncafter everyappendautomatically.
Sourcepub fn checksum_type(self, checksum_type: ChecksumType) -> Self
pub fn checksum_type(self, checksum_type: ChecksumType) -> Self
Sets the checksum type.
See ChecksumType for details.
Sourcepub fn flush_filter(self, flush_filter: Option<FlushFilterFunc>) -> Self
pub fn flush_filter(self, flush_filter: Option<FlushFilterFunc>) -> Self
Sourcepub fn open(&self, dir: impl Into<GenericPath>) -> Result<Log>
pub fn open(&self, dir: impl Into<GenericPath>) -> Result<Log>
Construct Log at given directory. Incrementally build up specified
indexes.
If the directory does not exist and create is set to true, it will
be created with essential files populated. After that, an empty Log
will be returned. Otherwise, open will fail.
See IndexDef for index definitions. Indexes can be added, removed, or
reordered, as long as a same name indicates a same index function.
That is, when an index function is changed, the caller is responsible
for changing the index name.
Driven by the “immutable by default” idea, together with append-only properties, this structure is different from some traditional mutable databases backed by the filesystem:
- Data are kind of “snapshotted and frozen” at open time. Mutating
files do not affect the view of instantiated
Logs. - Writes are buffered until
Log::syncis called. This maps to traditional “database transaction” concepts: aLogis always bounded to a transaction.Log::syncis like committing the transaction. Dropping theLoginstance is like abandoning a transaction.
Source§impl OpenOptions
impl OpenOptions
Sourcepub fn repair(&self, dir: impl Into<GenericPath>) -> Result<String>
pub fn repair(&self, dir: impl Into<GenericPath>) -> Result<String>
Attempt to repair a broken Log at the given directory.
This is done by truncating entries in the primary log, and rebuilding corrupted indexes.
Backup files are written for further investigation.
Return message useful for human consumption.
Source§impl OpenOptions
impl OpenOptions
Sourcepub fn delete_content(&self, dir: impl Into<GenericPath>) -> Result<()>
pub fn delete_content(&self, dir: impl Into<GenericPath>) -> Result<()>
Attempt to change a Log at the given directory so it becomes
empty and hopefully recovers from some corrupted state.
Warning: This deletes data, and there is no backup!
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