mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:14:12 +08:00
mdbx: refine assections (minor).
Change-Id: Ic924988b8ce043d6106df381c996dd2c8ff9ca1f
This commit is contained in:
parent
60bba72aa1
commit
c4e1c2b488
56
src/mdbx.c
56
src/mdbx.c
@ -2127,9 +2127,9 @@ static int mdbx_mapresize(MDBX_env *env, const pgno_t size_pgno,
|
||||
bailout:
|
||||
if (rc == MDBX_SUCCESS) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
assert(size_bytes == env->me_dxb_mmap.current);
|
||||
assert(size_bytes <= env->me_dxb_mmap.filesize);
|
||||
assert(limit_bytes == env->me_dxb_mmap.length);
|
||||
mdbx_assert(env, size_bytes == env->me_dxb_mmap.current);
|
||||
mdbx_assert(env, size_bytes <= env->me_dxb_mmap.filesize);
|
||||
mdbx_assert(env, limit_bytes == env->me_dxb_mmap.length);
|
||||
#endif
|
||||
env->me_dbgeo.now = size_bytes;
|
||||
env->me_dbgeo.upper = limit_bytes;
|
||||
@ -2232,7 +2232,7 @@ static int mdbx_page_alloc(MDBX_cursor *mc, unsigned num, MDBX_page **mp,
|
||||
|
||||
if (likely(flags & MDBX_ALLOC_CACHE)) {
|
||||
/* If there are any loose pages, just use them */
|
||||
assert(mp && num);
|
||||
mdbx_assert(env, mp && num);
|
||||
if (likely(num == 1 && txn->mt_loose_pages)) {
|
||||
np = txn->mt_loose_pages;
|
||||
txn->mt_loose_pages = NEXT_LOOSE_PAGE(np);
|
||||
@ -2563,7 +2563,7 @@ static int mdbx_page_alloc(MDBX_cursor *mc, unsigned num, MDBX_page **mp,
|
||||
*mp = NULL;
|
||||
txn->mt_flags |= MDBX_TXN_ERROR;
|
||||
}
|
||||
assert(rc);
|
||||
mdbx_assert(env, rc != MDBX_SUCCESS);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -2841,7 +2841,7 @@ static int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock) {
|
||||
env->me_sync_pending >
|
||||
pgno2bytes(env, 16 /* FIXME: define threshold */) &&
|
||||
(flags & MDBX_NOSYNC) == 0) {
|
||||
assert(((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0);
|
||||
mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0);
|
||||
const size_t usedbytes = pgno_align2os_bytes(env, head->mm_geo.next);
|
||||
|
||||
mdbx_txn_unlock(env);
|
||||
@ -3057,7 +3057,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
|
||||
mdbx_rdt_unlock(env);
|
||||
|
||||
if (likely(env->me_flags & MDBX_ENV_TXKEY)) {
|
||||
assert(env->me_live_reader == env->me_pid);
|
||||
mdbx_assert(env, env->me_live_reader == env->me_pid);
|
||||
mdbx_thread_rthc_set(env->me_txkey, r);
|
||||
}
|
||||
}
|
||||
@ -3176,7 +3176,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
bailout:
|
||||
assert(rc != MDBX_SUCCESS);
|
||||
mdbx_tassert(txn, rc != MDBX_SUCCESS);
|
||||
mdbx_txn_end(txn, MDBX_END_SLOT | MDBX_END_FAIL_BEGIN);
|
||||
return rc;
|
||||
}
|
||||
@ -3386,7 +3386,7 @@ static void mdbx_dbis_update(MDBX_txn *txn, int keep) {
|
||||
if (ptr) {
|
||||
env->me_dbxs[i].md_name.iov_len = 0;
|
||||
mdbx_compiler_barrier();
|
||||
assert(env->me_dbflags[i] == 0);
|
||||
mdbx_assert(env, env->me_dbflags[i] == 0);
|
||||
env->me_dbiseqs[i]++;
|
||||
env->me_dbxs[i].md_name.iov_base = NULL;
|
||||
free(ptr);
|
||||
@ -3506,8 +3506,8 @@ int mdbx_txn_reset(MDBX_txn *txn) {
|
||||
/* LY: don't close DBI-handles in MDBX mode */
|
||||
int rc = mdbx_txn_end(txn, MDBX_END_RESET | MDBX_END_UPDATE);
|
||||
if (rc == MDBX_SUCCESS) {
|
||||
assert(txn->mt_signature == MDBX_MT_SIGNATURE);
|
||||
assert(txn->mt_owner == 0);
|
||||
mdbx_tassert(txn, txn->mt_signature == MDBX_MT_SIGNATURE);
|
||||
mdbx_tassert(txn, txn->mt_owner == 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@ -4360,7 +4360,7 @@ static int mdbx_page_flush(MDBX_txn *txn, pgno_t keep) {
|
||||
continue;
|
||||
}
|
||||
pgno = dl[i].pgno;
|
||||
assert(pgno >= MIN_PAGENO);
|
||||
mdbx_tassert(txn, pgno >= MIN_PAGENO);
|
||||
/* clear dirty flag */
|
||||
dp->mp_flags &= ~P_DIRTY;
|
||||
dp->mp_validator = 0 /* TODO */;
|
||||
@ -4731,7 +4731,7 @@ fail:
|
||||
* before mapping it into memory. */
|
||||
static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta,
|
||||
uint64_t *filesize) {
|
||||
assert(offsetof(MDBX_page, mp_meta) == PAGEHDRSZ);
|
||||
STATIC_ASSERT(offsetof(MDBX_page, mp_meta) == PAGEHDRSZ);
|
||||
|
||||
int rc = mdbx_filesize(env->me_fd, filesize);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
@ -5907,7 +5907,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, int lck_rc) {
|
||||
break;
|
||||
|
||||
if (lck_rc == /* lck exclusive */ MDBX_RESULT_TRUE) {
|
||||
assert(META_IS_STEADY(&meta) && !META_IS_STEADY(head));
|
||||
mdbx_assert(env, META_IS_STEADY(&meta) && !META_IS_STEADY(head));
|
||||
if (env->me_flags & MDBX_RDONLY) {
|
||||
mdbx_error("rollback needed: (from head %" PRIaTXN
|
||||
" to steady %" PRIaTXN "), but unable in read-only mode",
|
||||
@ -6041,8 +6041,8 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, int lck_rc) {
|
||||
/* Open and/or initialize the lock region for the environment. */
|
||||
static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname,
|
||||
mode_t mode) {
|
||||
assert(env->me_fd != INVALID_HANDLE_VALUE);
|
||||
assert(env->me_lfd == INVALID_HANDLE_VALUE);
|
||||
mdbx_assert(env, env->me_fd != INVALID_HANDLE_VALUE);
|
||||
mdbx_assert(env, env->me_lfd == INVALID_HANDLE_VALUE);
|
||||
|
||||
const int open_flags =
|
||||
(env->me_flags & MDBX_EXCLUSIVE) ? O_RDWR : O_RDWR | O_CREAT;
|
||||
@ -7767,7 +7767,7 @@ int mdbx_cursor_get(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
||||
mc->mc_ki[mc->mc_top] = (uint16_t)nkeys;
|
||||
return MDBX_NOTFOUND;
|
||||
}
|
||||
assert(nkeys > 0);
|
||||
mdbx_cassert(mc, nkeys > 0);
|
||||
|
||||
rc = MDBX_SUCCESS;
|
||||
if (IS_LEAF2(mp)) {
|
||||
@ -8391,7 +8391,7 @@ int mdbx_cursor_put(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
||||
if ((rc2 = mdbx_ovpage_free(mc, omp)) != MDBX_SUCCESS)
|
||||
return rc2;
|
||||
} else if (data->iov_len == olddata.iov_len) {
|
||||
assert(EVEN(key->iov_len) == EVEN(leaf->mn_ksize));
|
||||
mdbx_cassert(mc, EVEN(key->iov_len) == EVEN(leaf->mn_ksize));
|
||||
/* same size, just replace it. Note that we could
|
||||
* also reuse this node if the new data is smaller,
|
||||
* but instead we opt to shrink the node in that case. */
|
||||
@ -8407,8 +8407,8 @@ int mdbx_cursor_put(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
||||
mdbx_cassert(mc, key->iov_len < UINT16_MAX);
|
||||
leaf->mn_ksize = (uint16_t)key->iov_len;
|
||||
memcpy(NODEKEY(leaf), key->iov_base, key->iov_len);
|
||||
assert((char *)NODEKEY(leaf) + NODEDSZ(leaf) <
|
||||
(char *)(mc->mc_pg[mc->mc_top]) + env->me_psize);
|
||||
mdbx_cassert(mc, (char *)NODEKEY(leaf) + NODEDSZ(leaf) <
|
||||
(char *)(mc->mc_pg[mc->mc_top]) + env->me_psize);
|
||||
goto fix_parent;
|
||||
}
|
||||
|
||||
@ -11667,14 +11667,16 @@ static int mdbx_dbi_bind(MDBX_txn *txn, const MDBX_dbi dbi, unsigned user_flags,
|
||||
if (!txn->mt_dbxs[dbi].md_cmp || MDBX_DEBUG) {
|
||||
if (!keycmp)
|
||||
keycmp = mdbx_default_keycmp(user_flags);
|
||||
assert(!txn->mt_dbxs[dbi].md_cmp || txn->mt_dbxs[dbi].md_cmp == keycmp);
|
||||
mdbx_tassert(txn, !txn->mt_dbxs[dbi].md_cmp ||
|
||||
txn->mt_dbxs[dbi].md_cmp == keycmp);
|
||||
txn->mt_dbxs[dbi].md_cmp = keycmp;
|
||||
}
|
||||
|
||||
if (!txn->mt_dbxs[dbi].md_dcmp || MDBX_DEBUG) {
|
||||
if (!datacmp)
|
||||
datacmp = mdbx_default_datacmp(user_flags);
|
||||
assert(!txn->mt_dbxs[dbi].md_dcmp || txn->mt_dbxs[dbi].md_dcmp == datacmp);
|
||||
mdbx_tassert(txn, !txn->mt_dbxs[dbi].md_dcmp ||
|
||||
txn->mt_dbxs[dbi].md_dcmp == datacmp);
|
||||
txn->mt_dbxs[dbi].md_dcmp = datacmp;
|
||||
}
|
||||
|
||||
@ -11789,7 +11791,7 @@ int mdbx_dbi_open_ex(MDBX_txn *txn, const char *table_name, unsigned user_flags,
|
||||
if (env->me_dbflags[i] & MDBX_VALID) {
|
||||
txn->mt_dbs[i].md_flags = env->me_dbflags[i] & PERSISTENT_FLAGS;
|
||||
txn->mt_dbflags[i] = DB_VALID | DB_USRVALID | DB_STALE;
|
||||
assert(txn->mt_dbxs[i].md_cmp != NULL);
|
||||
mdbx_tassert(txn, txn->mt_dbxs[i].md_cmp != NULL);
|
||||
}
|
||||
}
|
||||
txn->mt_numdbs = env->me_numdbs;
|
||||
@ -11818,7 +11820,7 @@ int mdbx_dbi_open_ex(MDBX_txn *txn, const char *table_name, unsigned user_flags,
|
||||
MDBX_db db_dummy;
|
||||
if (unlikely(rc)) {
|
||||
/* MDBX_NOTFOUND and MDBX_CREATE: Create new DB */
|
||||
assert(rc == MDBX_NOTFOUND);
|
||||
mdbx_tassert(txn, rc == MDBX_NOTFOUND);
|
||||
memset(&db_dummy, 0, sizeof(db_dummy));
|
||||
db_dummy.md_root = P_INVALID;
|
||||
db_dummy.md_flags = user_flags & PERSISTENT_FLAGS;
|
||||
@ -11841,7 +11843,7 @@ int mdbx_dbi_open_ex(MDBX_txn *txn, const char *table_name, unsigned user_flags,
|
||||
env->me_dbflags[slot] = 0;
|
||||
rc = mdbx_dbi_bind(txn, slot, user_flags, keycmp, datacmp);
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
assert((dbflag & DB_CREAT) == 0);
|
||||
mdbx_tassert(txn, (dbflag & DB_CREAT) == 0);
|
||||
bailout:
|
||||
free(namedup);
|
||||
} else {
|
||||
@ -12257,7 +12259,7 @@ int __cold mdbx_reader_check(MDBX_env *env, int *dead) {
|
||||
* MDBX_SUCCESS - done
|
||||
* Otherwise errcode. */
|
||||
int __cold mdbx_reader_check0(MDBX_env *env, int rdt_locked, int *dead) {
|
||||
assert(rdt_locked >= 0);
|
||||
mdbx_assert(env, rdt_locked >= 0);
|
||||
|
||||
if (unlikely(env->me_pid != mdbx_getpid())) {
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
@ -13173,7 +13175,7 @@ int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result,
|
||||
if (unlikely(new < increment))
|
||||
return MDBX_RESULT_TRUE;
|
||||
|
||||
assert(new > dbs->md_seq);
|
||||
mdbx_tassert(txn, new > dbs->md_seq);
|
||||
dbs->md_seq = new;
|
||||
txn->mt_flags |= MDBX_TXN_DIRTY;
|
||||
txn->mt_dbflags[dbi] |= DB_DIRTY;
|
||||
|
Loading…
x
Reference in New Issue
Block a user