libmdbx 0.14.1.444 (2026-03-04T00:16:49+03:00)
One of the fastest compact embeddable key-value ACID storage engine without WAL.
Loading...
Searching...
No Matches
Extra operations

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.

Enumerations

enum  MDBX_copy_flags_t {
  MDBX_CP_DEFAULTS = 0 , MDBX_CP_COMPACT = 1u , MDBX_CP_FORCE_DYNAMIC_SIZE = 2u , MDBX_CP_DONT_FLUSH = 4u ,
  MDBX_CP_THROTTLE_MVCC = 8u , MDBX_CP_DISPOSE_TXN = 16u , MDBX_CP_RENEW_TXN = 32u , MDBX_CP_OVERWRITE = 64u
}
 Environment copy flags. More...
enum  MDBX_env_delete_mode_t { MDBX_ENV_JUST_DELETE = 0 , MDBX_ENV_ENSURE_UNUSED = 1 , MDBX_ENV_WAIT_FOR_UNUSED = 2 }
 Deletion modes for mdbx_env_delete(). More...
enum  MDBX_chk_flags_t {
  MDBX_CHK_DEFAULTS = 0 , MDBX_CHK_READWRITE = 1 , MDBX_CHK_SKIP_BTREE_TRAVERSAL = 2 , MDBX_CHK_SKIP_KV_TRAVERSAL = 4 ,
  MDBX_CHK_IGNORE_ORDER = 8
}
 Flags/options for checking the integrity of a database. More...
enum  MDBX_chk_severity_t {
  MDBX_chk_severity_prio_shift = 4 , MDBX_chk_severity_kind_mask = 0xF , MDBX_chk_fatal = 0x00u , MDBX_chk_error = 0x11u ,
  MDBX_chk_warning = 0x22u , MDBX_chk_notice = 0x33u , MDBX_chk_result = 0x44u , MDBX_chk_resolution = 0x55u ,
  MDBX_chk_processing = 0x56u , MDBX_chk_info = 0x67u , MDBX_chk_verbose = 0x78u , MDBX_chk_details = 0x89u ,
  MDBX_chk_extra = 0x9Au
}
 Levels of logging/detailing of information supplied via callbacks during a database integrity check. More...
enum  MDBX_chk_stage_t {
  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
}
 The verification stages reported via callbacks during a database integrity check. More...
enum  MDBX_defrag_stopping_reasons_t {
  MDBX_defrag_noobstacles = 0 , MDBX_defrag_enough_theshold = 1 , MDBX_defrag_time_limit = 2 , MDBX_defrag_laggard_reader = 4 ,
  MDBX_defrag_large_chunk = 8 , MDBX_defrag_user_break = 16 , MDBX_defrag_error = 32
}
 The returned reasons for stopping database defragmentation. More...

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.

Detailed Description


Class Documentation

◆ MDBX_chk_line_t

struct MDBX_chk_line_t

A virtual row of the report generated during a database integrity check.

See also
mdbx_env_chk()
Class Members
char * begin
struct MDBX_chk_context * ctx
uint8_t empty
char * end
char * out
uint8_t scope_depth
uint8_t severity

◆ MDBX_chk_issue_t

struct MDBX_chk_issue_t

An issue problem was discovered during a database integrity check.

See also
mdbx_env_chk()
Class Members
const char * caption
size_t count
struct MDBX_chk_issue * next

◆ MDBX_chk_scope_t

struct MDBX_chk_scope_t

A hierarchical context during a database integrity check.

See also
mdbx_env_chk()
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

◆ MDBX_chk_histogram

struct MDBX_chk_histogram

A histogram with some statistical information collected during a database integrity check.

See also
mdbx_env_chk()
Class Members
size_t amount
size_t count
size_t le1_amount
size_t le1_count
struct MDBX_chk_histogram.ranges ranges[9]

◆ MDBX_chk_table_t

struct MDBX_chk_table_t

Information about a certain key-value table during a database integrity check.

See also
mdbx_env_chk()
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

◆ MDBX_chk_context_t

struct MDBX_chk_context_t

The context for checking the integrity of a database.

See also
mdbx_env_chk()
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

