Struct reth_libmdbx::Environment

source ·
pub struct Environment { /* private fields */ }
Expand description

An environment supports multiple databases, all residing in the same shared-memory map.

Accessing the environment is thread-safe. The environment will be closed when the last instance of this type is dropped.

Implementations§

source§

impl Environment

source

pub fn builder() -> EnvironmentBuilder

Creates a new builder for specifying options for opening an MDBX environment.

source

pub fn is_write_map(&self) -> bool

Returns true if the environment was opened as WRITEMAP.

source

pub fn env_kind(&self) -> EnvironmentKind

Returns the kind of the environment.

source

pub fn is_read_write(&self) -> bool

Returns true if the environment was opened in crate::Mode::ReadWrite mode.

source

pub fn is_read_only(&self) -> bool

Returns true if the environment was opened in crate::Mode::ReadOnly mode.

source

pub fn timed_out_not_aborted_transactions(&self) -> usize

Available on crate feature read-tx-timeouts only.

Returns the number of timed out transactions that were not aborted by the user yet.

source

pub fn begin_ro_txn(&self) -> Result<Transaction<RO>>

Create a read-only transaction for use with the environment.

source

pub fn begin_rw_txn(&self) -> Result<Transaction<RW>>

Create a read-write transaction for use with the environment. This method will block while there are any other read-write transactions open on the environment.

source

pub fn sync(&self, force: bool) -> Result<bool>

Flush the environment data buffers to disk.

source

pub fn stat(&self) -> Result<Stat>

Retrieves statistics about this environment.

source

pub fn info(&self) -> Result<Info>

Retrieves info about this environment.

source

pub fn freelist(&self) -> Result<usize>

Retrieves the total number of pages on the freelist.

Along with Environment::info(), this can be used to calculate the exact number of used pages as well as free pages in this environment.

let dir = tempfile::tempdir().unwrap();
let env = Environment::builder().open(dir.path()).unwrap();
let info = env.info().unwrap();
let stat = env.stat().unwrap();
let freelist = env.freelist().unwrap();
let last_pgno = info.last_pgno() + 1; // pgno is 0 based.
let total_pgs = info.map_size() / stat.page_size() as usize;
let pgs_in_use = last_pgno - freelist;
let pgs_free = total_pgs - pgs_in_use;

Note:

  • MDBX stores all the freelists in the designated database 0 in each environment, and the freelist count is stored at the beginning of the value as uint32_t in the native byte order.

  • It will create a read transaction to traverse the freelist database.

Trait Implementations§

source§

impl Clone for Environment

source§

fn clone(&self) -> Environment

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 Debug for Environment

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 8 bytes