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 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_tin 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 more