◆ MDBX_chk_callbacks_t

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’.

Note
This API has not been frozen yet, and there may be improvements and changes in subsequent versions.
See also
mdbx_env_chk()
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

◆ MDBX_defrag_result_t

struct MDBX_defrag_result_t

The numerical metrics of progress and result of database defragmentation.

See also
mdbx_env_defrag()
MDBX_defrag_notify_func
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.

◆ MDBX_chk_scope_t.usr_z

union MDBX_chk_scope_t.usr_z
Class Members
size_t number
void * ptr

◆ MDBX_chk_scope_t.usr_v

union MDBX_chk_scope_t.usr_v
Class Members
size_t number
void * ptr

◆ MDBX_chk_scope_t.usr_o

union MDBX_chk_scope_t.usr_o
Class Members
size_t number
void * ptr

◆ MDBX_chk_histogram.ranges

struct MDBX_chk_histogram.ranges
Class Members
size_t amount
size_t begin
size_t count
size_t end

◆ MDBX_chk_table_t.pages

struct MDBX_chk_table_t.pages
Class Members
size_t all
size_t branch
size_t broken
size_t empty
size_t leaf
size_t nested_branch
size_t nested_leaf
size_t nested_subleaf

◆ MDBX_chk_table_t.histogram

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

◆ MDBX_chk_context_t.result

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 Documentation

◆ MDBX_chk_user_table_cookie_t

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.

See also
mdbx_env_chk()

◆ MDBX_defrag_notify_func

typedef int(* MDBX_defrag_notify_func) (void *ctx, const MDBX_defrag_result_t *progress) noexcept
noexcept

A callback function to notify an application about the progress of defragmentation.

See also
mdbx_env_defrag()

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.

Parameters
[in]ctxA pointer to the context passed by a similar parameter in mdbx_env_defrag().
[in]progressA pointer to the MDBX_defrag_result_t structure filled in to reflects the current state of database defragmentation.
Returns
Any non-zero value will indicates a "user break" condition to abort defragmentation immediately.

Enumeration Type Documentation

◆ MDBX_chk_flags_t

Flags/options for checking the integrity of a database.

Note
This API has not been frozen yet, there may be improvements and changes in subsequent versions.
See also
mdbx_env_chk()
Enumerator
MDBX_CHK_DEFAULTS 

The check mode by default, including read-only mode.

MDBX_CHK_READWRITE 

Checking in read-write mode, with locking and suspending writing transactions.

MDBX_CHK_SKIP_BTREE_TRAVERSAL 

Skip the page tree crawl.

MDBX_CHK_SKIP_KV_TRAVERSAL 

Skip iterating and viewing key-value records.

MDBX_CHK_IGNORE_ORDER 

Ignore the order of keys and values.

Note
This options is required when checking databases created using non-standard (custom) key and/or value comparison functions.

◆ MDBX_chk_severity_t

Levels of logging/detailing of information supplied via callbacks during a database integrity check.

See also
mdbx_env_chk()
Enumerator
MDBX_chk_severity_prio_shift 
MDBX_chk_severity_kind_mask 
MDBX_chk_fatal 
MDBX_chk_error 
MDBX_chk_warning 
MDBX_chk_notice 
MDBX_chk_result 
MDBX_chk_resolution 
MDBX_chk_processing 
MDBX_chk_info 
MDBX_chk_verbose 
MDBX_chk_details 
MDBX_chk_extra 

◆ MDBX_chk_stage_t

The verification stages reported via callbacks during a database integrity check.

See also
mdbx_env_chk()
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 

◆ MDBX_copy_flags_t

Environment copy flags.

See also
mdbx_env_copy()
mdbx_env_copy2fd()
mdbx_txn_copy2pathname()
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

See also
mdbx_txn_park()
MDBX_CP_DISPOSE_TXN 

Abort/dispose passed transaction after copy

See also
mdbx_txn_copy2fd()
mdbx_txn_copy2pathname()
MDBX_CP_RENEW_TXN 

Enable renew/restart read transaction in case it use outdated MVCC shapshot, otherwise the MDBX_MVCC_RETARDED will be returned

