From 0b5cdee6eff3a1147b21eee411c193437f6a624a 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, 1 Jul 2022 11:37:13 +0300 Subject: [PATCH 1/6] mdbx: fix `mdbx_env_compact()` hand when DB is corrupted or the volume of an output pages aliquot to `MDBX_ENVCOPY_WRITEBUF`. --- src/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core.c b/src/core.c index fd367c86..826b0d72 100644 --- a/src/core.c +++ b/src/core.c @@ -19557,7 +19557,8 @@ __cold static int mdbx_env_compact(MDBX_env *env, MDBX_txn *read_txn, } if (rc == MDBX_SUCCESS) rc = mdbx_env_cwalk(&ctx, &root, 0); - mdbx_env_cthr_toggle(&ctx); + if (ctx.mc_wlen[ctx.mc_head & 1]) + mdbx_env_cthr_toggle(&ctx); mdbx_env_cthr_toggle(&ctx); thread_err = mdbx_thread_join(thread); mdbx_assert(env, (ctx.mc_tail == ctx.mc_head && From 3cc7f105a5aad9f43a9f9dd8139193d5aff21c16 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: Thu, 7 Jul 2022 17:54:13 +0300 Subject: [PATCH 2/6] mdbx: fix copy&paste typo inside `meta_checktxnid()`. --- src/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core.c b/src/core.c index 826b0d72..77a18cd8 100644 --- a/src/core.c +++ b/src/core.c @@ -7746,7 +7746,7 @@ static bool meta_checktxnid(const MDBX_env *env, const MDBX_meta *meta, likely(magic_and_version == MDBX_DATA_MAGIC)))) { if (report) mdbx_warning( - "catch invalid %sdb_mod_txnid %" PRIaTXN " for meta_txnid %" PRIaTXN + "catch invalid %sdb.mod_txnid %" PRIaTXN " for meta_txnid %" PRIaTXN " %s", "free", freedb_mod_txnid, meta_txnid, "(workaround for incoherent flaw of unified page/buffer cache)"); @@ -7757,7 +7757,7 @@ static bool meta_checktxnid(const MDBX_env *env, const MDBX_meta *meta, likely(magic_and_version == MDBX_DATA_MAGIC)))) { if (report) mdbx_warning( - "catch invalid %sdb_mod_txnid %" PRIaTXN " for meta_txnid %" PRIaTXN + "catch invalid %sdb.mod_txnid %" PRIaTXN " for meta_txnid %" PRIaTXN " %s", "main", maindb_mod_txnid, meta_txnid, "(workaround for incoherent flaw of unified page/buffer cache)"); @@ -7772,8 +7772,8 @@ static bool meta_checktxnid(const MDBX_env *env, const MDBX_meta *meta, if (report) mdbx_warning( "catch invalid root_page_txnid %" PRIaTXN - " for %sdb_mod_txnid %" PRIaTXN " %s", - root_txnid, "free", maindb_mod_txnid, + " for %sdb.mod_txnid %" PRIaTXN " %s", + root_txnid, "free", freedb_mod_txnid, "(workaround for incoherent flaw of unified page/buffer cache)"); ok = false; } @@ -7787,7 +7787,7 @@ static bool meta_checktxnid(const MDBX_env *env, const MDBX_meta *meta, if (report) mdbx_warning( "catch invalid root_page_txnid %" PRIaTXN - " for %sdb_mod_txnid %" PRIaTXN " %s", + " for %sdb.mod_txnid %" PRIaTXN " %s", root_txnid, "main", maindb_mod_txnid, "(workaround for incoherent flaw of unified page/buffer cache)"); ok = false; From f17bd06116e234bfae0bbab0d9867b1ffc7fe458 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 00:27:19 +0300 Subject: [PATCH 3/6] mdbx: update ChangeLog. --- ChangeLog.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 945b2eaa..1328b809 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,8 +1,32 @@ ChangeLog --------- +## v0.11.9 (scheduled to 2022-08-02) + +The stable bugfix release. + +New: + + - Ability to customise `MDBX_LOCK_SUFFIX`, `MDBX_DATANAME`, `MDBX_LOCKNAME` just by predefine ones during build. + +Fixes: + + - Fixed hang copy-with-compactification of a corrupted DB + or in case the volume of output pages is a multiple of `MDBX_ENVCOPY_WRITEBUF`. + +Minors: + + - Minor fixes Doxygen references, comments, descriptions, etc. + - Fixed copy&paste typo inside `meta_checktxnid()`. + + +------------------------------------------------------------------------------- + + ## v0.11.8 at 2022-06-12 +The stable release with an important fixes and workaround for the critical macOS thread-local-storage issue. + Acknowledgements: - [Masatoshi Fukunaga](https://github.com/mah0x211) for [Lua bindings](https://github.com/mah0x211/lua-libmdbx). @@ -51,6 +75,7 @@ Minors: ------------------------------------------------------------------------------- + ## v0.11.7 at 2022-04-22 The stable risen release after the Github's intentional malicious disaster. 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 4/6] 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) From c499f2bb36a0b15e4034b05902d5bb5a45d13837 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: Mon, 27 Jun 2022 13:53:22 +0300 Subject: [PATCH 5/6] mdbx: minor fix `EINVAL` from `mdbx_env_set_geometry()`. Silently growth `size_lower` to the `MIN_PAGENO` instead of returning `MDBX_EINVAL`. --- src/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core.c b/src/core.c index 787cb18f..2a123239 100644 --- a/src/core.c +++ b/src/core.c @@ -11796,8 +11796,13 @@ mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now, } if ((uint64_t)size_lower / pagesize < MIN_PAGENO) { - rc = MDBX_EINVAL; - goto bailout; + size_lower = pagesize * MIN_PAGENO; + if (unlikely(size_lower > size_upper)) { + rc = MDBX_EINVAL; + goto bailout; + } + if (size_now < size_lower) + size_now = size_lower; } if (unlikely((size_t)size_upper > MAX_MAPSIZE || From 61825e9bc8070d407726ae2d9feea5462906d66b 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:17:21 +0300 Subject: [PATCH 6/6] mdbx: update ChangeLog for v0.11.9 --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index ca0e5bf4..979ca3f1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -19,6 +19,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. + - Minor fix `mdbx_env_set_geometry()` to avoid returning `EINVAL` in particular rare cases. -------------------------------------------------------------------------------