Topics | |
| Checking and Recovery | |
Classes | |
| struct | MDBX_chk_line_t |
| A virtual row of the report generated during a database integrity check. More... | |
| struct | MDBX_chk_issue_t |
| An issue problem was discovered during a database integrity check. More... | |
| struct | MDBX_chk_scope_t |
| A hierarchical context during a database integrity check. More... | |
| struct | MDBX_chk_histogram |
| A histogram with some statistical information collected during a database integrity check. More... | |
| struct | MDBX_chk_table_t |
| Information about a certain key-value table during a database integrity check. More... | |
| struct | MDBX_chk_context_t |
| The context for checking the integrity of a database. More... | |
| struct | MDBX_chk_callbacks_t |
| A set of callback functions used for checking the integrity of a database. More... | |
| struct | MDBX_defrag_result_t |
| The numerical metrics of progress and result of database defragmentation. More... | |
| union | MDBX_chk_scope_t.usr_z |
| union | MDBX_chk_scope_t.usr_v |
| union | MDBX_chk_scope_t.usr_o |
| struct | MDBX_chk_histogram.ranges |
| struct | MDBX_chk_table_t.pages |
| struct | MDBX_chk_table_t.histogram |
| struct | MDBX_chk_context_t.result |
Typedefs | |
| typedef struct MDBX_chk_user_table_cookie | MDBX_chk_user_table_cookie_t |
| A custom type for binding additional data associated with a certain key-value table during a database integrity check. | |
| typedef int(* | MDBX_defrag_notify_func) (void *ctx, const MDBX_defrag_result_t *progress) noexcept |
| A callback function to notify an application about the progress of defragmentation. | |
Functions | |
| LIBMDBX_API int | mdbx_env_delete (const char *pathname, MDBX_env_delete_mode_t mode) |
| Delete the environment's files in a proper and multiprocess-safe way. | |
| LIBMDBX_API int | mdbx_env_deleteW (const wchar_t *pathname, MDBX_env_delete_mode_t mode) |
| Delete the environment's files in a proper and multiprocess-safe way. | |
| LIBMDBX_API int | mdbx_env_copy (MDBX_env *env, const char *dest, MDBX_copy_flags_t flags) |
| Copy an MDBX environment to the specified path, with options. | |
| LIBMDBX_API int | mdbx_txn_copy2pathname (MDBX_txn *txn, const char *dest, MDBX_copy_flags_t flags) |
| Copy an MDBX environment by given read transaction to the specified path, with options. | |
| LIBMDBX_API int | mdbx_env_copyW (MDBX_env *env, const wchar_t *dest, MDBX_copy_flags_t flags) |
| Copy an MDBX environment to the specified path, with options. | |
| LIBMDBX_API int | mdbx_txn_copy2pathnameW (MDBX_txn *txn, const wchar_t *dest, MDBX_copy_flags_t flags) |
| Copy an MDBX environment by given read transaction to the specified path, with options. | |
| LIBMDBX_API int | mdbx_env_copy2fd (MDBX_env *env, mdbx_filehandle_t fd, MDBX_copy_flags_t flags) |
| Copy an environment to the specified file descriptor, with options. | |
| LIBMDBX_API int | mdbx_txn_copy2fd (MDBX_txn *txn, mdbx_filehandle_t fd, MDBX_copy_flags_t flags) |
| Copy an environment by given read transaction to the specified file descriptor, with options. | |
| LIBMDBX_API int | mdbx_env_sync_ex (MDBX_env *env, bool force, bool nonblock) |
| Flush the environment data buffers to disk. | |
| int | mdbx_env_sync (MDBX_env *env) |
| The shortcut to calling mdbx_env_sync_ex() with the force=true and nonblock=false arguments. | |
| int | mdbx_env_sync_poll (MDBX_env *env) |
| The shortcut to calling mdbx_env_sync_ex() with the force=false and nonblock=true arguments. | |
| LIBMDBX_API int | mdbx_env_resurrect_after_fork (MDBX_env *env) |
| Restores an instance of the environment in a child process after forking the parent process using fork() or similar system calls. | |
| LIBMDBX_API int | mdbx_is_readahead_reasonable (size_t volume, intptr_t redundancy) |
| Find out whether to use readahead or not, based on the given database size and the amount of available memory. | |
| LIBMDBX_API int | mdbx_cursor_ignord (MDBX_cursor *cursor) |
| An auxiliary function for use in tools. | |
| LIBMDBX_API MDBX_cmp_func | mdbx_get_keycmp (MDBX_db_flags_t flags) |
| Returns default internal key's comparator for given table flags. | |
| LIBMDBX_API MDBX_cmp_func | mdbx_get_datacmp (MDBX_db_flags_t flags) |
| Returns default internal data's comparator for given table flags. | |
| LIBMDBX_API int | mdbx_reader_check (MDBX_env *env, int *dead) |
| Check for stale entries in the reader lock table. | |
| LIBMDBX_API int | mdbx_thread_register (const MDBX_env *env) |
| Registers the current thread as a reader for the environment. | |
| LIBMDBX_API int | mdbx_thread_unregister (const MDBX_env *env) |
| Unregisters the current thread as a reader for the environment. | |
| LIBMDBX_API int | mdbx_txn_lock (MDBX_env *env, bool dont_wait) |
| Acquires write-transaction lock. Provided for custom and/or complex locking scenarios. | |
| LIBMDBX_API int | mdbx_txn_unlock (MDBX_env *env) |
| Releases write-transaction lock. Provided for custom and/or complex locking scenarios. | |
| LIBMDBX_API int | mdbx_env_open_for_recovery (MDBX_env *env, const char *pathname, unsigned target_meta, bool writeable) |
| Open an environment instance using specific meta-page for checking and recovery. | |
| LIBMDBX_API int | mdbx_env_open_for_recoveryW (MDBX_env *env, const wchar_t *pathname, unsigned target_meta, bool writeable) |
| Open an environment instance using specific meta-page for checking and recovery. | |
| LIBMDBX_API int | mdbx_env_chk (MDBX_env *env, const MDBX_chk_callbacks_t *cb, MDBX_chk_context_t *ctx, const MDBX_chk_flags_t flags, MDBX_chk_severity_t verbosity, unsigned timeout_seconds_16dot16) |
| Checks the integrity of a database. | |
| LIBMDBX_API int | mdbx_env_chk_encount_problem (MDBX_chk_context_t *ctx) |
| An auxiliary function to account issues detected by an application, including those coming to an application through logging. | |
| LIBMDBX_API const char * | mdbx_ratio2digits (uint64_t numerator, uint64_t denominator, int precision, char *buffer, size_t buffer_size) |
| An auxiliary function for converting fractions to string of decimal digits without using floating-point operations. | |
| LIBMDBX_API const char * | mdbx_ratio2percents (uint64_t value, uint64_t whole, char *buffer, size_t buffer_size) |
| An auxiliary function for converting fractions to percentage string without using floating-point operations. | |
| LIBMDBX_API int | mdbx_env_defrag (MDBX_env *env, size_t defrag_atleast, size_t time_atleast_16dot16, size_t defrag_enough, size_t time_limit_16dot16, intptr_t acceptable_backlash, intptr_t preferred_batch, MDBX_defrag_notify_func progress_callback, void *ctx, MDBX_defrag_result_t *result) |
| Performs database defragmentation. | |
| struct MDBX_chk_line_t |
A virtual row of the report generated during a database integrity check.
| Class Members | ||
|---|---|---|
| char * | begin | |
| struct MDBX_chk_context * | ctx | |
| uint8_t | empty | |
| char * | end | |
| char * | out | |
| uint8_t | scope_depth | |
| uint8_t | severity | |
| struct MDBX_chk_issue_t |
An issue problem was discovered during a database integrity check.
| Class Members | ||
|---|---|---|
| const char * | caption | |
| size_t | count | |
| struct MDBX_chk_issue * | next | |
| struct MDBX_chk_scope_t |
A hierarchical context during a database integrity check.
| Class Members | ||
|---|---|---|
| struct MDBX_chk_internal * | internal | |
| MDBX_chk_issue_t * | issues | |
| const void * | object | |
| MDBX_chk_stage_t | stage | |
| size_t | subtotal_issues | |
| union MDBX_chk_scope_t.usr_o | usr_o | |
| union MDBX_chk_scope_t.usr_v | usr_v | |
| union MDBX_chk_scope_t.usr_z | usr_z | |
| MDBX_chk_severity_t | verbosity | |
| struct MDBX_chk_histogram |
A histogram with some statistical information collected during a database integrity check.
| Class Members | ||
|---|---|---|
| size_t | amount | |
| size_t | count | |
| size_t | le1_amount | |
| size_t | le1_count | |
| struct MDBX_chk_histogram.ranges | ranges[9] | |
| struct MDBX_chk_table_t |
Information about a certain key-value table during a database integrity check.
| Class Members | ||
|---|---|---|
| MDBX_chk_user_table_cookie_t * | cookie | |
| MDBX_db_flags_t | flags | |
| struct MDBX_chk_table_t.histogram | histogram | |
| int | id | |
| size_t | lost_bytes | |
| MDBX_val | name | |
| struct MDBX_chk_table_t.pages | pages | |
| size_t | payload_bytes | |
| struct MDBX_chk_context_t |
The context for checking the integrity of a database.
| Class Members | ||
|---|---|---|
| MDBX_env * | env | |
| struct MDBX_chk_internal * | internal | |
| struct MDBX_chk_context_t.result | result | |
| MDBX_chk_scope_t * | scope | |
| uint8_t | scope_nesting | |
| MDBX_txn * | txn | |
| struct MDBX_chk_callbacks_t |
A set of callback functions used for checking the integrity of a database.
The callback functions are designed to organize interaction with the application code. This includes the integration of application logic that verifies the integrity of a data structure above the key-value level, the preparation and structured output of information about both the progress and the results of verification.
All callback functions are optional, unused ones must be set to ‘nullptr’.
| Class Members | ||
|---|---|---|
| bool(*)(MDBX_chk_context_t *ctx) | check_break | |
| void(*)(MDBX_chk_context_t *ctx, const char *object, uint64_t entry_number, const char *issue, const char *extra_fmt, va_list extra_args) | issue | |
| MDBX_chk_line_t *(*)(MDBX_chk_context_t *ctx, MDBX_chk_severity_t severity) | print_begin | |
| void(*)(MDBX_chk_line_t *, const char *str, size_t len) | print_chars | |
| void(*)(MDBX_chk_line_t *) | print_done | |
| void(*)(MDBX_chk_line_t *) | print_flush | |
| void(*)(MDBX_chk_line_t *, const char *fmt, va_list args) | print_format | |
| void(*)(MDBX_chk_line_t *, const char *prefix, const uint64_t value, const char *suffix) | print_size | |
| int(*)(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *outer, MDBX_chk_scope_t *inner, int err) | scope_conclude | |
| void(*)(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *outer, MDBX_chk_scope_t *inner) | scope_pop | |
| int(*)(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *outer, MDBX_chk_scope_t *inner, const char *fmt, va_list args) | scope_push | |
| int(*)(MDBX_chk_context_t *ctx, MDBX_chk_stage_t) | stage_begin | |
| int(*)(MDBX_chk_context_t *ctx, MDBX_chk_stage_t, int err) | stage_end | |
| int(*)(MDBX_chk_context_t *ctx, const MDBX_chk_table_t *table, MDBX_cursor *cursor, int err) | table_conclude | |
| void(*)(MDBX_chk_context_t *ctx, const MDBX_chk_table_t *table) | table_dispose | |
| MDBX_chk_user_table_cookie_t *(*)(MDBX_chk_context_t *ctx, const MDBX_val *name, MDBX_db_flags_t flags) | table_filter | |
| int(*)(MDBX_chk_context_t *ctx, const MDBX_chk_table_t *table, size_t entry_number, const MDBX_val *key, const MDBX_val *value) | table_handle_kv | |
| struct MDBX_defrag_result_t |
The numerical metrics of progress and result of database defragmentation.
| Class Members | ||
|---|---|---|
| unsigned | cycles |
The number of defragmentation cycles. |
| size_t | obstructed_pgno |
The number of the page where the defragmentation stumbled, according to the reasons given in the stopping_reasons field. |
| size_t | obstructed_span |
The length of the large/overflow-page span where the defragmentation stumbled, according to the reasons given in the stopping_reasons field. |
| uint64_t | obstructed_txnid |
The transaction number corresponds to the earliest/first MVCC-snapshot held by reader(s) and preventing defragmentation. |
| mdbx_pid_t | obstructor_pid |
The system/native Process ID of one of a readers holding the MVCC snapshot that prevents defragmentation. |
| mdbx_tid_t | obstructor_tid |
The system/native Thread ID of one of a readers holding the MVCC snapshot that prevents defragmentation. |
| size_t | pages_left |
The estimated remaining number of pages that are potentially defragmented. |
| size_t | pages_moved |
The total number of pages moved during defragmentation. |
| size_t | pages_retained |
The number of pages held by other processes via reading MVCC-snapshots that prevent reclaiming and defragmentation. |
| size_t | pages_scheduled |
The number of pages scheduled to be moved at the next stage of the current defragmentation cycle. |
| intptr_t | pages_shrinked |
The number of pages that the database size was shrinked by. In the worst case, this value can be negative, for instance -1, when defragmentation was stopped for some reason, or the database structure does not allow it to be defragmented by moving individual pages. |
| size_t | pages_whole |
The whole number of pages in the database. |
| unsigned | rough_estimation_cycle_progress_permille |
Rough estimation a progress of the current defragmentation cycle in permilles (the 1000 means 100%). |
| unsigned | spent_time_16dot16 |
The time elapsed since the beginning of defragmentation in a 1/65536 second fractions. |
| unsigned | stopping_reasons |
Obstacles and reasons for stopping defragmentation in the form of a mask of OR'ed MDBX_defrag_stopping_reasons_t bits. |
| struct MDBX_chk_table_t.pages |
| struct MDBX_chk_table_t.histogram |
| Class Members | ||
|---|---|---|
| struct MDBX_chk_histogram | height |
Tree deep histogram |
| struct MDBX_chk_histogram | key_len |
Keys length histogram |
| struct MDBX_chk_histogram | large_or_nested_density |
Histogram of nested tree(s) branch and leaf pages filling in percents |
| struct MDBX_chk_histogram | large_pages |
Histogram of large/overflow pages length |
| struct MDBX_chk_histogram | multival |
Number of multi-values (aka duplicates) histogram |
| struct MDBX_chk_histogram | nested_height_or_gc_span_length |
Histogram of nested trees height, span length for GC |
| struct MDBX_chk_histogram | page_age |
Histogram of pages age |
| struct MDBX_chk_histogram | pgno |
Histogram of used pgno |
| struct MDBX_chk_histogram | tree_density |
Histogram of branch and leaf pages filling in percents |
| struct MDBX_chk_histogram | val_len |
Values length histogram |
| struct MDBX_chk_context_t.result |
| Class Members | ||
|---|---|---|
| size_t | alloc_pages | |
| size_t | backed_pages | |
| size_t | gc_pages | |
| size_t | gc_tree_problems | |
| struct MDBX_chk_histogram | histogram_page_age |
Histogram of pages age |
| struct MDBX_chk_histogram | histogram_pgno_payload |
Histogram of pgno retained by readers |
| struct MDBX_chk_histogram | histogram_pgno_retained |
Histogram of pgno used by all payload |
| size_t | kv_tree_problems | |
| size_t | problems_gc | |
| size_t | problems_kv | |
| size_t | problems_meta | |
| size_t | processed_pages | |
| uint64_t | recent_txnid | |
| size_t | reclaimable_pages | |
| uint64_t | steady_txnid | |
| size_t | table_processed | |
| size_t | table_total | |
| const MDBX_chk_table_t *const * | tables |
A pointer to the array of table_total pointers to instances of MDBX_chk_table_t structures with information about all key-value tables, including MainDB and GC. |
| size_t | total_payload_bytes | |
| size_t | total_problems | |
| size_t | total_unused_bytes | |
| size_t | tree_problems | |
| size_t | unused_pages | |
| typedef struct MDBX_chk_user_table_cookie MDBX_chk_user_table_cookie_t |
A custom type for binding additional data associated with a certain key-value table during a database integrity check.
|
noexcept |
A callback function to notify an application about the progress of defragmentation.
If provided such callback will be called time-to-time to notify about the progress of defragmentation. The rate of such notification calls is not explicitly defined, but it is guaranteed that it will be called at the beginning and end of each defragmentation cycle, as well as often will be enough to track progress in a percentages sharp.
| [in] | ctx | A pointer to the context passed by a similar parameter in mdbx_env_defrag(). |
| [in] | progress | A pointer to the MDBX_defrag_result_t structure filled in to reflects the current state of database defragmentation. |
| enum MDBX_chk_flags_t |
Flags/options for checking the integrity of a database.
| enum MDBX_chk_severity_t |
Levels of logging/detailing of information supplied via callbacks during a database integrity check.
| enum MDBX_chk_stage_t |
The verification stages reported via callbacks during a database integrity check.
| Enumerator | |
|---|---|
| MDBX_chk_none | |
| MDBX_chk_init | |
| MDBX_chk_lock | |
| MDBX_chk_meta | |
| MDBX_chk_tree | |
| MDBX_chk_gc | |
| MDBX_chk_space | |
| MDBX_chk_maindb | |
| MDBX_chk_tables | |
| MDBX_chk_conclude | |
| MDBX_chk_unlock | |
| MDBX_chk_finalize | |
| enum MDBX_copy_flags_t |
Environment copy flags.
| Enumerator | |
|---|---|
| MDBX_CP_DEFAULTS | |
| MDBX_CP_COMPACT | Copy with compactification: Omit free space from copy and renumber all pages sequentially |
| MDBX_CP_FORCE_DYNAMIC_SIZE | Force to make resizable copy, i.e. dynamic size instead of fixed |
| MDBX_CP_DONT_FLUSH | Don't explicitly flush the written data to an output media |
| MDBX_CP_THROTTLE_MVCC | Use read transaction parking during copying MVCC-snapshot
|
| MDBX_CP_DISPOSE_TXN | Abort/dispose passed transaction after copy |
| MDBX_CP_RENEW_TXN | Enable renew/restart read transaction in case it use outdated MVCC shapshot, otherwise the MDBX_MVCC_RETARDED will be returned |
| MDBX_CP_OVERWRITE | Silently overwrite the target file, if it exists, instead of returning an error |
The returned reasons for stopping database defragmentation.
Any number of individual values could be OR'ed together while while returning actual set of reasons.
| Enumerator | |
|---|---|
| MDBX_defrag_noobstacles | |
| MDBX_defrag_enough_theshold | |
| MDBX_defrag_time_limit | |
| MDBX_defrag_laggard_reader | |
| MDBX_defrag_large_chunk | |
| MDBX_defrag_user_break | |
| MDBX_defrag_error | |
Deletion modes for mdbx_env_delete().
| LIBMDBX_API int mdbx_cursor_ignord | ( | MDBX_cursor * | cursor | ) |
An auxiliary function for use in tools.
When using user-defined comparison functions, checking the order of keys or values will lead to incorrect results and return the error MDBX_CORRUPTED.
This function disables the control of the order of keys when reading database pages for this cursor, and thus allows to access data in the absence/unavailability of the comparison functions used.
| LIBMDBX_API int mdbx_env_chk | ( | MDBX_env * | env, |
| const MDBX_chk_callbacks_t * | cb, | ||
| MDBX_chk_context_t * | ctx, | ||
| const MDBX_chk_flags_t | flags, | ||
| MDBX_chk_severity_t | verbosity, | ||
| unsigned | timeout_seconds_16dot16 ) |
Checks the integrity of a database.
Interaction with the application code is implemented through callback functions provided by the application using the 'cb parameter. During such interaction, the application can monitor the verification process, including skipping/filtering the processing of individual elements, as well as implement additional verification of the structure and/or information, taking into account the purpose and semantic significance for an application. For example, an application can check its own indexes and the correctness of database entries. It is for this purpose that the integrity check functionality has been improved for intensive use of callbacks and moved from the mdbx_chk` utility to the main library.
Verification is performed in several stages, starting with initialization and ending with finalization. For more details, see MDBX_chk_stage_t. The application code is notified about the beginning and end of each stage through the corresponding callback functions. For more details, see MDBX_chk_callbacks_t.
| [in] | env | A pointer to an instance of environment. |
| [in] | cb | A set of callback functions. |
| [in,out] | ctx | The context of a database integrity check, where the results of the check will be generated. |
| [in] | flags | Flags/options for checking database integrity. |
| [in] | verbosity | The required level of detail of information about the progress and results of the checking. |
| [in] | timeout_seconds_16dot16 | The duration limit for performing the check in 1/65536 fractions of a second, either 0 means no limit. |
| LIBMDBX_API int mdbx_env_chk_encount_problem | ( | MDBX_chk_context_t * | ctx | ) |
An auxiliary function to account issues detected by an application, including those coming to an application through logging.
An application should call this function to account for detected issues, or vice versa, do not make these calls to ignore discovered issues.
| LIBMDBX_API int mdbx_env_copy | ( | MDBX_env * | env, |
| const char * | dest, | ||
| MDBX_copy_flags_t | flags ) |
Copy an MDBX environment to the specified path, with options.
This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
| [in] | env | An environment handle returned by mdbx_env_create(). It must have already been opened successfully. |
| [in] | dest | The pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable. |
| [in] | flags | Specifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here: |
| LIBMDBX_API int mdbx_env_copy2fd | ( | MDBX_env * | env, |
| mdbx_filehandle_t | fd, | ||
| MDBX_copy_flags_t | flags ) |
Copy an environment to the specified file descriptor, with options.
This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
| [in] | env | An environment handle returned by mdbx_env_create(). It must have already been opened successfully. |
| [in] | fd | The file descriptor to write the copy to. It must have already been opened for Write access. |
| [in] | flags | Special options for this operation. |
| LIBMDBX_API int mdbx_env_copyW | ( | MDBX_env * | env, |
| const wchar_t * | dest, | ||
| MDBX_copy_flags_t | flags ) |
Copy an MDBX environment to the specified path, with options.
This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
| [in] | env | An environment handle returned by mdbx_env_create(). It must have already been opened successfully. |
| [in] | dest | The pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable. |
| [in] | flags | Specifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here: |
| LIBMDBX_API int mdbx_env_defrag | ( | MDBX_env * | env, |
| size_t | defrag_atleast, | ||
| size_t | time_atleast_16dot16, | ||
| size_t | defrag_enough, | ||
| size_t | time_limit_16dot16, | ||
| intptr_t | acceptable_backlash, | ||
| intptr_t | preferred_batch, | ||
| MDBX_defrag_notify_func | progress_callback, | ||
| void * | ctx, | ||
| MDBX_defrag_result_t * | result ) |
Performs database defragmentation.
Defragmentation is the transfer of data from pages located at the end of the database to free pages closer to the beginning. After that, the pages that have become unused at the end of the database can be cut off while reducing the size of the database file. This function performs all the described actions in comply with ACID, trying to minimize the number of operations for moving data and writing to media.
The function accepts an extended set of parameters that allow you to fully control the goals and progress of defragmentation, including as to quickly get a minimum result by small steps and as to perform a fairly complete defragmentation in the least number of large cycles.
During the movement of data in the b-tree structure, it is necessary to adjust the links in the parent pages to the new moved child pages. According to the MVCC concept, this requires creating copies of altered parent pages along the entire chain from leaves to the root of the b-tree, inclusive. In addition, to move large/overflow pages, it may be necessary to form sequences of adjacent free pages, which will require moving other pages with data and correcting links to ones. Defragmentation almost always cannot be completely completed in one pass, as there are always fewer free pages than necessary to move due to the need to copy all the parent pages. In addition, if there are not enough sequences to move large/overflow pages, an additional commit step is required and a new transaction is started to continue.
Thus, defragmentation is almost always performed in several cycles, each of which ends with the transaction being committed and can be interrupted in any way while ensuring the durability of the database specified when it was opened.
| [in] | env | A pointer to an instance of environment. |
| [in] | defrag_atleast | The required at least number of pages by which the database must be reduced as a result of defragmentation. Defragmentation will not be completed and its goals will not be considered achieved until the database is shrinked by the specified amount. Must be less or equal to defrag_enough. Specify zero if in doubt or not known, this will mean no lower bound. |
| [in] | time_atleast_16dot16 | The time by a wall clock in 1/65536 unit of second that should be spent to defragment more, even if the goals given via other parameters have already been reached. Must be less or equal to time_limit_16dot16. Specify zero if in doubt or not known, this will mean no lower bound. |
| [in] | defrag_enough | The number of pages by which it will be enough to shrink the database during a defragmentation process to finish it rather than dig more. Must be greater or equal to defrag_atleast. Specify zero if in doubt or not known, this will mean no limit. |
| [in] | time_limit_16dot16 | The time limit by a wall clock in 1/65536 unit of second that could be spent to defragment. When the specified limit is reached, defragmentation will not continue, but the stage of writing the moved pages that has already begun will be completed. Must be greater or equal to time_atleast_16dot16. Specify zero if in doubt or not known, this will mean no limit. |
| [in] | acceptable_backlash | Defragmentation stops if a next cycle will unable to shrink database by the number of pages more than the specified value. This avoids the last few defragmentation cycles, which do not significantly reduce the size of the database. Specify -1 if in doubt or not known, this will mean autopilot. |
| [in] | preferred_batch | The preferred maximum number of pages to be moved per defragmentation cycle. Small batches take less time, so if necessary, defragmentation could be stopped faster without losing the intermediate result. On the other hand, smaller batches will require more transaction commits and more page rewrites to achieve a similar result. Specify 0 if in doubt or not known, this will mean no limit. |
| [in] | progress_callback | An optional custom progress notification callback function with the signature MDBX_defrag_notify_func, which will be called time-to-time to notify about the progress of defragmentation. The rate of calls to the provided function is not explicitly defined, but it is guaranteed that it will be called at the beginning and end of each defragmentation cycle, as well as often enough to track progress. Specify nullptr if in doubt or not known, this will mean unused. |
| [in] | ctx | An optional pointer to some context that will be passed to the progress_callback() function as it is. Specify nullptr if in doubt or not known, this will mean unused. |
| [out] | result | An optional address of a MDBX_defrag_result_t structure where the information of defragmentation results will be provided. Specify nullptr if in doubt or not known, this will mean a result is not needed. |
| MDBX_EINVAL | An invalid parameter was specified. |
| MDBX_LAGGARD_READER | One or more readers use old MVCC-snapshots of data and thus do not allow defragmentation to be completed. |
| MDBX_RESULT_TRUE | It was not possible to complete defragmentation or achieve the goals specified by the parameters due to the given limits or other obstacles, that can be knew from the MDBX_defrag_result_t structure. |
| LIBMDBX_API int mdbx_env_delete | ( | const char * | pathname, |
| MDBX_env_delete_mode_t | mode ) |
Delete the environment's files in a proper and multiprocess-safe way.
| [in] | pathname | The pathname for the database or the directory in which the database files reside. |
| [in] | mode | Specifies deletion mode for the environment. This parameter must be set to one of the constants described above in the MDBX_env_delete_mode_t section. |
| MDBX_RESULT_TRUE | No corresponding files or directories were found, so no deletion was performed. |
| LIBMDBX_API int mdbx_env_deleteW | ( | const wchar_t * | pathname, |
| MDBX_env_delete_mode_t | mode ) |
Delete the environment's files in a proper and multiprocess-safe way.
| [in] | pathname | The pathname for the database or the directory in which the database files reside. |
| [in] | mode | Specifies deletion mode for the environment. This parameter must be set to one of the constants described above in the MDBX_env_delete_mode_t section. |
| MDBX_RESULT_TRUE | No corresponding files or directories were found, so no deletion was performed. |
| LIBMDBX_API int mdbx_env_open_for_recovery | ( | MDBX_env * | env, |
| const char * | pathname, | ||
| unsigned | target_meta, | ||
| bool | writeable ) |
Open an environment instance using specific meta-page for checking and recovery.
This function mostly of internal API for mdbx_chk utility and subject to change at any time. Do not use this function to avoid shooting your own leg(s).
| LIBMDBX_API int mdbx_env_open_for_recoveryW | ( | MDBX_env * | env, |
| const wchar_t * | pathname, | ||
| unsigned | target_meta, | ||
| bool | writeable ) |
Open an environment instance using specific meta-page for checking and recovery.
This function mostly of internal API for mdbx_chk utility and subject to change at any time. Do not use this function to avoid shooting your own leg(s).
| LIBMDBX_API int mdbx_env_resurrect_after_fork | ( | MDBX_env * | env | ) |
Restores an instance of the environment in a child process after forking the parent process using fork() or similar system calls.
Without calling mdbx_env_resurrect_after_fork(), it is not possible to use an open instance of the environment in a child process, including all transactions running at the moment of forking.
The actions performed by the function can be considered as reopening the database in a child process, while preserving the set options and addresses of already created instances of most objects accesible via the API.
Forking does not affect the state of the MDBX environment in the parent process. All transactions that were in the parent process at the moment of forking will continue to be performed without interference after forking in the parent process. However, in a child process, all relevant transactions are no longer valid, and an attempt to use ones will result in an error being returned or sending the SIGSEGV signal by the OS kernel.
Using an instance of the environment in a child process is not possible until calling mdbx_env_resurrect_after_fork(), because as a result of forking, the process's PID changes, the value of which is used to organize collaboration with the database, including to track processes/threads performing reading transactions related to the corresponding MVCC-snapshots. All transactions active at the moment of forking cannot continue in the child process, as ones do not own any locks or any MVCC-snapshot and do not keep it from being recycled during garbage collection.
The mdbx_env_resurrect_after_fork() function restores the transferred instance of the environment in the child process after forking, namely: updates the system identifiers used, reopens file descriptors, acquires the necessary locks associated with LCK and DXB database files, restores the memory mappings of the database file, reader tables and auxiliary data to memory. However, transactions inherited from the parent process are not restored, and writing and reading transactions are handled differently:
The reason for not releasing the resources of reading transactions is that historically MDBX does not maintain any general list of reading transaction instances, as this is not required for normal operation, but requires using of atomic operations or additional synchronization objects when creating/destroying instances MDBX_txn.
Calling mdbx_env_resurrect_after_fork() without forking, or not in a child process, or repeated calls do not lead to any actions or changes.
| [in,out] | env | An instance of the environment created by the mdbx_env_create() function. |
| MDBX_BUSY | The database was opened in MDBX_EXCLUSIVE mode. |
| MDBX_EBADSIGN | If the signature of an object instance is corrupted, as well as if mdbx_env_resurrect_after_fork() is called simultaneously from different threads. |
| MDBX_PANIC | A critical error occurred when restoring an instance of the environment, or there was already such an error before calling the function. |
|
inline |
The shortcut to calling mdbx_env_sync_ex() with the force=true and nonblock=false arguments.
| LIBMDBX_API int mdbx_env_sync_ex | ( | MDBX_env * | env, |
| bool | force, | ||
| bool | nonblock ) |
Flush the environment data buffers to disk.
Unless the environment was opened with no-sync flags (MDBX_NOMETASYNC, MDBX_SAFE_NOSYNC and MDBX_UTTERLY_NOSYNC), then data is always written an flushed to disk when mdbx_txn_commit() is called. Otherwise mdbx_env_sync() may be called to manually write and flush unsynced data to disk.
Besides, mdbx_env_sync_ex() with argument force=false may be used to provide polling mode for lazy/asynchronous sync in conjunction with mdbx_env_set_syncbytes() and/or mdbx_env_set_syncperiod().
| [in] | env | An environment handle returned by mdbx_env_create() |
| [in] | force | If non-zero, force a flush. Otherwise, If force is zero, then will run in polling mode, i.e. it will check the thresholds that were set mdbx_env_set_syncbytes() and/or mdbx_env_set_syncperiod() and perform flush if at least one of the thresholds is reached. |
| [in] | nonblock | Don't wait if write transaction is running by other thread. |
| MDBX_EACCES | The environment is read-only. |
| MDBX_BUSY | The environment is used by other thread and nonblock=true. |
| MDBX_EINVAL | An invalid parameter was specified. |
| MDBX_EIO | An error occurred during the flushing/writing data to a storage medium/disk. |
|
inline |
The shortcut to calling mdbx_env_sync_ex() with the force=false and nonblock=true arguments.
| LIBMDBX_API MDBX_cmp_func mdbx_get_datacmp | ( | MDBX_db_flags_t | flags | ) |
Returns default internal data's comparator for given table flags.
| LIBMDBX_API MDBX_cmp_func mdbx_get_keycmp | ( | MDBX_db_flags_t | flags | ) |
Returns default internal key's comparator for given table flags.
| LIBMDBX_API int mdbx_is_readahead_reasonable | ( | size_t | volume, |
| intptr_t | redundancy ) |
Find out whether to use readahead or not, based on the given database size and the amount of available memory.
| [in] | volume | The expected database size in bytes. |
| [in] | redundancy | Additional reserve or overload in case of negative value. |
| MDBX_RESULT_TRUE | Readahead is reasonable. |
| MDBX_RESULT_FALSE | Readahead is NOT reasonable, i.e. MDBX_NORDAHEAD is useful to open environment by mdbx_env_open(). |
| OTHERWISE | the error code. |
| LIBMDBX_API const char * mdbx_ratio2digits | ( | uint64_t | numerator, |
| uint64_t | denominator, | ||
| int | precision, | ||
| char * | buffer, | ||
| size_t | buffer_size ) |
An auxiliary function for converting fractions to string of decimal digits without using floating-point operations.
| LIBMDBX_API const char * mdbx_ratio2percents | ( | uint64_t | value, |
| uint64_t | whole, | ||
| char * | buffer, | ||
| size_t | buffer_size ) |
An auxiliary function for converting fractions to percentage string without using floating-point operations.
| LIBMDBX_API int mdbx_reader_check | ( | MDBX_env * | env, |
| int * | dead ) |
Check for stale entries in the reader lock table.
| [in] | env | An environment handle returned by mdbx_env_create(). |
| [out] | dead | Number of stale slots that were cleared. |
| LIBMDBX_API int mdbx_thread_register | ( | const MDBX_env * | env | ) |
Registers the current thread as a reader for the environment.
To perform read operations without blocking, a reader slot must be assigned for each thread. However, this assignment requires a short-term lock acquisition which is performed automatically. This function allows you to assign the reader slot in advance and thus avoid acquiring a lock when the reading transaction starts firstly from the current thread.
| [in] | env | An environment handle returned by mdbx_env_create(). |
| LIBMDBX_API int mdbx_thread_unregister | ( | const MDBX_env * | env | ) |
Unregisters the current thread as a reader for the environment.
To perform read operations without blocking, a reader slot must be assigned for each thread. However, the assigned reader slot will remain occupied until the thread ends or the environment closes. This function allows you to explicitly release the assigned reader slot.
| [in] | env | An environment handle returned by mdbx_env_create(). |
| LIBMDBX_API int mdbx_txn_copy2fd | ( | MDBX_txn * | txn, |
| mdbx_filehandle_t | fd, | ||
| MDBX_copy_flags_t | flags ) |
Copy an environment by given read transaction to the specified file descriptor, with options.
This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | fd | The file descriptor to write the copy to. It must have already been opened for Write access. |
| [in] | flags | Special options for this operation. |
| LIBMDBX_API int mdbx_txn_copy2pathname | ( | MDBX_txn * | txn, |
| const char * | dest, | ||
| MDBX_copy_flags_t | flags ) |
Copy an MDBX environment by given read transaction to the specified path, with options.
This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | dest | The pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable. |
| [in] | flags | Specifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here: |
| LIBMDBX_API int mdbx_txn_copy2pathnameW | ( | MDBX_txn * | txn, |
| const wchar_t * | dest, | ||
| MDBX_copy_flags_t | flags ) |
Copy an MDBX environment by given read transaction to the specified path, with options.
This function may be used to make a backup of an existing environment. No lockfile is created, since it gets recreated at need.
| [in] | txn | A transaction handle returned by mdbx_txn_begin(). |
| [in] | dest | The pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable. |
| [in] | flags | Specifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here: |
| LIBMDBX_API int mdbx_txn_lock | ( | MDBX_env * | env, |
| bool | dont_wait ) |
Acquires write-transaction lock. Provided for custom and/or complex locking scenarios.
| LIBMDBX_API int mdbx_txn_unlock | ( | MDBX_env * | env | ) |
Releases write-transaction lock. Provided for custom and/or complex locking scenarios.