Struct libmdbx::Database

source ·
pub struct Database<E>where
    E: DatabaseKind,
{ /* private fields */ }
Expand description

An environment supports multiple tables, all residing in the same shared-memory map.

Implementations§

source§

impl<E> Database<E>where
    E: DatabaseKind,

source

pub fn new() -> DatabaseBuilder<E>

Creates a new builder for specifying options for opening an MDBX environment.

source

pub fn ptr(&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.

source

pub fn begin_ro_txn(&self) -> Result<Transaction<'_, RO, E>>

Create a read-only transaction for use with the environment.

source

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.

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 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>::new().open(dir.path()).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 libc::size_t in the native byte order.

  • It will create a read transaction to traverse the freelist table.

Trait Implementations§

source§

impl<E> Debug for Database<E>where
    E: DatabaseKind,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<E> Drop for Database<E>where
    E: DatabaseKind,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<E> Send for Database<E>where
    E: DatabaseKind,

source§

impl<E> Sync for Database<E>where
    E: DatabaseKind,

Auto Trait Implementations§

§

impl<E> RefUnwindSafe for Database<E>where
    E: RefUnwindSafe,

§

impl<E> Unpin for Database<E>where
    E: Unpin,

§

impl<E> UnwindSafe for Database<E>where
    E: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.