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
impl Environment
Sourcepub fn builder() -> EnvironmentBuilder
pub fn builder() -> EnvironmentBuilder
Creates a new builder for specifying options for opening an MDBX environment.
Sourcepub fn is_write_map(&self) -> bool
pub fn is_write_map(&self) -> bool
Returns true if the environment was opened as WRITEMAP.
Sourcepub fn env_kind(&self) -> EnvironmentKind
pub fn env_kind(&self) -> EnvironmentKind
Returns the kind of the environment.
Sourcepub fn is_read_write(&self) -> Result<bool>
pub fn is_read_write(&self) -> Result<bool>
Returns true if the environment was opened in crate::Mode::ReadWrite
mode.
Sourcepub fn is_read_only(&self) -> Result<bool>
pub fn is_read_only(&self) -> Result<bool>
Returns true if the environment was opened in crate::Mode::ReadOnly
mode.
Sourcepub fn timed_out_not_aborted_transactions(&self) -> usize
Available on crate feature read-tx-timeouts
only.
pub fn timed_out_not_aborted_transactions(&self) -> usize
read-tx-timeouts
only.Returns the number of timed out transactions that were not aborted by the user yet.
Sourcepub fn begin_ro_txn(&self) -> Result<Transaction<RO>>
pub fn begin_ro_txn(&self) -> Result<Transaction<RO>>
Create a read-only transaction for use with the environment.
Sourcepub fn begin_rw_txn(&self) -> Result<Transaction<RW>>
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.
Sourcepub fn freelist(&self) -> Result<usize>
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
impl Clone for Environment
Source§fn clone(&self) -> Environment
fn clone(&self) -> Environment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for Environment
impl !RefUnwindSafe for Environment
impl Send for Environment
impl Sync for Environment
impl Unpin for Environment
impl !UnwindSafe for Environment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
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