See also
mdbx_txn_copy2fd()
mdbx_txn_copy2pathname()
MDBX_CP_OVERWRITE 

Silently overwrite the target file, if it exists, instead of returning an error

See also
mdbx_txn_copy2pathname()
mdbx_env_copy()

◆ MDBX_defrag_stopping_reasons_t

The returned reasons for stopping database defragmentation.

Any number of individual values could be OR'ed together while while returning actual set of reasons.

See also
MDBX_defrag_result_t
mdbx_env_defrag()
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 

◆ MDBX_env_delete_mode_t

Deletion modes for mdbx_env_delete().

See also
mdbx_env_delete()
Enumerator
MDBX_ENV_JUST_DELETE 

Just delete the environment's files and directory if any.

Note
On POSIX systems, processes already working with the database will continue to work without interference until it close the environment.
On Windows, the behavior of MDBX_ENV_JUST_DELETE is different because the system does not support deleting files that are currently memory mapped.
MDBX_ENV_ENSURE_UNUSED 

Make sure that the environment is not being used by other processes, or return an error otherwise.

MDBX_ENV_WAIT_FOR_UNUSED 

Wait until other processes closes the environment before deletion.

Function Documentation

◆ mdbx_cursor_ignord()

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.

See also
avoid_custom_comparators
Returns
A non-zero error value on failure and 0 on success.

◆ mdbx_env_chk()

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.

Parameters
[in]envA pointer to an instance of environment.
[in]cbA set of callback functions.
[in,out]ctxThe context of a database integrity check, where the results of the check will be generated.
[in]flagsFlags/options for checking database integrity.
[in]verbosityThe required level of detail of information about the progress and results of the checking.
[in]timeout_seconds_16dot16The duration limit for performing the check in 1/65536 fractions of a second, either 0 means no limit.
Returns
A non-zero error value on failure and 0 on success.

◆ mdbx_env_chk_encount_problem()

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.

See also
mdbx_env_chk()
MDBX_debug_func
Returns
A non-zero error value on failure and 0 on success.

◆ mdbx_env_copy()

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.

Note
This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Restrictions & Caveats section.
On Windows the mdbx_env_copyW() is recommended to use.
See also
mdbx_env_copy2fd()
mdbx_txn_copy2pathname()
Parameters
[in]envAn environment handle returned by mdbx_env_create(). It must have already been opened successfully.
[in]destThe pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable.
[in]flagsSpecifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here:
  • MDBX_CP_DEFAULTS Perform copy as-is without compaction, etc.
  • MDBX_CP_COMPACT Perform compaction while copying: omit free pages and sequentially renumber all pages in output. This option consumes little bit more CPU for processing, but may running quickly than the default, on account skipping free pages.
  • 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 to reduce the time of the operation and the duration of the transaction.
  • MDBX_CP_THROTTLE_MVCC Use read transaction parking during copying MVCC-snapshot to avoid stopping recycling and overflowing the database. This allows the writing transaction to oust the read transaction used to copy the database if copying takes so long that it will interfere with the recycling old MVCC snapshots and may lead to an overflow of the database. However, if the reading transaction is ousted the copy will be aborted until successful completion. Thus, this option allows copy the database without interfering with write transactions and a threat of database overflow, but at the cost that copying will be aborted to prevent such conditions.
    See also
    mdbx_txn_park()
    Returns
    A non-zero error value on failure and 0 on success.

◆ mdbx_env_copy2fd()

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.

See also
mdbx_env_copy()
mdbx_txn_copy2fd()
Note
This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Restrictions & Caveats section.
Fails if the environment has suffered a page leak and the destination file descriptor is associated with a pipe, socket, or FIFO.
Parameters
[in]envAn environment handle returned by mdbx_env_create(). It must have already been opened successfully.
[in]fdThe file descriptor to write the copy to. It must have already been opened for Write access.
[in]flagsSpecial options for this operation.
See also
mdbx_env_copy()
Returns
A non-zero error value on failure and 0 on success.

◆ mdbx_env_copyW()

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.

