Skip to main content

DatabaseEnv

Struct DatabaseEnv 

Source
pub struct DatabaseEnv { /* private fields */ }
Available on crate feature mdbx only.
Expand description

Wrapper for the libmdbx environment: Environment

Implementations§

Source§

impl DatabaseEnv

Source

pub fn open( path: &Path, kind: DatabaseEnvKind, args: DatabaseArguments, ) -> Result<Self, DatabaseError>

Opens the database at the specified path with the given EnvKind.

It does not create the tables, for that call DatabaseEnv::create_tables.

Source

pub fn with_metrics(self) -> Self

Enables metrics on the database.

Source

pub fn with_metrics_if(self, enabled: bool) -> Self

Enables metrics on the database if requested.

Source

pub fn create_tables(&mut self) -> Result<(), DatabaseError>

Creates all the tables defined in Tables, if necessary.

This keeps tracks of the created table handles and stores them for better efficiency.

Source

pub fn create_and_track_tables_for<TS: TableSet>( &mut self, ) -> Result<(), DatabaseError>

Creates all the tables defined in the given TableSet, if necessary.

This keeps tracks of the created table handles and stores them for better efficiency.

Source

pub fn create_tables_for<TS: TableSet>( self: &mut Arc<Self>, ) -> Result<(), DatabaseError>

Creates all the tables defined in Tables, if necessary.

If this type is unique the created handle for the tables will be updated.

This is recommended to be called during initialization to create and track additional tables after the default Self::create_tables are created.

Source

pub fn drop_orphan_table(&self, name: &str) -> Result<bool, DatabaseError>

Drops an orphaned table by name.

This is used to clean up tables that are no longer defined in the schema but may still exist on disk from previous versions.

Returns Ok(true) if the table existed and was dropped, Ok(false) if the table was not found.

§Safety

This permanently deletes the table and all its data. Only use for tables that are confirmed to be obsolete.

Source

pub fn record_client_version( &self, version: ClientVersion, ) -> Result<(), DatabaseError>

Records version that accesses the database with write privileges.

Source

pub const fn with_disable_long_read_transaction_safety(self) -> Self

Disables timeouts and long-read backtrace reporting for transactions opened through this handle. Existing transactions and other previously cloned handles are unaffected.

Use for offline work that intentionally holds transactions open.

Methods from Deref<Target = Environment>§

Source

pub fn is_write_map(&self) -> bool

Returns true if the environment was opened as WRITEMAP.

Source

pub fn env_kind(&self) -> EnvironmentKind

Returns the kind of the environment.

Source

pub fn is_read_write(&self) -> Result<bool, Error>

Returns true if the environment was opened in crate::Mode::ReadWrite mode.

Source

pub fn is_read_only(&self) -> Result<bool, Error>

Returns true if the environment was opened in crate::Mode::ReadOnly mode.

Source

pub fn timed_out_not_aborted_transactions(&self) -> usize

Available on crate feature read-tx-timeouts only.

Returns the number of timed out transactions that were not aborted by the user yet.

Source

pub fn begin_ro_txn(&self) -> Result<Transaction<RO>, Error>

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

Reuses a previously-reset transaction handle from the internal pool when available, avoiding the lck_rdt_lock mutex in MDBX’s mvcc_bind_slot on each new transaction.

Source

pub fn begin_rw_txn(&self) -> Result<Transaction<RW>, Error>

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, Error>

Flush the environment data buffers to disk.

Source

pub fn stat(&self) -> Result<Stat, Error>

Retrieves statistics about this environment.

Source

pub fn info(&self) -> Result<Info, Error>

Retrieves info about this environment.

Source

pub fn freelist(&self) -> Result<usize, Error>

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 DatabaseEnv

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Database for DatabaseEnv

Source§

type TX = Tx<RO>

Read-Only database transaction
Source§

type TXMut = Tx<RW>

Read-Write database transaction
Source§

fn tx(&self) -> Result<Self::TX, DatabaseError>

Create read only transaction.
Source§

fn tx_mut(&self) -> Result<Self::TXMut, DatabaseError>

Create read write transaction only possible if database is open with write access.
Source§

fn path(&self) -> PathBuf

Returns the path to the database directory.
Source§

fn oldest_reader_txnid(&self) -> Option<u64>

Returns the transaction ID of the oldest active reader, if available. Read more
Source§

fn last_txnid(&self) -> Option<u64>

Returns the ID of the most recently committed transaction, if available.
§

fn view<T, F>(&self, f: F) -> Result<T, DatabaseError>
where F: FnOnce(&mut Self::TX) -> T,

Takes a function and passes a read-only transaction into it, making sure it’s closed in the end of the execution.
§

fn update<T, F>(&self, f: F) -> Result<T, DatabaseError>
where F: FnOnce(&Self::TXMut) -> T,

Takes a function and passes a write-read transaction into it, making sure it’s committed in the end of the execution.
Source§

impl DatabaseMetrics for DatabaseEnv

Source§

fn report_metrics(&self)

Reports metrics for the database.
Source§

fn gauge_metrics(&self) -> Vec<(&'static str, f64, Vec<Label>)>

Returns a list of Gauge metrics for the database.
§

fn counter_metrics(&self) -> Vec<(&'static str, u64, Vec<Label>)>

Returns a list of Counter metrics for the database.
§

fn histogram_metrics(&self) -> Vec<(&'static str, f64, Vec<Label>)>

Returns a list of Histogram metrics for the database.
Source§

impl Debug for DatabaseEnv

Source§

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

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

impl Deref for DatabaseEnv

Source§

type Target = Environment

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeDebug for T
where T: Debug,

§

impl<T> NonStaticAny for T
where T: ?Sized,

§

fn type_id(&self) -> TypeId

Returns the lifetime-erased type ID of self.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<DB> ReaderTxnTracker for DB
where DB: Database,

§

fn wait_for_pre_commit_readers(&self)

Waits until all readers older than the latest committed txnid have drained.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types #44874)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

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: 64 bytes