mdbx: refine/clarify error messages.

Change-Id: If2a38bdfb4a9fce176acb87fa452709bcfc5c972
This commit is contained in:
Leonid Yuriev 2020-02-02 02:14:27 +03:00
parent 17fe5f106b
commit a594f79e5f
2 changed files with 56 additions and 43 deletions

32
mdbx.h
View File

@ -1412,7 +1412,7 @@ typedef enum MDBX_cursor_op {
/* Environment maxreaders reached */ /* Environment maxreaders reached */
#define MDBX_READERS_FULL (-30790) #define MDBX_READERS_FULL (-30790)
/* Txn has too many dirty pages */ /* Transaction has too many dirty pages, i.e transaction too big */
#define MDBX_TXN_FULL (-30788) #define MDBX_TXN_FULL (-30788)
/* Cursor stack too deep - internal error */ /* Cursor stack too deep - internal error */
@ -1421,30 +1421,35 @@ typedef enum MDBX_cursor_op {
/* Page has not enough space - internal error */ /* Page has not enough space - internal error */
#define MDBX_PAGE_FULL (-30786) #define MDBX_PAGE_FULL (-30786)
/* Database contents grew beyond environment mapsize */ /* Database contents grew beyond environment mapsize and engine was
* unable to extend mapping, e.g. since address space is unavailable or busy */
#define MDBX_MAP_RESIZED (-30785) #define MDBX_MAP_RESIZED (-30785)
/* Operation and DB incompatible, or DB type changed. This can mean: /* Environment or database is not compatible with the requested operation
* or the specified flags. This can mean:
* - The operation expects an MDBX_DUPSORT / MDBX_DUPFIXED database. * - The operation expects an MDBX_DUPSORT / MDBX_DUPFIXED database.
* - Opening a named DB when the unnamed DB has MDBX_DUPSORT/MDBX_INTEGERKEY. * - Opening a named DB when the unnamed DB has MDBX_DUPSORT/MDBX_INTEGERKEY.
* - Accessing a data record as a database, or vice versa. * - Accessing a data record as a database, or vice versa.
* - The database was dropped and recreated with different flags. */ * - The database was dropped and recreated with different flags. */
#define MDBX_INCOMPATIBLE (-30784) #define MDBX_INCOMPATIBLE (-30784)
/* Invalid reuse of reader locktable slot */ /* Invalid reuse of reader locktable slot,
* e.g. read-transaction already run for current thread */
#define MDBX_BAD_RSLOT (-30783) #define MDBX_BAD_RSLOT (-30783)
/* Transaction must abort, has a child, or is invalid */ /* Transaction is not valid for requested operation,
* e.g. had errored and be must aborted, has a child, or is invalid */
#define MDBX_BAD_TXN (-30782) #define MDBX_BAD_TXN (-30782)
/* Unsupported size of key/DB name/data, or wrong DUPFIXED size, /* Invalid size or alignment of key or data for target database,
* or wrong aligment */ * either invalid subDB name */
#define MDBX_BAD_VALSIZE (-30781) #define MDBX_BAD_VALSIZE (-30781)
/* The specified DBI was changed unexpectedly */ /* The specified DBI-handle is invalid
* or changed by another thread/transaction */
#define MDBX_BAD_DBI (-30780) #define MDBX_BAD_DBI (-30780)
/* Unexpected problem - txn should abort */ /* Unexpected internal error, transaction should be aborted */
#define MDBX_PROBLEM (-30779) #define MDBX_PROBLEM (-30779)
/* The last LMDB-compatible defined error code */ /* The last LMDB-compatible defined error code */
@ -1454,8 +1459,7 @@ typedef enum MDBX_cursor_op {
* opening with MDBX_EXCLUSIVE flag */ * opening with MDBX_EXCLUSIVE flag */
#define MDBX_BUSY (-30778) #define MDBX_BUSY (-30778)
/* The mdbx_put() or mdbx_replace() was called for key, /* The specified key has more than one associated value */
* that has more that one associated value. */
#define MDBX_EMULTIVAL (-30421) #define MDBX_EMULTIVAL (-30421)
/* Bad signature of a runtime object(s), this can mean: /* Bad signature of a runtime object(s), this can mean:
@ -1463,8 +1467,8 @@ typedef enum MDBX_cursor_op {
* - ABI version mismatch (rare case); */ * - ABI version mismatch (rare case); */
#define MDBX_EBADSIGN (-30420) #define MDBX_EBADSIGN (-30420)
/* Database should be recovered, but this could NOT be done automatically /* Database should be recovered, but this could NOT be done for now
* right now (e.g. in readonly mode and so forth). */ * since it opened in read-only mode */
#define MDBX_WANNA_RECOVERY (-30419) #define MDBX_WANNA_RECOVERY (-30419)
/* The given key value is mismatched to the current cursor position, /* The given key value is mismatched to the current cursor position,
@ -1479,7 +1483,7 @@ typedef enum MDBX_cursor_op {
* e.g. a transaction that started by another thread. */ * e.g. a transaction that started by another thread. */
#define MDBX_THREAD_MISMATCH (-30416) #define MDBX_THREAD_MISMATCH (-30416)
/* Overlapping read and write transactions for the same thread */ /* Overlapping read and write transactions for the current thread */
#define MDBX_TXN_OVERLAPPING (-30415) #define MDBX_TXN_OVERLAPPING (-30415)
/**** FUNCTIONS & RELATED STRUCTURES ******************************************/ /**** FUNCTIONS & RELATED STRUCTURES ******************************************/

View File

@ -3186,23 +3186,29 @@ static const char *__mdbx_strerr(int errnum) {
"MDBX_VERSION_MISMATCH: DB version mismatch libmdbx", "MDBX_VERSION_MISMATCH: DB version mismatch libmdbx",
"MDBX_INVALID: File is not an MDBX file", "MDBX_INVALID: File is not an MDBX file",
"MDBX_MAP_FULL: Environment mapsize limit reached", "MDBX_MAP_FULL: Environment mapsize limit reached",
"MDBX_DBS_FULL: Too may DBI (maxdbs reached)", "MDBX_DBS_FULL: Too may DBI-handles (maxdbs reached)",
"MDBX_READERS_FULL: Too many readers (maxreaders reached)", "MDBX_READERS_FULL: Too many readers (maxreaders reached)",
NULL /* MDBX_TLS_FULL (-30789): unused in MDBX */, NULL /* MDBX_TLS_FULL (-30789): unused in MDBX */,
"MDBX_TXN_FULL: Transaction has too many dirty pages, " "MDBX_TXN_FULL: Transaction has too many dirty pages,"
"i.e transaction too big", " i.e transaction too big",
"MDBX_CURSOR_FULL: Internal error - cursor stack limit reached", "MDBX_CURSOR_FULL: Internal error - Cursor stack limit reached",
"MDBX_PAGE_FULL: Internal error - page has no more space", "MDBX_PAGE_FULL: Internal error - Page has no more space",
"MDBX_MAP_RESIZED: Database contents grew beyond environment mapsize", "MDBX_MAP_RESIZED: Database contents grew beyond environment mapsize"
"MDBX_INCOMPATIBLE: Operation and DB incompatible, or DB flags changed", " and engine was unable to extend mapping,"
"MDBX_BAD_RSLOT: Invalid reuse of reader locktable slot", " e.g. since address space is unavailable or busy",
"MDBX_BAD_TXN: Transaction must abort, has a child, or is invalid", "MDBX_INCOMPATIBLE: Environment or database is not compatible"
"MDBX_BAD_VALSIZE: Unsupported size of key/DB name/data, or wrong " " with the requested operation or the specified flags",
"DUPFIXED size", "MDBX_BAD_RSLOT: Invalid reuse of reader locktable slot,"
"MDBX_BAD_DBI: The specified DBI handle was closed/changed unexpectedly", " e.g. read-transaction already run for current thread",
"MDBX_PROBLEM: Unexpected problem - txn should abort", "MDBX_BAD_TXN: Transaction is not valid for requested operation,"
"MDBX_BUSY: Another write transaction is running or " " e.g. had errored and be must aborted, has a child, or is invalid",
"environment is already used while opening with MDBX_EXCLUSIVE flag", "MDBX_BAD_VALSIZE: Invalid size or alignment of key or data"
" for target database, either invalid subDB 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_BUSY: Another write transaction is running,"
" or environment is already used while opening with MDBX_EXCLUSIVE flag",
}; };
if (errnum >= MDBX_KEYEXIST && errnum <= MDBX_LAST_LMDB_ERRCODE) { if (errnum >= MDBX_KEYEXIST && errnum <= MDBX_LAST_LMDB_ERRCODE) {
@ -3214,24 +3220,27 @@ static const char *__mdbx_strerr(int errnum) {
case MDBX_SUCCESS: case MDBX_SUCCESS:
return "MDBX_SUCCESS: Successful"; return "MDBX_SUCCESS: Successful";
case MDBX_EMULTIVAL: case MDBX_EMULTIVAL:
return "MDBX_EMULTIVAL: Unable to update multi-value for the given key"; return "MDBX_EMULTIVAL: The specified key has"
" more than one associated value";
case MDBX_EBADSIGN: case MDBX_EBADSIGN:
return "MDBX_EBADSIGN: Wrong signature of a runtime object(s)"; return "MDBX_EBADSIGN: Wrong signature of a runtime object(s),"
" e.g. memory corruption or double-free";
case MDBX_WANNA_RECOVERY: case MDBX_WANNA_RECOVERY:
return "MDBX_WANNA_RECOVERY: Database should be recovered, but this could " return "MDBX_WANNA_RECOVERY: Database should be recovered,"
"NOT be done in a read-only mode"; " but this could NOT be done automatically for now"
" since it opened in read-only mode";
case MDBX_EKEYMISMATCH: case MDBX_EKEYMISMATCH:
return "MDBX_EKEYMISMATCH: The given key value is mismatched to the " return "MDBX_EKEYMISMATCH: The given key value is mismatched to the"
"current cursor position"; " current cursor position";
case MDBX_TOO_LARGE: case MDBX_TOO_LARGE:
return "MDBX_TOO_LARGE: Database is too large for current system, " return "MDBX_TOO_LARGE: Database is too large for current system,"
"e.g. could NOT be mapped into RAM"; " e.g. could NOT be mapped into RAM";
case MDBX_THREAD_MISMATCH: case MDBX_THREAD_MISMATCH:
return "MDBX_THREAD_MISMATCH: A thread has attempted to use a not " return "MDBX_THREAD_MISMATCH: A thread has attempted to use a not"
"owned object, e.g. a transaction that started by another thread"; " owned object, e.g. a transaction that started by another thread";
case MDBX_TXN_OVERLAPPING: case MDBX_TXN_OVERLAPPING:
return "MDBX_TXN_OVERLAPPING: Overlapping read and write transactions for " return "MDBX_TXN_OVERLAPPING: Overlapping read and write transactions for"
"the same thread"; " the current thread";
default: default:
return NULL; return NULL;
} }
@ -5950,7 +5959,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
if (unlikely(txn->mt_txnid == 0 || if (unlikely(txn->mt_txnid == 0 ||
txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) { txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) {
mdbx_error("%s", "environment corrupted by died writer, must shutdown!"); mdbx_error("%s", "environment corrupted by died writer, must shutdown!");
rc = MDBX_WANNA_RECOVERY; rc = MDBX_CORRUPTED;
goto bailout; goto bailout;
} }
mdbx_assert(env, txn->mt_txnid >= *env->me_oldest); mdbx_assert(env, txn->mt_txnid >= *env->me_oldest);
@ -9360,7 +9369,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
const unsigned meta_clash_mask = mdbx_meta_eq_mask(env); const unsigned meta_clash_mask = mdbx_meta_eq_mask(env);
if (meta_clash_mask) { if (meta_clash_mask) {
mdbx_error("meta-pages are clashed: mask 0x%d", meta_clash_mask); mdbx_error("meta-pages are clashed: mask 0x%d", meta_clash_mask);
return MDBX_WANNA_RECOVERY; return MDBX_CORRUPTED;
} }
while (1) { while (1) {