Note
This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Restrictions & Caveats section.
On Windows the mdbx_env_copyW() is recommended to use.
See also
mdbx_env_copy2fd()
mdbx_txn_copy2pathname()
Parameters
[in]envAn environment handle returned by mdbx_env_create(). It must have already been opened successfully.
[in]destThe pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable.
[in]flagsSpecifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here:
  • MDBX_CP_DEFAULTS Perform copy as-is without compaction, etc.
  • MDBX_CP_COMPACT Perform compaction while copying: omit free pages and sequentially renumber all pages in output. This option consumes little bit more CPU for processing, but may running quickly than the default, on account skipping free pages.
  • 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 to reduce the time of the operation and the duration of the transaction.
  • MDBX_CP_THROTTLE_MVCC Use read transaction parking during copying MVCC-snapshot to avoid stopping recycling and overflowing the database. This allows the writing transaction to oust the read transaction used to copy the database if copying takes so long that it will interfere with the recycling old MVCC snapshots and may lead to an overflow of the database. However, if the reading transaction is ousted the copy will be aborted until successful completion. Thus, this option allows copy the database without interfering with write transactions and a threat of database overflow, but at the cost that copying will be aborted to prevent such conditions.
    See also
    mdbx_txn_park()
    Returns
    A non-zero error value on failure and 0 on success.
    Note
    Available only on Windows.
    See also
    mdbx_env_copy()

◆ mdbx_env_defrag()

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.

See also
MDBX_defrag_notify_func
MDBX_defrag_result_t

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.

Note
Any parallel reading transactions do not make defragmentation impossible, but ones limit it to single cycle and will definitely disallow to be performed completely.

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.

Parameters
[in]envA pointer to an instance of environment.
[in]defrag_atleastThe 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_16dot16The 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_enoughThe 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_16dot16The 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_backlashDefragmentation 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_batchThe 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_callbackAn 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]ctxAn 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]resultAn 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.
Returns
A non-zero error value on failure and 0 on success, some possible errors are:
Return values
MDBX_EINVALAn invalid parameter was specified.
MDBX_LAGGARD_READEROne or more readers use old MVCC-snapshots of data and thus do not allow defragmentation to be completed.
MDBX_RESULT_TRUEIt 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.

◆ mdbx_env_delete()

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.

Note
On Windows the mdbx_env_deleteW() is recommended to use.
Parameters
[in]pathnameThe pathname for the database or the directory in which the database files reside.
[in]modeSpecifies 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.
Note
The MDBX_ENV_JUST_DELETE don't supported on Windows since system unable to delete a memory-mapped files.
Returns
A non-zero error value on failure and 0 on success, some possible errors are:
Return values
MDBX_RESULT_TRUENo corresponding files or directories were found, so no deletion was performed.

◆ mdbx_env_deleteW()

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.

Note
On Windows the mdbx_env_deleteW() is recommended to use.
Parameters
[in]pathnameThe pathname for the database or the directory in which the database files reside.
[in]modeSpecifies 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.
Note
The MDBX_ENV_JUST_DELETE don't supported on Windows since system unable to delete a memory-mapped files.
Returns
A non-zero error value on failure and 0 on success, some possible errors are:
Return values
MDBX_RESULT_TRUENo corresponding files or directories were found, so no deletion was performed.
Note
Available only on Windows.
See also
mdbx_env_delete()

◆ mdbx_env_open_for_recovery()

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).

Note
On Windows the mdbx_env_open_for_recoveryW() is recommended to use.

◆ mdbx_env_open_for_recoveryW()

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).

Note
On Windows the mdbx_env_open_for_recoveryW() is recommended to use.
Available only on Windows.
See also
mdbx_env_open_for_recovery()

◆ mdbx_env_resurrect_after_fork()

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.

Note
This function is not available in the Windows OS family due to the lack of process forking functionality in the operating system 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 writing transaction, if there was one at the moment of forking, is aborted in the child process with the release of its associated resources, including all nested transactions.
  • The reading transactions, if any in the parent process, are logically aborted in the child process, but without releasing resources. Therefore, it is necessary to provide a call to mdbx_txn_abort() for each such reading transaction in the child process, or accept resource leakage until the child process is termitaned.

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.

