Struct mmtkvdb::EnvBuilder

source ·
pub struct EnvBuilder<P> { /* private fields */ }
Expand description

Options for opening an environment

This struct follows the builder pattern. Start with EnvBuilder::new and open the environment with EnvBuilder::open_ro (for read-only access) or EnvBuilder::open_rw (for read-write access).

Caveats / Safety

Do not open the same environment twice in the same process at the same time.

Since this cannot be easily ensured (and because the environment must be free of corruption on the storage medium), open_ro and open_rw are marked as unsafe. Use Env::clone_ro to (re-)open an already open environment in read-only mode.

The file format is platform specific, so endianness and word size must not change across use.

Example

// question mark operator may return with `std::io::Error`
use mmtkvdb::{self as kv, traits::*};
use tempfile::tempdir;
let location = tempdir()?;
let env_builder = kv::EnvBuilder::new().dir(location.path()).max_dbs(1);
// SAFETY:
// * database isn't opened twice in this process at the same time
// * it is assumed no other processes access the environment
// * since environment is newly created, it matches the platform
let mut env_rw = unsafe { env_builder.open_rw() }?;
let env_ro = env_rw.clone_ro();

Implementations§

source§

impl EnvBuilder<()>

source

pub const fn new() -> Self

Default options for environment

source§

impl<P> EnvBuilder<P>

source

pub fn dir<'a>( self, path: &'a impl AsRef<Path> + ?Sized ) -> EnvBuilder<&'a Path>

Set directory location

Overwrites a previously set directory or file location.

source

pub fn file<'a>( self, path: &'a impl AsRef<Path> + ?Sized ) -> EnvBuilder<&'a Path>

Set file location

Overwrites a previously set directory or file location.

source

pub const fn get_writemap(&self) -> bool

Get write-map option

source

pub const fn writemap(self, flag: bool) -> Self

Set or clear write-map option

Enabling this option is incompatible with nested transactions (see TxnRw::nested).

source

pub const fn get_nometasync(&self) -> bool

Get no-meta-sync option

source

pub const fn nometasync(self, flag: bool) -> Self

Set or clear no-meta-sync option

source

pub const fn get_nosync(&self) -> bool

Get no-sync option

source

pub const fn nosync(self, flag: bool) -> Self

Set or clear no-sync option

source

pub const fn get_mapasync(&self) -> bool

Get map-async option

source

pub const fn mapasync(self, flag: bool) -> Self

Set or clear map-async option

source

pub const fn get_nordahead(&self) -> bool

Get no-read-ahead option

source

pub const fn nordahead(self, flag: bool) -> Self

Set or clear no-read-ahead option

source

pub const fn get_max_size(&self) -> usize

Get maximum environment size

source

pub const fn max_size(self, max_size: usize) -> Self

Set maximum environment size

source

pub const fn get_max_readers(&self) -> usize

Get maximum number of concurrent readers

source

pub const fn max_readers(self, max_readers: usize) -> Self

Set maximum number of concurrent readers

source

pub const fn get_max_dbs(&self) -> usize

Get maximum number of named databases

source

pub const fn max_dbs(self, max_dbs: usize) -> Self

Set maximum number of named databases

source

pub const fn get_unix_file_mode(&self) -> u32

Get file mode

source

pub const fn unix_file_mode(self, mode: u32) -> Self

Set file mode

source

pub const fn nestable_txns(&self) -> bool

Check if transactions are nestable with current options

See TxnRw::nested.

source§

impl<'a> EnvBuilder<&'a Path>

source

pub unsafe fn open_ro(&self) -> Result<EnvRo>

Open environment in read-only mode

Safety
  • Do not open the same environment twice in the same process at the same time.
  • The environment must be free of corruption on the storage medium and no other processes may corrupt the environment on the storage medium.
  • The file format is platform specific, so endianness and word size must not change across use.
source

pub unsafe fn open_rw(&self) -> Result<EnvRw>

Open environment in read-write mode

Safety
  • Do not open the same environment twice in the same process at the same time.
  • The environment must be free of corruption on the storage medium and no other processes may corrupt the environment on the storage medium.
  • The file format is platform specific, so endianness and word size must not change across use.

Trait Implementations§

source§

impl<P: Clone> Clone for EnvBuilder<P>

source§

fn clone(&self) -> EnvBuilder<P>

Returns a copy 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<P: Debug> Debug for EnvBuilder<P>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> RefUnwindSafe for EnvBuilder<P>where P: RefUnwindSafe,

§

impl<P> Send for EnvBuilder<P>where P: Send,

§

impl<P> Sync for EnvBuilder<P>where P: Sync,

§

impl<P> Unpin for EnvBuilder<P>where P: Unpin,

§

impl<P> UnwindSafe for EnvBuilder<P>where P: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.