From 110cf09cf80e38e7131806ca6864de44aa8347a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Fri, 11 Feb 2022 15:12:31 +0300 Subject: [PATCH] mdbx: simplify core-dbs update inside `mdbx_txn_commit_ex()`. --- src/core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/core.c b/src/core.c index 620540ec..cdd88e56 100644 --- a/src/core.c +++ b/src/core.c @@ -10157,9 +10157,7 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) { /* Update parent's DBs array */ memcpy(parent->mt_dbs, txn->mt_dbs, txn->mt_numdbs * sizeof(MDBX_db)); parent->mt_numdbs = txn->mt_numdbs; - parent->mt_dbistate[FREE_DBI] = txn->mt_dbistate[FREE_DBI]; - parent->mt_dbistate[MAIN_DBI] = txn->mt_dbistate[MAIN_DBI]; - for (unsigned i = CORE_DBS; i < txn->mt_numdbs; i++) { + for (unsigned i = 0; i < txn->mt_numdbs; i++) { /* preserve parent's status */ const uint8_t state = txn->mt_dbistate[i] | @@ -10254,6 +10252,14 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) { if (unlikely(rc != MDBX_SUCCESS)) goto fail; + txn->mt_dbs[FREE_DBI].md_mod_txnid = (txn->mt_dbistate[FREE_DBI] & DBI_DIRTY) + ? txn->mt_txnid + : txn->mt_dbs[FREE_DBI].md_mod_txnid; + + txn->mt_dbs[MAIN_DBI].md_mod_txnid = (txn->mt_dbistate[MAIN_DBI] & DBI_DIRTY) + ? txn->mt_txnid + : txn->mt_dbs[MAIN_DBI].md_mod_txnid; + ts_2 = latency ? mdbx_osal_monotime() : 0; if (mdbx_audit_enabled()) { rc = mdbx_audit_ex(txn, MDBX_PNL_SIZE(txn->tw.retired_pages), true); @@ -10273,7 +10279,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)) { - const MDBX_meta *head = constmeta_prefer_last(env); MDBX_meta meta; memcpy(meta.mm_magic_and_version, head->mm_magic_and_version, 8); @@ -10283,18 +10288,9 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) { unaligned_poke_u64(4, meta.mm_pages_retired, unaligned_peek_u64(4, head->mm_pages_retired) + MDBX_PNL_SIZE(txn->tw.retired_pages)); - 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; meta_set_txnid(env, &meta, txn->mt_txnid);