Parameters
[in,out]envAn instance of the environment created by the mdbx_env_create() function.
Returns
A non-zero error value on failure and 0 on success, some possible errors are:
Return values
MDBX_BUSYThe database was opened in MDBX_EXCLUSIVE mode.
MDBX_EBADSIGNIf the signature of an object instance is corrupted, as well as if mdbx_env_resurrect_after_fork() is called simultaneously from different threads.
MDBX_PANICA critical error occurred when restoring an instance of the environment, or there was already such an error before calling the function.

◆ mdbx_env_sync()

int mdbx_env_sync ( MDBX_env * env)
inline

The shortcut to calling mdbx_env_sync_ex() with the force=true and nonblock=false arguments.

◆ mdbx_env_sync_ex()

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().

Note
This call is not valid if the environment was opened with MDBX_RDONLY.
Parameters
[in]envAn environment handle returned by mdbx_env_create()
[in]forceIf 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]nonblockDon't wait if write transaction is running by other thread.
Returns
A non-zero error value on failure and MDBX_RESULT_TRUE or 0 on success. The MDBX_RESULT_TRUE means no data pending for flush to disk, and 0 otherwise. Some possible errors are:
Return values
MDBX_EACCESThe environment is read-only.
MDBX_BUSYThe environment is used by other thread and nonblock=true.
MDBX_EINVALAn invalid parameter was specified.
MDBX_EIOAn error occurred during the flushing/writing data to a storage medium/disk.

◆ mdbx_env_sync_poll()

int mdbx_env_sync_poll ( MDBX_env * env)
inline

The shortcut to calling mdbx_env_sync_ex() with the force=false and nonblock=true arguments.

◆ mdbx_get_datacmp()

LIBMDBX_API MDBX_cmp_func mdbx_get_datacmp ( MDBX_db_flags_t flags)

Returns default internal data's comparator for given table flags.

◆ mdbx_get_keycmp()

LIBMDBX_API MDBX_cmp_func mdbx_get_keycmp ( MDBX_db_flags_t flags)

Returns default internal key's comparator for given table flags.

◆ mdbx_is_readahead_reasonable()

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.

Parameters
[in]volumeThe expected database size in bytes.
[in]redundancyAdditional reserve or overload in case of negative value.
Returns
A MDBX_RESULT_TRUE or MDBX_RESULT_FALSE value, otherwise the error code.
Return values
MDBX_RESULT_TRUEReadahead is reasonable.
MDBX_RESULT_FALSEReadahead is NOT reasonable, i.e. MDBX_NORDAHEAD is useful to open environment by mdbx_env_open().
OTHERWISEthe error code.

◆ mdbx_ratio2digits()

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.

Note
The accuracy of the conversion result is limited both by the simplicity of the algorithms and by 64-bit arithmetic.
Returns
A pointer to the beginning of the string with the result of conversion.

◆ mdbx_ratio2percents()

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.

Note
The accuracy of the conversion result is limited both by the simplicity of the algorithms and by 64-bit arithmetic.
Returns
A pointer to the beginning of the string with the result of conversion.

◆ mdbx_reader_check()

LIBMDBX_API int mdbx_reader_check ( MDBX_env * env,
int * dead )

Check for stale entries in the reader lock table.

Parameters
[in]envAn environment handle returned by mdbx_env_create().
[out]deadNumber of stale slots that were cleared.
Returns
A non-zero error value on failure and 0 on success, or MDBX_RESULT_TRUE if a dead reader(s) found or mutex was recovered.

◆ mdbx_thread_register()

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.

See also
mdbx_thread_unregister()
Note
Threads are registered automatically the first time a read transaction starts. Therefore, there is no need to use this function, except in special cases.
Parameters
[in]envAn environment handle returned by mdbx_env_create().
Returns
A non-zero error value on failure and 0 on success, or MDBX_RESULT_TRUE if thread is already registered.

◆ mdbx_thread_unregister()

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.

See also
mdbx_thread_register()
Parameters
[in]envAn environment handle returned by mdbx_env_create().
Returns
A non-zero error value on failure and 0 on success, or MDBX_RESULT_TRUE if thread is not registered or already unregistered.

◆ mdbx_txn_copy2fd()

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.

