pub struct Database<E>where
E: DatabaseKind,{ /* private fields */ }
Expand description
Supports multiple tables, all residing in the same shared-memory map.
Implementations§
Source§impl<E> Database<E>where
E: DatabaseKind,
impl<E> Database<E>where
E: DatabaseKind,
pub fn open_with_options( path: impl AsRef<Path>, options: DatabaseOptions, ) -> Result<Database<E>>
Sourcepub fn ptr(&self) -> DbPtr
pub fn ptr(&self) -> DbPtr
Returns a raw pointer to the underlying MDBX database.
The caller must ensure that the pointer is not dereferenced after the lifetime of the database.
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 database.
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 database. This method will block while there are any other read-write transactions open on the database.
Sourcepub fn freelist(&self) -> Result<usize>
pub fn freelist(&self) -> Result<usize>
Retrieves the total number of pages on the freelist.
Along with Database::info(), this can be used to calculate the exact number of used pages as well as free pages in this database.
let dir = tempfile::tempdir().unwrap();
let db = Database::<NoWriteMap>::open(&dir).unwrap();
let info = db.info().unwrap();
let stat = db.stat().unwrap();
let freelist = db.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 table 0 in each database, and the freelist count is stored at the beginning of the value as 32-bit integer in the native byte order.
-
It will create a read transaction to traverse the freelist table.