Struct OpenOptions

Source
pub struct OpenOptions { /* private fields */ }
Expand description

Options used to configured how an Log is opened.

Implementations§

Source§

impl OpenOptions

Source

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.

Source

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.

Source

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.

Source

pub fn fold_def( self, name: &'static str, create_fold: fn() -> Box<dyn Fold>, ) -> Self

Add a “fold” definition. See FoldDef and Fold for details.

Source

pub fn index_defs(self, index_defs: Vec<IndexDef>) -> Self

Sets index definitions.

See IndexDef::new for details.

Source

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.

Source

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 call sync automatically.
  • Some(size): Call sync when the in-memory buffer exceeds size.
  • Some(0): Call sync after every append automatically.
Source

pub fn checksum_type(self, checksum_type: ChecksumType) -> Self

Sets the checksum type.

See ChecksumType for details.

Source

pub fn flush_filter(self, flush_filter: Option<FlushFilterFunc>) -> Self

Sets the flush filter function.

The function will be called at Log::sync time, if there are changes to the log since open (or last sync) time.

The filter function can be used to avoid writing content that already exists in the Log, or rewrite content as needed.

Source

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::sync is called. This maps to traditional “database transaction” concepts: a Log is always bounded to a transaction. Log::sync is like committing the transaction. Dropping the Log instance is like abandoning a transaction.
Source§

impl OpenOptions

Source

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

Source

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

Source§

fn clone(&self) -> OpenOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OpenWithRepair for T
where T: OpenOptionsOutput + OpenOptionsRepair,

Source§

type Output = <T as OpenOptionsOutput>::Output

Source§

fn open_with_repair( &self, path: impl AsRef<Path>, ) -> Result<<T as OpenWithRepair>::Output, Error>

Call open. If it fails with data corruption errors, try repair once, then open again. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more