See also
mdbx_txn_copy2pathname()
mdbx_env_copy2fd()
Note
This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Restrictions & Caveats section.
Fails if the environment has suffered a page leak and the destination file descriptor is associated with a pipe, socket, or FIFO.
Parameters
[in]txnA transaction handle returned by mdbx_txn_begin().
[in]fdThe file descriptor to write the copy to. It must have already been opened for Write access.
[in]flagsSpecial options for this operation.
See also
mdbx_env_copy()
Returns
A non-zero error value on failure and 0 on success.

◆ mdbx_txn_copy2pathname()

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.

Note
This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Restrictions & Caveats section.
On Windows the mdbx_txn_copy2pathnameW() is recommended to use.
See also
mdbx_txn_copy2fd()
mdbx_env_copy()
Parameters
[in]txnA transaction handle returned by mdbx_txn_begin().
[in]destThe pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable.
[in]flagsSpecifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here:
  • MDBX_CP_DEFAULTS Perform copy as-is without compaction, etc.
  • MDBX_CP_COMPACT Perform compaction while copying: omit free pages and sequentially renumber all pages in output. This option consumes little bit more CPU for processing, but may running quickly than the default, on account skipping free pages.
  • 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 to reduce the time of the operation and the duration of the transaction.
  • MDBX_CP_THROTTLE_MVCC Use read transaction parking during copying MVCC-snapshot to avoid stopping recycling and overflowing the database. This allows the writing transaction to oust the read transaction used to copy the database if copying takes so long that it will interfere with the recycling old MVCC snapshots and may lead to an overflow of the database. However, if the reading transaction is ousted the copy will be aborted until successful completion. Thus, this option allows copy the database without interfering with write transactions and a threat of database overflow, but at the cost that copying will be aborted to prevent such conditions.
    See also
    mdbx_txn_park()
    Returns
    A non-zero error value on failure and 0 on success.

◆ mdbx_txn_copy2pathnameW()

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.

Note
This call can trigger significant file size growth if run in parallel with write transactions, because it employs a read-only transaction. See long-lived transactions under Restrictions & Caveats section.
On Windows the mdbx_txn_copy2pathnameW() is recommended to use.
See also
mdbx_txn_copy2fd()
mdbx_env_copy()
Parameters
[in]txnA transaction handle returned by mdbx_txn_begin().
[in]destThe pathname of a file in which the copy will reside. This file must not be already exist, but parent directory must be writable.
[in]flagsSpecifies options for this operation. This parameter must be bitwise OR'ing together any of the constants described here:
  • MDBX_CP_DEFAULTS Perform copy as-is without compaction, etc.
  • MDBX_CP_COMPACT Perform compaction while copying: omit free pages and sequentially renumber all pages in output. This option consumes little bit more CPU for processing, but may running quickly than the default, on account skipping free pages.
  • 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 to reduce the time of the operation and the duration of the transaction.
  • MDBX_CP_THROTTLE_MVCC Use read transaction parking during copying MVCC-snapshot to avoid stopping recycling and overflowing the database. This allows the writing transaction to oust the read transaction used to copy the database if copying takes so long that it will interfere with the recycling old MVCC snapshots and may lead to an overflow of the database. However, if the reading transaction is ousted the copy will be aborted until successful completion. Thus, this option allows copy the database without interfering with write transactions and a threat of database overflow, but at the cost that copying will be aborted to prevent such conditions.
    See also
    mdbx_txn_park()
    Returns
    A non-zero error value on failure and 0 on success.
    Note
    Available only on Windows.
    See also
    mdbx_txn_copy2pathname()

◆ mdbx_txn_lock()

LIBMDBX_API int mdbx_txn_lock ( MDBX_env * env,
bool dont_wait )

Acquires write-transaction lock. Provided for custom and/or complex locking scenarios.

Returns
A non-zero error value on failure and 0 on success.

◆ mdbx_txn_unlock()

LIBMDBX_API int mdbx_txn_unlock ( MDBX_env * env)

Releases write-transaction lock. Provided for custom and/or complex locking scenarios.

Returns
A non-zero error value on failure and 0 on success.