Unmanaged database environment. More...
#include <mdbx.h++>
Inherited by mdbx::env_managed.
Classes | |
struct | geometry |
Database geometry for size management. More... | |
struct | limits |
struct | operate_options |
Operate options. More... | |
struct | operate_parameters |
Operate parameters. More... | |
struct | reader_info |
Reader information. More... | |
struct | reclaiming_options |
Garbage reclaiming options. More... | |
Public Types | |
enum | mode { readonly, write_file_io, write_mapped_io } |
Operation mode. More... | |
enum | durability { robust_synchronous, half_synchronous_weak_last, lazy_weak_tail, whole_fragile } |
Durability level. More... | |
enum | remove_mode { just_remove = MDBX_ENV_JUST_DELETE, ensure_unused = MDBX_ENV_ENSURE_UNUSED, wait_for_unused = MDBX_ENV_WAIT_FOR_UNUSED } |
Deletion modes for remove(). More... | |
using | stat = ::MDBX_stat |
Statistics for a database in the MDBX environment. More... | |
using | info = ::MDBX_envinfo |
Information about the environment. More... | |
Public Member Functions | |
MDBX_CXX11_CONSTEXPR | env () noexcept=default |
env (const env &) noexcept=default | |
env & | operator= (env &&other) noexcept |
env (env &&other) noexcept | |
~env () noexcept | |
MDBX_CXX14_CONSTEXPR | operator bool () const noexcept |
MDBX_CXX14_CONSTEXPR | operator const MDBX_env * () const |
MDBX_CXX14_CONSTEXPR | operator MDBX_env * () |
env::operate_parameters | get_operation_parameters () const |
Returns current operation parameters. More... | |
env::mode | get_mode () const |
Returns current operation mode. More... | |
env::durability | get_durability () const |
Returns current durability mode. More... | |
env::reclaiming_options | get_reclaiming () const |
Returns current reclaiming options. More... | |
env::operate_options | get_options () const |
Returns current operate options. More... | |
bool | is_pristine () const |
Returns true for a freshly created database, but false if at least one transaction was committed. More... | |
bool | is_empty () const |
Checks whether the database is empty. More... | |
size_t | dbsize_min () const |
Returns the minimal database size in bytes for the environment. More... | |
size_t | dbsize_max () const |
Returns the maximal database size in bytes for the environment. More... | |
size_t | key_min (key_mode mode) const noexcept |
Returns the minimal key size in bytes for specified keys mode. More... | |
size_t | key_max (key_mode mode) const |
Returns the maximal key size in bytes for specified keys mode. More... | |
size_t | value_min (value_mode mode) const noexcept |
Returns the minimal value size in bytes for specified values mode. More... | |
size_t | value_max (value_mode mode) const |
Returns the maximal value size in bytes for specified values mode. More... | |
size_t | transaction_size_max () const |
Returns the maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes. More... | |
env & | copy (const MDBX_STD_FILESYSTEM_PATH &destination, bool compactify, bool force_dynamic_size=false) |
Make a copy (backup) of an existing environment to the specified path. More... | |
env & | copy (const ::std::string &destination, bool compactify, bool force_dynamic_size=false) |
env & | copy (filehandle fd, bool compactify, bool force_dynamic_size=false) |
Copy an environment to the specified file descriptor. More... | |
stat | get_stat () const |
Returns snapshot statistics about the MDBX environment. More... | |
size_t | get_pagesize () const |
Returns pagesize of this MDBX environment. More... | |
info | get_info () const |
Return snapshot information about the MDBX environment. More... | |
stat | get_stat (const txn &) const |
Return statistics about the MDBX environment accordingly to the specified transaction. More... | |
info | get_info (const txn &) const |
Return information about the MDBX environment accordingly to the specified transaction. More... | |
filehandle | get_filehandle () const |
Returns the file descriptor for the DXB file of MDBX environment. More... | |
path | get_path () const |
Return the path that was used for opening the environment. More... | |
MDBX_env_flags_t | get_flags () const |
Returns environment flags. More... | |
unsigned | max_readers () const |
Returns the maximum number of threads/reader slots for the environment. More... | |
unsigned | max_maps () const |
Returns the maximum number of named databases for the environment. More... | |
void * | get_context () const noexcept |
Returns the application context associated with the environment. More... | |
env & | set_context (void *) |
Sets the application context associated with the environment. More... | |
env & | set_sync_threshold (size_t bytes) |
Sets threshold to force flush the data buffers to disk, for non-sync durability modes. More... | |
env & | set_sync_period (unsigned seconds_16dot16) |
Sets relative period since the last unsteady commit to force flush the data buffers to disk, for non-sync durability modes. More... | |
env & | set_sync_period (double seconds) |
Sets relative period since the last unsteady commit to force flush the data buffers to disk, for non-sync durability modes. More... | |
env & | alter_flags (MDBX_env_flags_t flags, bool on_off) |
Alter environment flags. More... | |
env & | set_geometry (const geometry &size) |
Set all size-related parameters of environment. More... | |
bool | sync_to_disk (bool force=true, bool nonblock=false) |
Flush the environment data buffers. More... | |
bool | poll_sync_to_disk () |
Performs non-blocking polling of sync-to-disk thresholds. More... | |
void | close_map (const map_handle &) |
Close a key-value map (aka sub-database) handle. Normally unnecessary. More... | |
template<typename VISITOR > | |
int | enumerate_readers (VISITOR &visitor) |
Enumerate readers. More... | |
unsigned | check_readers () |
Checks for stale readers in the lock table and return number of cleared slots. More... | |
env & | set_HandleSlowReaders (MDBX_hsr_func *) |
Sets a Handle-Slow-Readers callback to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled. More... | |
MDBX_hsr_func * | get_HandleSlowReaders () const noexcept |
Returns the current Handle-Slow-Readers callback used to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled. More... | |
txn_managed | start_read () const |
Starts read (read-only) transaction. More... | |
txn_managed | prepare_read () const |
Creates but not start read transaction. More... | |
txn_managed | start_write (bool dont_wait=false) |
Starts write (read-write) transaction. More... | |
txn_managed | try_start_write () |
Tries to start write (read-write) transaction without blocking. More... | |
Static Public Member Functions | |
static size_t | default_pagesize () noexcept |
Returns default page size for current system/platform. More... | |
static bool | remove (const MDBX_STD_FILESYSTEM_PATH &, const remove_mode mode=just_remove) |
Removes the environment's files in a proper and multiprocess-safe way. More... | |
static bool | remove (const ::std::string &, const remove_mode mode=just_remove) |
Protected Member Functions | |
MDBX_CXX11_CONSTEXPR | env (MDBX_env *ptr) noexcept |
Protected Attributes | |
MDBX_env * | handle_ {nullptr} |
Friends | |
class | txn |
MDBX_CXX11_CONSTEXPR bool | operator== (const env &a, const env &b) noexcept |
MDBX_CXX11_CONSTEXPR bool | operator!= (const env &a, const env &b) noexcept |
Unmanaged database environment.
Like other unmanaged classes, env
allows copying and assignment for instances, but does not destroys the represented underlying object from the own class destructor.
An environment supports multiple key-value sub-databases (aka key-value spaces or tables), all residing in the same shared-memory map.
using mdbx::env::info = ::MDBX_envinfo |
Information about the environment.
using mdbx::env::stat = ::MDBX_stat |
Statistics for a database in the MDBX environment.
Durability level.
Enumerator | |
---|---|
robust_synchronous | Default robust and durable sync mode. Metadata is written and flushed to disk after a data is written and flushed, which guarantees the integrity of the database in the event of a crash at any time.
|
half_synchronous_weak_last | Don't sync the meta-page after commit. Flush system buffers to disk only once per transaction commit, omit the metadata flush. Defer that until the system flushes files to disk, or next non-MDBX_RDONLY commit or mdbx_env_sync(). Depending on the platform and hardware, with MDBX_NOMETASYNC you may get a doubling of write performance. This trade-off maintains database integrity, but a system crash may undo the last committed transaction. I.e. it preserves the ACI (atomicity, consistency, isolation) but not D (durability) database property.
|
lazy_weak_tail | Don't sync anything but keep previous steady commits. Like MDBX_UTTERLY_NOSYNC the With MDBX_WRITEMAP the Depending on the platform and hardware, with In contrast to MDBX_UTTERLY_NOSYNC mode, with
In other words, with The number and volume of of disk IOPs with MDBX_SAFE_NOSYNC flag will exactly the as without any no-sync flags. However, you should expect a larger process's work set and significantly worse a locality of reference, due to the more intensive allocation of previously unused pages and increase the size of the database.
|
whole_fragile | Don't sync anything and wipe previous steady commits. Don't flush system buffers to disk when committing a transaction. This optimization means a system crash can corrupt the database, if buffers are not yet flushed to disk. Depending on the platform and hardware, with If the filesystem preserves write order (which is rare and never provided unless explicitly noted) and the MDBX_WRITEMAP and MDBX_LIFORECLAIM flags are not used, then a system crash can't corrupt the database, but you can lose the last transactions, if at least one buffer is not yet flushed to disk. The risk is governed by how often the system flushes dirty buffers to disk and how often mdbx_env_sync() is called. So, transactions exhibit ACI (atomicity, consistency, isolation) properties and only lose Otherwise, if the filesystem not preserves write order (which is typically) or MDBX_WRITEMAP or MDBX_LIFORECLAIM flags are used, you should expect the corrupted database after a system crash. So, most important thing about
Nevertheless,
|
enum mdbx::env::mode |
Operation mode.
Enumerator | |
---|---|
readonly | Read only mode. Open the environment in read-only mode. No write operations will be allowed. MDBX will still modify the lock file - except on read-only filesystems, where MDBX does not use locks.
This flag affects only at environment opening but can't be changed after. |
write_file_io | |
write_mapped_io | Map data into memory with write permission. Use a writeable memory map unless MDBX_RDONLY is set. This uses fewer mallocs and requires much less work for tracking database pages, but loses protection from application bugs like wild pointer writes and other bad updates into the database. This may be slightly faster for DBs that fit entirely in RAM, but is slower for DBs larger than RAM. Also adds the possibility for stray application writes thru pointers to silently corrupt the database.
This flag affects only at environment opening but can't be changed after. |
Deletion modes for remove().
|
protectednoexcept |
|
defaultnoexcept |
|
defaultnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Alter environment flags.
|
inline |
Checks for stale readers in the lock table and return number of cleared slots.
|
inline |
Close a key-value map (aka sub-database) handle. Normally unnecessary.
Closing a database handle is not necessary, but lets txn::open_map() reuse the handle value. Usually it's better to set a bigger env::operate_parameters::max_maps, unless that value would be large.
Handles should only be closed if no other threads are going to reference the database handle or one of its cursors any further. Do not close a handle if an existing transaction has modified its database. Doing so can cause misbehavior from database corruption to errors like MDBX_BAD_DBI (since the DB name is gone).
env& mdbx::env::copy | ( | const ::std::string & | destination, |
bool | compactify, | ||
bool | force_dynamic_size = false |
||
) |
env& mdbx::env::copy | ( | const MDBX_STD_FILESYSTEM_PATH & | destination, |
bool | compactify, | ||
bool | force_dynamic_size = false |
||
) |
Make a copy (backup) of an existing environment to the specified path.
env& mdbx::env::copy | ( | filehandle | fd, |
bool | compactify, | ||
bool | force_dynamic_size = false |
||
) |
Copy an environment to the specified file descriptor.
|
inline |
Returns the maximal database size in bytes for the environment.
|
inline |
Returns the minimal database size in bytes for the environment.
|
inlinestaticnoexcept |
Returns default page size for current system/platform.
|
inline |
Enumerate readers.
The VISITOR class must have int operator(const reader_info&, int serial)
which should return continue_loop (zero) to continue enumeration, or any non-zero value to exit.
|
inlinenoexcept |
Returns the application context associated with the environment.
|
inline |
Returns current durability mode.
|
inline |
Returns the file descriptor for the DXB file of MDBX environment.
|
inline |
Returns environment flags.
|
inlinenoexcept |
Returns the current Handle-Slow-Readers callback used to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled.
|
inline |
Return snapshot information about the MDBX environment.
Return information about the MDBX environment accordingly to the specified transaction.
|
inline |
Returns current operation mode.
|
inline |
Returns current operation parameters.
|
inline |
Returns current operate options.
|
inline |
Returns pagesize of this MDBX environment.
path mdbx::env::get_path | ( | ) | const |
Return the path that was used for opening the environment.
|
inline |
Returns current reclaiming options.
|
inline |
Returns snapshot statistics about the MDBX environment.
Return statistics about the MDBX environment accordingly to the specified transaction.
bool mdbx::env::is_empty | ( | ) | const |
Checks whether the database is empty.
bool mdbx::env::is_pristine | ( | ) | const |
Returns true
for a freshly created database, but false
if at least one transaction was committed.
|
inline |
Returns the maximal key size in bytes for specified keys mode.
|
inlinenoexcept |
Returns the minimal key size in bytes for specified keys mode.
|
inline |
Returns the maximum number of named databases for the environment.
|
inline |
Returns the maximum number of threads/reader slots for the environment.
|
noexcept |
MDBX_CXX14_CONSTEXPR mdbx::env::operator const MDBX_env * | ( | ) | const |
MDBX_CXX14_CONSTEXPR mdbx::env::operator MDBX_env * | ( | ) |
|
inline |
Performs non-blocking polling of sync-to-disk thresholds.
True
if sync done or no data to sync, or false
if the environment is busy by other thread or none of the thresholds are reached.
|
inline |
Creates but not start read transaction.
|
static |
|
static |
Removes the environment's files in a proper and multiprocess-safe way.
|
inline |
Sets the application context associated with the environment.
Set all size-related parameters of environment.
|
inline |
Sets a Handle-Slow-Readers callback to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled.
Such callback will be triggered in a case where there is not enough free space in the database due to long read transaction(s) which impedes reusing the pages of an old MVCC snapshot(s).
Using this callback you can choose how to resolve the situation:
|
inline |
Sets relative period since the last unsteady commit to force flush the data buffers to disk, for non-sync durability modes.
The relative period value affects all processes which operates with given environment until the last process close environment or a new value will be settled. Data is always written to disk when txn_managed::commit() is called, but the operating system may keep it buffered. MDBX always flushes the OS buffers upon commit as well, unless the environment was opened with whole_fragile, lazy_weak_tail or in part half_synchronous_weak_last. Settled period don't checked asynchronously, but only by the txn_managed::commit() and env::sync_to_disk() functions. Therefore, in cases where transactions are committed infrequently and/or irregularly, polling by env::poll_sync_to_disk() may be a reasonable solution to timeout enforcement. The default is 0, than mean no any timeout checked, and no additional flush will be made.
[in] | seconds | The period in second when a synchronous flush would be made since the last unsteady commit. |
|
inline |
Sets relative period since the last unsteady commit to force flush the data buffers to disk, for non-sync durability modes.
The relative period value affects all processes which operates with given environment until the last process close environment or a new value will be settled. Data is always written to disk when txn_managed::commit() is called, but the operating system may keep it buffered. MDBX always flushes the OS buffers upon commit as well, unless the environment was opened with whole_fragile, lazy_weak_tail or in part half_synchronous_weak_last. Settled period don't checked asynchronously, but only by the txn_managed::commit() and env::sync_to_disk() functions. Therefore, in cases where transactions are committed infrequently and/or irregularly, polling by env::poll_sync_to_disk() may be a reasonable solution to timeout enforcement. The default is 0, than mean no any timeout checked, and no additional flush will be made.
[in] | seconds_16dot16 | The period in 1/65536 of second when a synchronous flush would be made since the last unsteady commit. |
|
inline |
Sets threshold to force flush the data buffers to disk, for non-sync durability modes.
The threshold value affects all processes which operates with given environment until the last process close environment or a new value will be settled. Data is always written to disk when txn_managed::commit() is called, but the operating system may keep it buffered. MDBX always flushes the OS buffers upon commit as well, unless the environment was opened with whole_fragile, lazy_weak_tail or in part half_synchronous_weak_last. The default is 0, than mean no any threshold checked, and no additional flush will be made.
|
inline |
Starts read (read-only) transaction.
|
inline |
Starts write (read-write) transaction.
Flush the environment data buffers.
True
if sync done or no data to sync, or false
if the environment is busy by other thread or none of the thresholds are reached.
|
inline |
Returns the maximal write transaction size (i.e. limit for summary volume of dirty pages) in bytes.
|
inline |
Tries to start write (read-write) transaction without blocking.
|
inline |
Returns the maximal value size in bytes for specified values mode.
|
inlinenoexcept |
Returns the minimal value size in bytes for specified values mode.
|
friend |
|
friend |
|
friend |
|
protected |