diff --git a/src/core.c b/src/core.c index 25edb1be..6be438da 100644 --- a/src/core.c +++ b/src/core.c @@ -10057,9 +10057,6 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) { ts_3 = latency ? mdbx_osal_monotime() : 0; if (likely(rc == MDBX_SUCCESS)) { - if (txn->mt_dbs[MAIN_DBI].md_flags & DBI_DIRTY) - txn->mt_dbs[MAIN_DBI].md_mod_txnid = txn->mt_txnid; - txn->mt_dbs[FREE_DBI].md_mod_txnid = txn->mt_txnid; MDBX_meta meta, *head = mdbx_meta_head(env); memcpy(meta.mm_magic_and_version, head->mm_magic_and_version, 8); @@ -10072,7 +10069,15 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) { meta.mm_geo = txn->mt_geo; meta.mm_dbs[FREE_DBI] = txn->mt_dbs[FREE_DBI]; + meta.mm_dbs[FREE_DBI].md_mod_txnid = + (txn->mt_dbistate[FREE_DBI] & DBI_DIRTY) + ? txn->mt_txnid + : txn->mt_dbs[FREE_DBI].md_mod_txnid; meta.mm_dbs[MAIN_DBI] = txn->mt_dbs[MAIN_DBI]; + meta.mm_dbs[MAIN_DBI].md_mod_txnid = + (txn->mt_dbistate[MAIN_DBI] & DBI_DIRTY) + ? txn->mt_txnid + : txn->mt_dbs[MAIN_DBI].md_mod_txnid; meta.mm_canary = txn->mt_canary; mdbx_meta_set_txnid(env, &meta, txn->mt_txnid); @@ -13150,7 +13155,7 @@ dirty: } if (unlikely(ret.page->mp_txnid > front) && - (ret.page->mp_txnid > txn->mt_front || front < txn->mt_txnid)) { + unlikely(ret.page->mp_txnid > txn->mt_front || front < txn->mt_txnid)) { bad_page(ret.page, "invalid page txnid (%" PRIaTXN ") for %s' txnid (%" PRIaTXN ")\n", ret.page->mp_txnid, @@ -13404,11 +13409,13 @@ __hot static int mdbx_page_search(MDBX_cursor *mc, const MDBX_val *key, : mc->mc_txn->mt_txnid; MDBX_txn *scan = mc->mc_txn; do - if (scan->mt_dbistate[mc->mc_dbi] & DBI_DIRTY) { + if ((scan->mt_flags & MDBX_TXN_DIRTY) && + (mc->mc_dbi == MAIN_DBI || + (scan->mt_dbistate[mc->mc_dbi] & DBI_DIRTY))) { pp_txnid = scan->mt_front; break; } - while ((scan = scan->mt_parent) != nullptr); + while (unlikely((scan = scan->mt_parent) != nullptr)); if (unlikely((rc = mdbx_page_get(mc, root, &mc->mc_pg[0], pp_txnid) != 0))) return rc; }