reth_libmdbx

Struct 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) -> Result<bool>

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

Source

pub fn is_read_only(&self) -> Result<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