From 6e2a1ebfbd77447d668d48b7b3dec2730cbb806c 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, 8 Jul 2022 01:08:54 +0300 Subject: [PATCH] mdbx: minor fix `meta_checktxnid()` to avoid assertion in debug mode. --- ChangeLog.md | 1 + src/core.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 1328b809..ca0e5bf4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -18,6 +18,7 @@ Minors: - Minor fixes Doxygen references, comments, descriptions, etc. - Fixed copy&paste typo inside `meta_checktxnid()`. + - Minor fix `meta_checktxnid()` to avoid assertion in debug mode. ------------------------------------------------------------------------------- diff --git a/src/core.c b/src/core.c index 77a18cd8..787cb18f 100644 --- a/src/core.c +++ b/src/core.c @@ -7724,7 +7724,7 @@ __cold int mdbx_thread_unregister(const MDBX_env *env) { /* check against todo4recovery://erased_by_github/libmdbx/issues/269 */ static bool meta_checktxnid(const MDBX_env *env, const MDBX_meta *meta, bool report) { - const txnid_t meta_txnid = constmeta_txnid(env, meta); + const txnid_t head_txnid = meta_txnid(env, meta); const txnid_t freedb_mod_txnid = meta->mm_dbs[FREE_DBI].md_mod_txnid; const txnid_t maindb_mod_txnid = meta->mm_dbs[MAIN_DBI].md_mod_txnid; @@ -7741,25 +7741,25 @@ static bool meta_checktxnid(const MDBX_env *env, const MDBX_meta *meta, const uint64_t magic_and_version = unaligned_peek_u64(4, &meta->mm_magic_and_version); bool ok = true; - if (unlikely(meta_txnid < freedb_mod_txnid || + if (unlikely(!head_txnid || head_txnid < freedb_mod_txnid || (!freedb_mod_txnid && freedb_root && likely(magic_and_version == MDBX_DATA_MAGIC)))) { if (report) mdbx_warning( "catch invalid %sdb.mod_txnid %" PRIaTXN " for meta_txnid %" PRIaTXN " %s", - "free", freedb_mod_txnid, meta_txnid, + "free", freedb_mod_txnid, head_txnid, "(workaround for incoherent flaw of unified page/buffer cache)"); ok = false; } - if (unlikely(meta_txnid < maindb_mod_txnid || + if (unlikely(head_txnid < maindb_mod_txnid || (!maindb_mod_txnid && maindb_root && likely(magic_and_version == MDBX_DATA_MAGIC)))) { if (report) mdbx_warning( "catch invalid %sdb.mod_txnid %" PRIaTXN " for meta_txnid %" PRIaTXN " %s", - "main", maindb_mod_txnid, meta_txnid, + "main", maindb_mod_txnid, head_txnid, "(workaround for incoherent flaw of unified page/buffer cache)"); ok = false; } @@ -7800,7 +7800,7 @@ static bool meta_checktxnid(const MDBX_env *env, const MDBX_meta *meta, * for todo4recovery://erased_by_github/libmdbx/issues/269 */ static int meta_waittxnid(const MDBX_env *env, const MDBX_meta *meta, uint64_t *timestamp) { - if (likely(meta_checktxnid(env, (const MDBX_meta *)meta, !*timestamp))) + if (likely(meta_checktxnid(env, meta, !*timestamp))) return MDBX_SUCCESS; if (!*timestamp)