Skip to content

Group c_err

Modules > c_err

Public Types

Type Name
enum MDBX_error_t
Errors and return codes.
typedef int(* MDBX_hsr_func
A Handle-Slow-Readers callback function to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled.

Public Functions

Type Name
LIBMDBX_API int mdbx_env_set_hsr (MDBX_env * env, MDBX_hsr_func hsr_callback)
Sets a Handle-Slow-Readers callback to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled.
LIBMDBX_API const char * mdbx_liberr2str (int errnum)
Returns a string describing only MDBX error numbers.
LIBMDBX_API const char * mdbx_strerror (int errnum)
Return a string describing a given error code.
LIBMDBX_API const char * mdbx_strerror_ANSI2OEM (int errnum)
Similar to mdbx_strerror() but returns Windows error-messages in the OEM-encoding for console utilities.
LIBMDBX_API const char * mdbx_strerror_r (int errnum, char * buf, size_t buflen)
Return a string describing a given error code.
LIBMDBX_API const char * mdbx_strerror_r_ANSI2OEM (int errnum, char * buf, size_t buflen)
Similar to mdbx_strerror_r() but returns Windows error-messages in the OEM-encoding for console utilities.

Public Types Documentation

enum MDBX_error_t

Errors and return codes.

enum MDBX_error_t {
    MDBX_SUCCESS = 0,
    MDBX_RESULT_FALSE = MDBX_SUCCESS,
    MDBX_RESULT_TRUE = -1,
    MDBX_KEYEXIST = -30799,
    MDBX_FIRST_LMDB_ERRCODE = MDBX_KEYEXIST,
    MDBX_NOTFOUND = -30798,
    MDBX_PAGE_NOTFOUND = -30797,
    MDBX_CORRUPTED = -30796,
    MDBX_PANIC = -30795,
    MDBX_VERSION_MISMATCH = -30794,
    MDBX_INVALID = -30793,
    MDBX_MAP_FULL = -30792,
    MDBX_DBS_FULL = -30791,
    MDBX_READERS_FULL = -30790,
    MDBX_TXN_FULL = -30788,
    MDBX_CURSOR_FULL = -30787,
    MDBX_PAGE_FULL = -30786,
    MDBX_UNABLE_EXTEND_MAPSIZE = -30785,
    MDBX_INCOMPATIBLE = -30784,
    MDBX_BAD_RSLOT = -30783,
    MDBX_BAD_TXN = -30782,
    MDBX_BAD_VALSIZE = -30781,
    MDBX_BAD_DBI = -30780,
    MDBX_PROBLEM = -30779,
    MDBX_LAST_LMDB_ERRCODE = MDBX_PROBLEM,
    MDBX_BUSY = -30778,
    MDBX_FIRST_ADDED_ERRCODE = MDBX_BUSY,
    MDBX_EMULTIVAL = -30421,
    MDBX_EBADSIGN = -30420,
    MDBX_WANNA_RECOVERY = -30419,
    MDBX_EKEYMISMATCH = -30418,
    MDBX_TOO_LARGE = -30417,
    MDBX_THREAD_MISMATCH = -30416,
    MDBX_TXN_OVERLAPPING = -30415,
    MDBX_BACKLOG_DEPLETED = -30414,
    MDBX_DUPLICATED_LCK = -30413,
    MDBX_DANGLING_DBI = -30412,
    MDBX_OUSTED = -30411,
    MDBX_MVCC_RETARDED = -30410,
    MDBX_LAGGARD_READER = -30409,
    MDBX_LAST_ADDED_ERRCODE = MDBX_LAGGARD_READER,
    MDBX_ENODATA = ENODATA,
    MDBX_EINVAL = EINVAL,
    MDBX_EACCESS = EACCES,
    MDBX_ENOMEM = ENOMEM,
    MDBX_EROFS = EROFS,
    MDBX_ENOSYS = ENOTSUP,
    MDBX_EIO = EIO,
    MDBX_EPERM = EPERM,
    MDBX_EINTR = EINTR,
    MDBX_EEXIST = EEXIST,
    MDBX_ENOFILE = ENOENT,
    MDBX_EREMOTE = EREMOTEIO,
    MDBX_EDEADLK = EDEADLK
};

BerkeleyDB uses -30800 to -30999, we'll go under them

See also: mdbx_strerror()

See also: mdbx_strerror_r()

See also: mdbx_liberr2str()

MDBX_SUCCESS Successful result

MDBX_RESULT_FALSE Alias for MDBX_SUCCESS

MDBX_RESULT_TRUE Successful result with special meaning or a flag

MDBX_KEYEXIST key/data pair already exists

MDBX_FIRST_LMDB_ERRCODE The first LMDB-compatible defined error code

MDBX_NOTFOUND key/data pair not found (EOF)

MDBX_PAGE_NOTFOUND Requested page not found - this usually indicates corruption

MDBX_CORRUPTED Database is corrupted (page was wrong type and so on)

MDBX_PANIC Environment had fatal error, i.e. update of meta page failed and so on.

MDBX_VERSION_MISMATCH DB file version mismatch with libmdbx

MDBX_INVALID File is not a valid MDBX file

MDBX_MAP_FULL Environment mapsize reached

MDBX_DBS_FULL Environment maxdbs reached

MDBX_READERS_FULL Environment maxreaders reached

See also: mdbx_env_set_maxreaders()

See also: mdbx_env_get_maxreaders()

See also: mdbx_reader_check()

See also: mdbx_reader_list()

MDBX_TXN_FULL Transaction has too many dirty pages, i.e transaction too big

MDBX_CURSOR_FULL Cursor stack too deep - this usually indicates corruption, i.e branch-pages loop

MDBX_PAGE_FULL Page has not enough space - internal error

MDBX_UNABLE_EXTEND_MAPSIZE Database engine was unable to extend mapping, e.g. since address space is unavailable or busy. This can mean: * Database size extended by other process beyond to environment mapsize and engine was unable to extend mapping while starting read transaction. Environment should be reopened to continue. * Engine was unable to extend mapping during write transaction or explicit call of mdbx_env_set_geometry().

MDBX_INCOMPATIBLE Environment or table is not compatible with the requested operation or the specified flags. This can mean: * The operation expects an MDBX_DUPSORT / MDBX_DUPFIXED table. * Opening a named DB when the unnamed DB has MDBX_DUPSORT / MDBX_INTEGERKEY. * Accessing a data record as a named table, or vice versa. * The table was dropped and recreated with different flags.

MDBX_BAD_RSLOT Reader locktable slot was unexpectly reused or cleared by an enemy thread

MDBX_BAD_TXN Transaction is not valid for requested operation, e.g. had errored and be must aborted, has a child/nested transaction, or is invalid

MDBX_BAD_VALSIZE Invalid size or alignment of key or data for target table, either invalid table name

MDBX_BAD_DBI The specified DBI-handle is invalid or changed by another thread/transaction

MDBX_PROBLEM Unexpected internal error, transaction should be aborted

MDBX_LAST_LMDB_ERRCODE The last LMDB-compatible defined error code

MDBX_BUSY Another write transaction is running or environment is already used while opening with MDBX_EXCLUSIVE flag

MDBX_FIRST_ADDED_ERRCODE The first of MDBX-added error codes

MDBX_EMULTIVAL The specified key has more than one associated value

MDBX_EBADSIGN Bad signature of a runtime object(s), this can mean: * memory corruption or double-free; * ABI version mismatch (rare case);

MDBX_WANNA_RECOVERY Database should be recovered, but this could NOT be done for now since it opened in read-only mode

MDBX_EKEYMISMATCH The given key value is mismatched to the current cursor position

MDBX_TOO_LARGE Database is too large for current system, e.g. could NOT be mapped into RAM.

MDBX_THREAD_MISMATCH A thread has attempted to use a not owned object, e.g. a transaction that started by another thread

MDBX_TXN_OVERLAPPING Overlapping read and write transactions for the current thread

MDBX_BACKLOG_DEPLETED An internal error returned if there is a shortage of available pages when updating the GC. It is used as an auxiliary tool for debugging.

Note:

From the user's point of view, it is semantically equivalent to MDBX_PROBLEM.

MDBX_DUPLICATED_LCK Alternative/Duplicate LCK-file is exists and should be removed manually

MDBX_DANGLING_DBI Some cursors and/or other resources should be closed before table or corresponding DBI-handle could be (re)used and/or closed.

MDBX_OUSTED The parked read transaction was outed for the sake of recycling old MVCC snapshots.

MDBX_MVCC_RETARDED MVCC snapshot used by parked transaction was bygone.

MDBX_LAGGARD_READER An operation cannot continue because a lagging reader is interfering with the reclaiming of GC and old MVCC-snapshots.

MDBX_ENODATA No data available, i.e. the ENODATA counterpart.

MDBX_EINVAL Invalid argument, i.e. the EINVAL counterpart.

MDBX_EACCESS Permission denied, i.e. the EACCES counterpart.

MDBX_ENOMEM Cannot allocate memory, i.e. the ENOMEM counterpart.

MDBX_EROFS Read-only file system, i.e. the EROFS counterpart.

MDBX_ENOSYS Operation not supported, i.e. the ENOTSUP counterpart.

MDBX_EIO I/O error, i.e. the EIO counterpart.

MDBX_EPERM Operation not permitted, i.e. the EPERM counterpart.

MDBX_EINTR Interrupted system call, i.e. the EINTR counterpart.

MDBX_EEXIST File exists, i.e. the EEXIST counterpart.

MDBX_ENOFILE No such file, i.e. the ENOENT counterpart.

MDBX_EREMOTE Cannot use the database on a network file system or when exporting it via NFS.

MDBX_EDEADLK Resource deadlock avoided, i.e. the EDEADLK counterpart.


typedef MDBX_hsr_func

A Handle-Slow-Readers callback function to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled.

typedef int(* MDBX_hsr_func) (const MDBX_env *env, const MDBX_txn *txn, mdbx_pid_t pid, mdbx_tid_t tid, uint64_t laggard, unsigned gap, size_t space, int retry) noexcept;

Read transactions prevent reuse of pages freed by newer write transactions, thus the database can grow quickly. This callback will be called when there is not enough space in the database (i.e. before increasing the database size or before MDBX_MAP_FULL error) and thus can be used to resolve issues with a "long-lived" read transactions.

See also: mdbx_env_set_hsr()

See also: mdbx_env_get_hsr()

See also: mdbx_txn_park()

See also: Long-lived read transactions

See also: mdbx_env_set_maxreaders()

See also: mdbx_env_get_maxreaders()

See also: mdbx_reader_check()

See also: mdbx_reader_list() Using this callback you can choose how to resolve the situation: * abort the write transaction with an error; * wait for the read transaction(s) to complete; * notify a thread performing a long-lived read transaction and wait for an effect; * kill the thread or whole process that performs the long-lived read transaction;

Depending on the arguments and needs, your implementation may wait, terminate a process or thread that is performing a long read, or perform some other action. In doing so it is important that the returned code always corresponds to the performed action.

The callback is invoked with the write transaction lock held by the calling thread. Therefore, the callback must not call mdbx functions on the same environment (in particular, must not start or end a write transaction), otherwise: * on POSIX.1-2001/2008 systems the recursive acquisition of the write transaction lock fails safely with MDBX_EDEADLK error; * on POSIX.1-1988/SysV systems with semaphore-based locking such a call hangs waiting for itself; * on Windows the recursive acquisition likely succeeds and results in a re-entrant entry into libmdbx.

Parameters:

  • env An environment handle returned by mdbx_env_create().
  • txn The current write transaction which internally at the MDBX_MAP_FULL condition.
  • pid A pid of the reader process.
  • tid A thread_id of the reader thread.
  • laggard An oldest read transaction number on which stalled.
  • gap A lag from the last committed txn.
  • space A space that actually become available for reuse after this reader finished. The callback function can take this value into account to evaluate the impact that a long-running transaction has.
  • retry A retry number starting from 0. If callback has returned 0 at least once, then at end of current handling loop the callback function will be called additionally with negative retry value to notify about the end of loop. The callback function can use this fact to implement timeout reset logic while waiting for a readers.

Returns:

The RETURN CODE determines the further actions libmdbx and must match the action which was executed by the callback:

Return value:

  • -2 or less An error condition and the reader was not killed.
  • -1 The callback was unable to solve the problem and agreed on MDBX_MAP_FULL error; libmdbx should increase the database size or return MDBX_MAP_FULL error.
  • 0 (zero) The callback solved the problem or just waited for a while, libmdbx should rescan the reader lock table and retry. This also includes a situation when corresponding transaction terminated in normal way by mdbx_txn_abort() or mdbx_txn_reset(), and my be restarted. I.e. reader slot don't needed to be cleaned from transaction.
  • 1 Transaction aborted asynchronous and reader slot should be cleared immediately, i.e. read transaction will not continue but mdbx_txn_abort() nor mdbx_txn_reset() will be called later.
  • 2 or great The reader process was terminated or killed, and libmdbx should entirely reset reader registration.

Public Functions Documentation

function mdbx_env_set_hsr

Sets a Handle-Slow-Readers callback to resolve database full/overflow issue due to a reader(s) which prevents the old data from being recycled.

LIBMDBX_API int mdbx_env_set_hsr (
    MDBX_env * env,
    MDBX_hsr_func hsr_callback
) 

The callback will only be triggered when the database is full due to a reader(s) prevents the old data from being recycled.

See also: MDBX_hsr_func

See also: mdbx_env_get_hsr()

See also: mdbx_txn_park()

See also: Long-lived read transactions

See also: mdbx_env_set_maxreaders()

See also: mdbx_env_get_maxreaders()

See also: mdbx_reader_check()

See also: mdbx_reader_list()

Parameters:

Returns:

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


function mdbx_liberr2str

Returns a string describing only MDBX error numbers.

LIBMDBX_API const char * mdbx_liberr2str (
    int errnum
) 

Returns NULL for non-MDBX error codes. This function is thread-safe since it returns pointers to constant non-localized strings.

See also: mdbx_strerror() mdbx_strerror_r()

Parameters:

  • errnum The error code.

Returns:

A string describing the MDBX error code, or NULL if the given errnum is not an MDBX error code.


function mdbx_strerror

Return a string describing a given error code.

LIBMDBX_API const char * mdbx_strerror (
    int errnum
) 

This function is a superset of the ANSI C X3.159-1989 (ANSI C) strerror() function. If the error code is greater than or equal to 0, then the string returned by the system function strerror() is returned. If the error code is less than 0, an error string corresponding to the MDBX library error is returned. See errors for a list of MDBX-specific error codes.

mdbx_strerror() is NOT thread-safe because may share common internal buffer for system messages. The returned string must NOT be modified by the application, but MAY be modified by a subsequent call to mdbx_strerror(), strerror() and other related functions.

See also: mdbx_strerror_r()

Parameters:

  • errnum The error code.

Returns:

"error message" The description of the error.


function mdbx_strerror_ANSI2OEM

Similar to mdbx_strerror() but returns Windows error-messages in the OEM-encoding for console utilities.

LIBMDBX_API const char * mdbx_strerror_ANSI2OEM (
    int errnum
) 

Bit of Windows' madness.

See also: mdbx_strerror_r_ANSI2OEM()

Parameters:

  • errnum The error code.

Returns:

"error message" The description of the error.


function mdbx_strerror_r

Return a string describing a given error code.

LIBMDBX_API const char * mdbx_strerror_r (
    int errnum,
    char * buf,
    size_t buflen
) 

This function is a superset of the ANSI C X3.159-1989 (ANSI C) strerror() function. If the error code is greater than or equal to 0, then the string returned by the system function strerror() is returned. If the error code is less than 0, an error string corresponding to the MDBX library error is returned. See errors for a list of MDBX-specific error codes.

mdbx_strerror_r() is thread-safe since uses user-supplied buffer where appropriate. The returned string must NOT be modified by the application, since it may be pointer to internal constant string. However, there is no restriction if the returned string points to the supplied buffer.

See also: mdbx_strerror()

Parameters:

  • errnum The error code.
  • buf Buffer to store the error message.
  • buflen The size of buffer to store the message.

Returns:

"error message" The description of the error.


function mdbx_strerror_r_ANSI2OEM

Similar to mdbx_strerror_r() but returns Windows error-messages in the OEM-encoding for console utilities.

LIBMDBX_API const char * mdbx_strerror_r_ANSI2OEM (
    int errnum,
    char * buf,
    size_t buflen
) 

Bit of Windows' madness.

See also: mdbx_strerror_ANSI2OEM()

Parameters:

  • errnum The error code.
  • buf The buffer to store the message.
  • buflen The size of buffer to store the message.

Returns:

"error message" The description of the error.