Struct libmdbx::Environment
source · [−]pub struct Environment<E> where
E: EnvironmentKind, { /* private fields */ }Expand description
An environment supports multiple databases, all residing in the same shared-memory map.
Implementations
sourceimpl<E> Environment<E> where
E: EnvironmentKind,
impl<E> Environment<E> where
E: EnvironmentKind,
sourcepub fn new() -> EnvironmentBuilder<E>
pub fn new() -> EnvironmentBuilder<E>
Creates a new builder for specifying options for opening an MDBX environment.
sourcepub fn env(&self) -> *mut MDBX_env
pub fn env(&self) -> *mut MDBX_env
Returns a raw pointer to the underlying MDBX environment.
The caller must ensure that the pointer is not dereferenced after the lifetime of the environment.
sourcepub fn begin_ro_txn(&self) -> Result<Transaction<'_, RO, E>>
pub fn begin_ro_txn(&self) -> Result<Transaction<'_, RO, E>>
Create a read-only transaction for use with the environment.
sourcepub fn begin_rw_txn(&self) -> Result<Transaction<'_, RW, E>>
pub fn begin_rw_txn(&self) -> Result<Transaction<'_, RW, E>>
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::<NoWriteMap>::new().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:
-
LMDB 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
libc::size_tin the native byte order. -
It will create a read transaction to traverse the freelist database.
Trait Implementations
sourceimpl<E> Debug for Environment<E> where
E: EnvironmentKind,
impl<E> Debug for Environment<E> where
E: EnvironmentKind,
sourceimpl<E> Drop for Environment<E> where
E: EnvironmentKind,
impl<E> Drop for Environment<E> where
E: EnvironmentKind,
impl<E> Send for Environment<E> where
E: EnvironmentKind,
impl<E> Sync for Environment<E> where
E: EnvironmentKind,
Auto Trait Implementations
impl<E> RefUnwindSafe for Environment<E> where
E: RefUnwindSafe,
impl<E> Unpin for Environment<E> where
E: Unpin,
impl<E> UnwindSafe for Environment<E> where
E: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more