Typedefs | |
typedef enum MDBX_option_t | MDBX_option_t |
Functions | |
LIBMDBX_API int | mdbx_env_set_option (MDBX_env *env, const MDBX_option_t option, uint64_t value) |
Sets the value of a runtime options for an environment. More... | |
LIBMDBX_API int | mdbx_env_get_option (const MDBX_env *env, const MDBX_option_t option, uint64_t *pvalue) |
Gets the value of runtime options from an environment. More... | |
int | mdbx_env_set_syncbytes (MDBX_env *env, size_t threshold) |
Sets threshold to force flush the data buffers to disk, even any of MDBX_SAFE_NOSYNC flag in the environment. More... | |
int | mdbx_env_set_syncperiod (MDBX_env *env, unsigned seconds_16dot16) |
Sets relative period since the last unsteady commit to force flush the data buffers to disk, even of MDBX_SAFE_NOSYNC flag in the environment. More... | |
LIBMDBX_API int | mdbx_env_set_flags (MDBX_env *env, MDBX_env_flags_t flags, bool onoff) |
Set environment flags. More... | |
LIBMDBX_API int | mdbx_env_set_geometry (MDBX_env *env, intptr_t size_lower, intptr_t size_now, intptr_t size_upper, intptr_t growth_step, intptr_t shrink_threshold, intptr_t pagesize) |
Set all size-related parameters of environment, including page size and the min/max size of the memory map. More... | |
MDBX_DEPRECATED int | mdbx_env_set_mapsize (MDBX_env *env, size_t size) |
int | mdbx_env_set_maxreaders (MDBX_env *env, unsigned readers) |
Set the maximum number of threads/reader slots for for all processes interacts with the database. More... | |
int | mdbx_env_set_maxdbs (MDBX_env *env, MDBX_dbi dbs) |
Set the maximum number of named databases for the environment. More... | |
LIBMDBX_API int | mdbx_env_set_userctx (MDBX_env *env, void *ctx) |
Sets application information (a context pointer) associated with the environment. More... | |
typedef enum MDBX_option_t MDBX_option_t |
LIBMDBX_API int mdbx_env_get_option | ( | const MDBX_env * | env, |
const MDBX_option_t | option, | ||
uint64_t * | pvalue | ||
) |
Gets the value of runtime options from an environment.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | option | The option from MDBX_option_t to get value of it. |
[out] | pvalue | The address where the option's value will be stored. |
LIBMDBX_API int mdbx_env_set_flags | ( | MDBX_env * | env, |
MDBX_env_flags_t | flags, | ||
bool | onoff | ||
) |
Set environment flags.
This may be used to set some flags in addition to those from mdbx_env_open(), or to unset these flags.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | flags | The env_flags to change, bitwise OR'ed together. |
[in] | onoff | A non-zero value sets the flags, zero clears them. |
MDBX_EINVAL | An invalid parameter was specified. |
LIBMDBX_API int mdbx_env_set_geometry | ( | MDBX_env * | env, |
intptr_t | size_lower, | ||
intptr_t | size_now, | ||
intptr_t | size_upper, | ||
intptr_t | growth_step, | ||
intptr_t | shrink_threshold, | ||
intptr_t | pagesize | ||
) |
Set all size-related parameters of environment, including page size and the min/max size of the memory map.
In contrast to LMDB, the MDBX provide automatic size management of an database according the given parameters, including shrinking and resizing on the fly. From user point of view all of these just working. Nevertheless, it is reasonable to know some details in order to make optimal decisions when choosing parameters.
Both mdbx_env_set_geometry() and legacy mdbx_env_set_mapsize() are inapplicable to read-only opened environment.
Both mdbx_env_set_geometry() and legacy mdbx_env_set_mapsize() could be called either before or after mdbx_env_open(), either within the write transaction running by current thread or not:
In case mdbx_env_set_geometry() or legacy mdbx_env_set_mapsize() was called BEFORE mdbx_env_open(), i.e. for closed environment, then the specified parameters will be used for new database creation, or will be applied during opening if database exists and no other process using it.
If the database is already exist, opened with MDBX_EXCLUSIVE or not used by any other process, and parameters specified by mdbx_env_set_geometry() are incompatible (i.e. for instance, different page size) then mdbx_env_open() will return MDBX_INCOMPATIBLE error.
In another way, if database will opened read-only or will used by other process during calling mdbx_env_open() that specified parameters will silently discarded (open the database with MDBX_EXCLUSIVE flag to avoid this).
Essentially a concept of "automatic size management" is simple and useful:
So, there some considerations about choosing these parameters:
size_now
argument) is an auxiliary parameter for simulation legacy mdbx_env_set_mapsize() and as workaround Windows issues (see below).Unfortunately, Windows has is a several issue with resizing of memory-mapped file:
MDBX bypasses all Windows issues, but at a cost:
SlimReadWriteLock
during each read-only transaction.For create a new database with particular parameters, including the page size, mdbx_env_set_geometry() should be called after mdbx_env_create() and before mdbx_env_open(). Once the database is created, the page size cannot be changed. If you do not specify all or some of the parameters, the corresponding default values will be used. For instance, the default for database size is 10485760 bytes.
If the mapsize is increased by another process, MDBX silently and transparently adopt these changes at next transaction start. However, mdbx_txn_begin() will return MDBX_UNABLE_EXTEND_MAPSIZE if new mapping size could not be applied for current process (for instance if address space is busy). Therefore, in the case of MDBX_UNABLE_EXTEND_MAPSIZE error you need close and reopen the environment to resolve error.
mdbx_chk
with the -v
option.Legacy mdbx_env_set_mapsize() correspond to calling mdbx_env_set_geometry() with the arguments size_lower
, size_now
, size_upper
equal to the size
and -1
(i.e. default) for all other parameters.
[in] | env | An environment handle returned by mdbx_env_create() |
[in] | size_lower | The lower bound of database size in bytes. Zero value means "minimal acceptable", and negative means "keep current or use default". |
[in] | size_now | The size in bytes to setup the database size for now. Zero value means "minimal acceptable", and negative means "keep current or use default". So, it is recommended always pass -1 in this argument except some special cases. |
[in] | size_upper | The upper bound of database size in bytes. Zero value means "minimal acceptable", and negative means "keep current or use default". It is recommended to avoid change upper bound while database is used by other processes or threaded (i.e. just pass -1 in this argument except absolutely necessary). Otherwise you must be ready for MDBX_UNABLE_EXTEND_MAPSIZE error(s), unexpected pauses during remapping and/or system errors like "address busy", and so on. In other words, there is no way to handle a growth of the upper bound robustly because there may be a lack of appropriate system resources (which are extremely volatile in a multi-process multi-threaded environment). |
[in] | growth_step | The growth step in bytes, must be greater than zero to allow the database to grow. Negative value means "keep current or use default". |
[in] | shrink_threshold | The shrink threshold in bytes, must be greater than zero to allow the database to shrink and greater than growth_step to avoid shrinking right after grow. Negative value means "keep current or use default". Default is 2*growth_step. |
[in] | pagesize | The database page size for new database creation or -1 otherwise. Once the database is created, the page size cannot be changed. Must be power of 2 in the range between MDBX_MIN_PAGESIZE and MDBX_MAX_PAGESIZE. Zero value means "minimal acceptable", and negative means "keep current or use default". |
MDBX_EINVAL | An invalid parameter was specified, or the environment has an active write transaction. |
MDBX_EPERM | Two specific cases for Windows: 1) Shrinking was disabled before via geometry settings and now it enabled, but there are reading threads that don't use the additional SRWL (which is required to avoid Windows issues). 2) Temporary close memory mapped is required to change geometry, but there read transaction(s) is running and no corresponding thread(s) could be suspended since the MDBX_NOTLS mode is used. |
MDBX_EACCESS | The environment opened in read-only. |
MDBX_MAP_FULL | Specified size smaller than the space already consumed by the environment. |
MDBX_TOO_LARGE | Specified size is too large, i.e. too many pages for given size, or a 32-bit process requests too much bytes for the 32-bit address space. |
|
inline |
Set the maximum number of named databases for the environment.
This function is only needed if multiple databases will be used in the environment. Simpler applications that use the environment as a single unnamed database can ignore this option. This function may only be called after mdbx_env_create() and before mdbx_env_open().
Currently a moderate number of slots are cheap but a huge number gets expensive: 7-120 words per transaction, and every mdbx_dbi_open() does a linear search of the opened slots.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | dbs | The maximum number of databases. |
MDBX_EINVAL | An invalid parameter was specified. |
MDBX_EPERM | The environment is already open. |
|
inline |
Set the maximum number of threads/reader slots for for all processes interacts with the database.
This defines the number of slots in the lock table that is used to track readers in the the environment. The default is about 100 for 4K system page size. Starting a read-only transaction normally ties a lock table slot to the current thread until the environment closes or the thread exits. If MDBX_NOTLS is in use, mdbx_txn_begin() instead ties the slot to the MDBX_txn object until it or the MDBX_env object is destroyed. This function may only be called after mdbx_env_create() and before mdbx_env_open(), and has an effect only when the database is opened by the first process interacts with the database.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | readers | The maximum number of reader lock table slots. |
MDBX_EINVAL | An invalid parameter was specified. |
MDBX_EPERM | The environment is already open. |
LIBMDBX_API int mdbx_env_set_option | ( | MDBX_env * | env, |
const MDBX_option_t | option, | ||
uint64_t | value | ||
) |
Sets the value of a runtime options for an environment.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | option | The option from MDBX_option_t to set value of it. |
[in] | value | The value of option to be set. |
|
inline |
Sets threshold to force flush the data buffers to disk, even any of MDBX_SAFE_NOSYNC flag in the environment.
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 mdbx_txn_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 MDBX_SAFE_NOSYNC, MDBX_UTTERLY_NOSYNC or in part MDBX_NOMETASYNC.
The default is 0, than mean no any threshold checked, and no additional flush will be made.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | threshold | The size in bytes of summary changes when a synchronous flush would be made. |
|
inline |
Sets relative period since the last unsteady commit to force flush the data buffers to disk, even of MDBX_SAFE_NOSYNC flag in the environment.
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 mdbx_txn_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 MDBX_SAFE_NOSYNC or in part MDBX_NOMETASYNC.
Settled period don't checked asynchronously, but only by the mdbx_txn_commit() and mdbx_env_sync() functions. Therefore, in cases where transactions are committed infrequently and/or irregularly, polling by mdbx_env_sync() 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] | env | An environment handle returned by mdbx_env_create(). |
[in] | seconds_16dot16 | The period in 1/65536 of second when a synchronous flush would be made since the last unsteady commit. |
LIBMDBX_API int mdbx_env_set_userctx | ( | MDBX_env * | env, |
void * | ctx | ||
) |
Sets application information (a context pointer) associated with the environment.
[in] | env | An environment handle returned by mdbx_env_create(). |
[in] | ctx | An arbitrary pointer for whatever the application needs. |