Typedefs | |
typedef enum MDBX_env_flags_t | MDBX_env_flags_t |
Enumerations | |
enum | MDBX_env_flags_t { MDBX_ENV_DEFAULTS = 0, MDBX_NOSUBDIR = UINT32_C(0x4000), MDBX_RDONLY = UINT32_C(0x20000), MDBX_EXCLUSIVE = UINT32_C(0x400000), MDBX_ACCEDE = UINT32_C(0x40000000), MDBX_WRITEMAP = UINT32_C(0x80000), MDBX_NOTLS = UINT32_C(0x200000), MDBX_NORDAHEAD = UINT32_C(0x800000), MDBX_NOMEMINIT = UINT32_C(0x1000000), MDBX_COALESCE = UINT32_C(0x2000000), MDBX_LIFORECLAIM = UINT32_C(0x4000000), MDBX_PAGEPERTURB = UINT32_C(0x8000000), MDBX_SYNC_DURABLE = 0, MDBX_NOMETASYNC = UINT32_C(0x40000), MDBX_SAFE_NOSYNC = UINT32_C(0x10000), MDBX_MAPASYNC = MDBX_SAFE_NOSYNC, MDBX_UTTERLY_NOSYNC = MDBX_SAFE_NOSYNC | UINT32_C(0x100000) } |
Environment flags. More... | |
Functions | |
LIBMDBX_API int | mdbx_env_create (MDBX_env **penv) |
Create an MDBX environment instance. More... | |
LIBMDBX_API int | mdbx_env_open (MDBX_env *env, const char *pathname, MDBX_env_flags_t flags, mdbx_mode_t mode) |
Open an environment instance. More... | |
LIBMDBX_API int | mdbx_env_close_ex (MDBX_env *env, bool dont_sync) |
Close the environment and release the memory map. More... | |
int | mdbx_env_close (MDBX_env *env) |
The shortcut to calling mdbx_env_close_ex() with the dont_sync=false argument. More... | |
typedef enum MDBX_env_flags_t MDBX_env_flags_t |
enum MDBX_env_flags_t |
Environment flags.
Enumerator | |
---|---|
MDBX_ENV_DEFAULTS | |
MDBX_NOSUBDIR | No environment directory. By default, MDBX creates its environment in a directory whose pathname is given in path, and creates its data and lock files under that directory. With this option, path is used as-is for the database main data file. The database lock file is the path with "-lck" appended.
This flag affects only at new environment creating by mdbx_env_open(), otherwise at opening an existing environment libmdbx will choice this automatically. |
MDBX_RDONLY | 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. |
MDBX_EXCLUSIVE | Open environment in exclusive/monopolistic mode.
This flag affects only at environment opening but can't be changed after. |
MDBX_ACCEDE | Using database/environment which already opened by another process(es). The
|
MDBX_WRITEMAP | 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. |
MDBX_NOTLS | Tie reader locktable slots to read-only transactions instead of to threads. Don't use Thread-Local Storage, instead tie reader locktable slots to MDBX_txn objects instead of to threads. So, mdbx_txn_reset() keeps the slot reserved for the MDBX_txn object. A thread may use parallel read-only transactions. And a read-only transaction may span threads if you synchronizes its use. Applications that multiplex many user threads over individual OS threads need this option. Such an application must also serialize the write transactions in an OS thread, since MDBX's write locking is unaware of the user threads.
This flag affects only at environment opening but can't be changed after. |
MDBX_NORDAHEAD | Don't do readahead. Turn off readahead. Most operating systems perform readahead on read requests by default. This option turns it off if the OS supports it. Turning it off may help random read performance when the DB is larger than RAM and system RAM is full. By default libmdbx dynamically enables/disables readahead depending on the actual database size and currently available memory. On the other hand, such automation has some limitation, i.e. could be performed only when DB size changing but can't tracks and reacts changing a free RAM availability, since it changes independently and asynchronously.
This flag affects only at environment opening and can't be changed after. |
MDBX_NOMEMINIT | Don't initialize malloc'ed memory before writing to datafile. Don't initialize malloc'ed memory before writing to unused spaces in the data file. By default, memory for pages written to the data file is obtained using malloc. While these pages may be reused in subsequent transactions, freshly malloc'ed pages will be initialized to zeroes before use. This avoids persisting leftover data from other code (that used the heap and subsequently freed the memory) into the data file. Note that many other system libraries may allocate and free memory from the heap for arbitrary uses. E.g., stdio may use the heap for file I/O buffers. This initialization step has a modest performance cost so some applications may want to disable it using this flag. This option can be a problem for applications which handle sensitive data like passwords, and it makes memory checkers like Valgrind noisy. This flag is not needed with MDBX_WRITEMAP, which writes directly to the mmap instead of using malloc for pages. The initialization is also skipped if MDBX_RESERVE is used; the caller is expected to overwrite all of the memory that was reserved in that case. This flag may be changed at any time using |
MDBX_COALESCE | Aims to coalesce a Garbage Collection items. With This flag may be changed at any time using mdbx_env_set_flags(). |
MDBX_LIFORECLAIM | LIFO policy for recycling a Garbage Collection items.
LIFO recycling policy means that for reuse pages will be taken which became unused the lastest (i.e. just now or most recently). Therefore the loop of database pages circulation becomes as short as possible. In other words, the number of pages, that are overwritten in memory and on disk during a series of write transactions, will be as small as possible. Thus creates ideal conditions for the efficient operation of the disk write-back cache. MDBX_LIFORECLAIM is compatible with all no-sync flags, but gives NO noticeable impact in combination with MDBX_SAFE_NOSYNC or MDBX_UTTERLY_NOSYNC. Because MDBX will reused pages only before the last "steady" MVCC-snapshot, i.e. the loop length of database pages circulation will be mostly defined by frequency of calling mdbx_env_sync() rather than LIFO and FIFO difference. This flag may be changed at any time using mdbx_env_set_flags(). |
MDBX_PAGEPERTURB | Debugging option, fill/perturb released pages. |
MDBX_SYNC_DURABLE | 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.
|
MDBX_NOMETASYNC | 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.
|
MDBX_SAFE_NOSYNC | 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.
|
MDBX_MAPASYNC |
Since version 0.9.x the |
MDBX_UTTERLY_NOSYNC | 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,
|
|
inline |
The shortcut to calling mdbx_env_close_ex() with the dont_sync=false
argument.
LIBMDBX_API int mdbx_env_close_ex | ( | MDBX_env * | env, |
bool | dont_sync | ||
) |
Close the environment and release the memory map.
Only a single thread may call this function. All transactions, databases, and cursors must already be closed before calling this function. Attempts to use any such handles after calling this function will cause a SIGSEGV
. The environment handle will be freed and must not be used again after this call.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | dont_sync | A dont'sync flag, if non-zero the last checkpoint will be kept "as is" and may be still "weak" in the MDBX_SAFE_NOSYNC or MDBX_UTTERLY_NOSYNC modes. Such "weak" checkpoint will be ignored on opening next time, and transactions since the last non-weak checkpoint (meta-page update) will rolledback for consistency guarantee. |
MDBX_BUSY | The write transaction is running by other thread, in such case MDBX_env instance has NOT be destroyed not released! |
MDBX_EBADSIGN | Environment handle already closed or not valid, i.e. mdbx_env_close() was already called for the env or was not created by mdbx_env_create(). |
MDBX_PANIC | If mdbx_env_close_ex() was called in the child process after fork() . In this case MDBX_PANIC is expected, i.e. MDBX_env instance was freed in proper manner. |
MDBX_EIO | An error occurred during synchronization. |
LIBMDBX_API int mdbx_env_create | ( | MDBX_env ** | penv | ) |
Create an MDBX environment instance.
This function allocates memory for a MDBX_env structure. To release the allocated memory and discard the handle, call mdbx_env_close(). Before the handle may be used, it must be opened using mdbx_env_open().
Various other options may also need to be set before opening the handle, e.g. mdbx_env_set_geometry(), mdbx_env_set_maxreaders(), mdbx_env_set_maxdbs(), depending on usage requirements.
[out] | penv | The address where the new handle will be stored. |
LIBMDBX_API int mdbx_env_open | ( | MDBX_env * | env, |
const char * | pathname, | ||
MDBX_env_flags_t | flags, | ||
mdbx_mode_t | mode | ||
) |
Open an environment instance.
Indifferently this function will fails or not, the mdbx_env_close() must be called later to discard the MDBX_env handle and release associated resources.
[in] | env | An environment handle returned by mdbx_env_create() |
[in] | pathname | The pathname for the database or the directory in which the database files reside. In the case of directory it must already exist and be writable. |
[in] | flags | Specifies options for this environment. This parameter must be bitwise OR'ing together any constants described above in the env_flags and SYNC MODES sections. |
Flags set by mdbx_env_set_flags() are also used:
MDB_NOLOCK
flag don't supported by MDBX, try use MDBX_EXCLUSIVE as a replacement.If the database is already exist and parameters specified early by mdbx_env_set_geometry() are incompatible (i.e. for instance, different page size) then mdbx_env_open() will return MDBX_INCOMPATIBLE error.
[in] | mode | The UNIX permissions to set on created files. Zero value means to open existing, but do not create. |
MDBX_VERSION_MISMATCH | The version of the MDBX library doesn't match the version that created the database environment. |
MDBX_INVALID | The environment file headers are corrupted. |
MDBX_ENOENT | The directory specified by the path parameter doesn't exist. |
MDBX_EACCES | The user didn't have permission to access the environment files. |
MDBX_EAGAIN | The environment was locked by another process. |
MDBX_BUSY | The MDBX_EXCLUSIVE flag was specified and the environment is in use by another process, or the current process tries to open environment more than once. |
MDBX_INCOMPATIBLE | Environment is already opened by another process, but with different set of MDBX_SAFE_NOSYNC, MDBX_UTTERLY_NOSYNC flags. Or if the database is already exist and parameters specified early by mdbx_env_set_geometry() are incompatible (i.e. different pagesize, etc). |
MDBX_WANNA_RECOVERY | The MDBX_RDONLY flag was specified but read-write access is required to rollback inconsistent state after a system crash. |
MDBX_TOO_LARGE | Database is too large for this process, i.e. 32-bit process tries to open >4Gb database. |