Operate options. More...
#include <mdbx.h++>
Public Member Functions | |
| constexpr | operate_options () noexcept |
| constexpr | operate_options (const operate_options &) noexcept=default |
| constexpr operate_options & | operator= (const operate_options &) noexcept=default |
| operate_options (MDBX_env_flags_t) noexcept | |
Public Attributes | |
| bool | no_sticky_threads {false} |
| bool | nested_transactions {false} |
| Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов. | |
| bool | exclusive {false} |
| bool | disable_readahead {false} |
| bool | disable_clear_memory {false} |
| bool | enable_validation {false} |
Operate options.
|
inlineconstexprnoexcept |
|
constexprdefaultnoexcept |
|
noexcept |
|
constexprdefaultnoexcept |
| bool mdbx::env::operate_options::disable_clear_memory {false} |
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_env_set_flags().
| bool mdbx::env::operate_options::disable_readahead {false} |
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.
| bool mdbx::env::operate_options::enable_validation {false} |
Extra validation of DB structure and pages content.
The MDBX_VALIDATION enabled the simple safe/careful mode for working with damaged or untrusted DB. However, a notable performance degradation should be expected.
| bool mdbx::env::operate_options::exclusive {false} |
Open environment in exclusive/monopolistic mode.
MDBX_EXCLUSIVE flag can be used as a replacement for MDB_NOLOCK, which don't supported by MDBX. In this way, you can get the minimal overhead, but with the correct multi-process and multi-thread locking.
This flag affects only at environment opening but can't be changed after.
| bool mdbx::env::operate_options::nested_transactions {false} |
Разрешает вложенные транзакции ценой отключения MDBX_WRITEMAP и увеличением накладных расходов.
| bool mdbx::env::operate_options::no_sticky_threads {false} |
Unlinks transactions from threads as much as possible.
This option is intended for applications that multiplex multiple user-defined lightweight execution threads across separate operating system threads, such as in the GoLang and Rust runtimes. It is also recommended for such applications to serialize write transactions in a single operating system thread, since MDBX write locking uses basic synchronization system primitives and knows nothing about user threads and/or lightweight runtime threads. Anyway, at a minimum, it is absolutely necessary to ensure that each writing transaction is finished strictly in the same thread of the operating system where it was started.
When using MDBX_NOSTICKYTHREADS, transactions become unrelated to system threads that created ones. Therefore, the API functions do not check the correspondence between the transaction and the current execution thread. Most functions that work with transactions and cursors can be called from any execution thread. However, it also becomes impossible to detect mistakes when transactions and/or cursors are used simultaneously in different threads.
Using MDBX_NOSTICKYTHREADS also narrows down the possibilities for resizing the database, as it loses the ability to track execution threads working with the database and suspend ones while the database is unmapped in RAM. Thus unmapping and remapping of a database file becomes impossible while at least one transaction in still present. In particular, for this reason, on Windows, reducing the database file is not possible until the database is closed by the last process working with it or until the database is subsequently opened in read-write mode.
When using MDBX_NOSTICKYTHREADS, reading transactions do not use TLS (Thread Local Storage), and the MVCC-snapshot lock slots in a readers table are becomes linked only to transactions. The completion of any threads does not lead to the release of MVCC snapshot locks until the transactions are explicitly completed, or until the corresponding process as a whole is completed. For writing transactions, there is no checking of the correspondence between the current execution thread and the thread that created the transaction. However, the commit or interruption of writing transactions must be performed strictly in the thread that started the transaction, since these operations are associated with the acquire and release of synchronization primitives (mutexes, semaphores, critical sections), for which most operating systems require the release only by the thread that acquired the resource.
This flag takes effect when the environment is opened and cannot be changed after.