From 538d2e4d62940b4f211f84abc3fbcdde643656db Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 5 Sep 2020 11:57:34 +0300 Subject: [PATCH 1/7] mdbx: skip update meta-geo in read-only mode. Change-Id: I1c9610920ad87dc8110e8d03038ef385220000c8 --- src/core.c | 65 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/src/core.c b/src/core.c index 00716db5..3ff00df9 100644 --- a/src/core.c +++ b/src/core.c @@ -9709,8 +9709,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) { env->me_dxb_mmap.current); return MDBX_PROBLEM; } - if (env->me_dxb_mmap.current != env->me_dbgeo.now && - (env->me_flags & MDBX_RDONLY) == 0) { + if (env->me_dxb_mmap.current != env->me_dbgeo.now) { meta.mm_geo.now = bytes2pgno(env, env->me_dxb_mmap.current); mdbx_verbose("update meta-geo to filesize %" PRIuPTR " bytes, %" PRIaPGNO " pages", @@ -9718,32 +9717,44 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) { } if (memcmp(&meta.mm_geo, &head->mm_geo, sizeof(meta.mm_geo))) { - const txnid_t txnid = mdbx_meta_txnid_stable(env, head); - const txnid_t next_txnid = safe64_txnid_next(txnid); - mdbx_verbose("updating meta.geo: " - "from l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO - "/s%u-g%u (txn#%" PRIaTXN "), " - "to l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO - "/s%u-g%u (txn#%" PRIaTXN ")", - head->mm_geo.lower, head->mm_geo.now, head->mm_geo.upper, - head->mm_geo.shrink, head->mm_geo.grow, txnid, - meta.mm_geo.lower, meta.mm_geo.now, meta.mm_geo.upper, - meta.mm_geo.shrink, meta.mm_geo.grow, next_txnid); + if (env->me_flags & MDBX_RDONLY) { + mdbx_warning( + "skipped update meta.geo in read-only mode: from l%" PRIaPGNO + "-n%" PRIaPGNO "-u%" PRIaPGNO "/s%u-g%u, to l%" PRIaPGNO + "-n%" PRIaPGNO "-u%" PRIaPGNO "/s%u-g%u", + head->mm_geo.lower, head->mm_geo.now, head->mm_geo.upper, + head->mm_geo.shrink, head->mm_geo.grow, meta.mm_geo.lower, + meta.mm_geo.now, meta.mm_geo.upper, meta.mm_geo.shrink, + meta.mm_geo.grow); + } else { + const txnid_t txnid = mdbx_meta_txnid_stable(env, head); + const txnid_t next_txnid = safe64_txnid_next(txnid); + mdbx_notice("updating meta.geo: " + "from l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO + "/s%u-g%u (txn#%" PRIaTXN "), " + "to l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO + "/s%u-g%u (txn#%" PRIaTXN ")", + head->mm_geo.lower, head->mm_geo.now, head->mm_geo.upper, + head->mm_geo.shrink, head->mm_geo.grow, txnid, + meta.mm_geo.lower, meta.mm_geo.now, meta.mm_geo.upper, + meta.mm_geo.shrink, meta.mm_geo.grow, next_txnid); - mdbx_ensure(env, mdbx_meta_eq(env, &meta, head)); - mdbx_meta_set_txnid(env, &meta, next_txnid); - err = mdbx_sync_locked(env, env->me_flags | MDBX_SHRINK_ALLOWED, &meta); - if (err) { - mdbx_error("error %d, while updating meta.geo: " - "from l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO - "/s%u-g%u (txn#%" PRIaTXN "), " - "to l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO - "/s%u-g%u (txn#%" PRIaTXN ")", - err, head->mm_geo.lower, head->mm_geo.now, - head->mm_geo.upper, head->mm_geo.shrink, head->mm_geo.grow, - txnid, meta.mm_geo.lower, meta.mm_geo.now, meta.mm_geo.upper, - meta.mm_geo.shrink, meta.mm_geo.grow, next_txnid); - return err; + mdbx_ensure(env, mdbx_meta_eq(env, &meta, head)); + mdbx_meta_set_txnid(env, &meta, next_txnid); + err = mdbx_sync_locked(env, env->me_flags | MDBX_SHRINK_ALLOWED, &meta); + if (err) { + mdbx_error("error %d, while updating meta.geo: " + "from l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO + "/s%u-g%u (txn#%" PRIaTXN "), " + "to l%" PRIaPGNO "-n%" PRIaPGNO "-u%" PRIaPGNO + "/s%u-g%u (txn#%" PRIaTXN ")", + err, head->mm_geo.lower, head->mm_geo.now, + head->mm_geo.upper, head->mm_geo.shrink, head->mm_geo.grow, + txnid, meta.mm_geo.lower, meta.mm_geo.now, + meta.mm_geo.upper, meta.mm_geo.shrink, meta.mm_geo.grow, + next_txnid); + return err; + } } } } From 9249297d31fcb7ddf26ec48c4e4bdc49867011ae Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 5 Sep 2020 12:16:00 +0300 Subject: [PATCH 2/7] mdbx: fix MSVC compiler version requirements. Change-Id: Iabf7ab571ca887bd7995ae6293d3c70bb85a947b --- src/internals.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internals.h b/src/internals.h index 094f6571..06233526 100644 --- a/src/internals.h +++ b/src/internals.h @@ -64,8 +64,8 @@ #endif #ifdef _MSC_VER -# if _MSC_VER < 1400 -# error "Microsoft Visual C++ 8.0 (Visual Studio 2005) or later version is required" +# if _MSC_FULL_VER < 190024234 +# error "At least \"Microsoft C/C++ Compiler\" version 19.00.24234 (Visual Studio 2015 Update 3) is required." # endif # ifndef _CRT_SECURE_NO_WARNINGS # define _CRT_SECURE_NO_WARNINGS From f393ae1c510165383b7eead6d2766f55c71d83e5 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 7 Sep 2020 12:08:11 +0300 Subject: [PATCH 3/7] mdbx-doc: fix typos. Change-Id: Iff6be053a796f57cc89e29e016a52b7654953cda --- mdbx.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mdbx.h b/mdbx.h index 49d01991..8f86694b 100644 --- a/mdbx.h +++ b/mdbx.h @@ -2172,7 +2172,7 @@ LIBMDBX_API int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *fd); * \param [in] env An environment handle returned * by \ref mdbx_env_create() * - * \param [in] size_lower The lower bound of database sive in bytes. + * \param [in] size_lower The lower bound of database size in bytes. * Zero value means "minimal acceptable", * and negative means "keep current or use default". * @@ -2182,16 +2182,16 @@ LIBMDBX_API int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *fd); * it is recommended always pass -1 in this argument * except some special cases. * - * \param [in] size_upper The upper bound of database sive in bytes. + * \param [in] size_upper The upper bound of database size in bytes. * Zero value means "minimal acceptable", * and negative means "keep current or use default". * It is recommended to avoid change upper bound while * database is used by other processes or threaded * (i.e. just pass -1 in this argument except absolutely - * necessity). Otherwise you must be ready for + * necessary). Otherwise you must be ready for * \ref MDBX_UNABLE_EXTEND_MAPSIZE error(s), unexpected * pauses during remapping and/or system errors like - * "addtress busy", and so on. In other words, there + * "address busy", and so on. In other words, there * is no way to handle a growth of the upper bound * robustly because there may be a lack of appropriate * system resources (which are extremely volatile in @@ -2209,7 +2209,7 @@ LIBMDBX_API int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *fd); * \param [in] pagesize The database page size for new database * creation or -1 otherwise. Must be power of 2 * in the range between \ref MDBX_MIN_PAGESIZE and - * \ref MDBX_MAX_PAGESIZE. Zero value means + * \ref MDBX_MAX_PAGESIZE. Zero value means * "minimal acceptable", and negative means * "keep current or use default". * From 64e35a1e4451fbf361f2bb4f025b782d1f5909bd Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 7 Sep 2020 12:30:50 +0300 Subject: [PATCH 4/7] mdbx-doc: add and describe MDBX_SYNC_DURABLE. Change-Id: Id51e8c764a073e7c502d8d0b95ace0e14510e85b --- mdbx.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mdbx.h b/mdbx.h index 8f86694b..8bf0eac5 100644 --- a/mdbx.h +++ b/mdbx.h @@ -972,13 +972,25 @@ enum MDBX_env_flags_t { * be written to disk, while the itself B-tree not yet. In that case, the * database will be corrupted! * - * \see MDBX_NOMETASYNC \see MDBX_SAFE_NOSYNC \see MDBX_UTTERLY_NOSYNC + * \see MDBX_SYNC_DURABLE \see MDBX_NOMETASYNC \see MDBX_SAFE_NOSYNC + * \see MDBX_UTTERLY_NOSYNC * * @{ */ + /** Default robust and durable sync mode. + * + * Metadata is written and flushed to disk after a data is written and + * flushed, which guarantees the integrity of the database in the event + * of a crash at any time. + * + * \attention Please do not use other modes until you have studied all the + * details and are sure. Otherwise, you may lose your users' data, as happens + * in [Miranda NG](https://www.miranda-ng.org/) messenger. */ + MDBX_SYNC_DURABLE = 0, + /** Don't sync the meta-page after commit. * - * Flush system buffers to disk only once per transaction, omit the + * Flush system buffers to disk only once per transaction commit, omit the * metadata flush. Defer that until the system flushes files to disk, * or next non-\ref MDBX_RDONLY commit or \ref mdbx_env_sync(). Depending on * the platform and hardware, with \ref MDBX_NOMETASYNC you may get a doubling From 7272403cfd2421801c5eeab17e3df66445637a5d Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 7 Sep 2020 15:21:21 +0300 Subject: [PATCH 5/7] mdbx-doc: simplify Doxygen TOC. Change-Id: I9f433628433fd8deea6c4128c4e1452bcadfba49 --- GNUmakefile | 2 +- docs/_toc.md | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 6b8222b3..a46acbe5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -268,7 +268,7 @@ docs/intro.md: docs/_preface.md docs/__characteristics.md docs/__improvements.md cat $^ | sed 's/^Performance comparison$$/Performance comparison {#performance}/' > $@ docs/usage.md: docs/__usage.md docs/_starting.md docs/__bindings.md - echo -e "\\page usage Usage\n\\section getting Getting the libmdbx" | cat - $^ | sed 's/^Bindings$$/Bindings {#bindings}/' > $@ + echo -e "\\page usage Usage\n\\section getting Building & Embedding" | cat - $^ | sed 's/^Bindings$$/Bindings {#bindings}/' > $@ doxygen: docs/Doxyfile docs/overall.md docs/intro.md docs/usage.md mdbx.h src/options.h ChangeLog.md AUTHORS LICENSE rm -rf docs/html && cp mdbx.h src/options.h ChangeLog.md docs/ && (cd docs && doxygen Doxyfile) && cp AUTHORS LICENSE docs/html/ diff --git a/docs/_toc.md b/docs/_toc.md index 60e7748b..2e06e62b 100644 --- a/docs/_toc.md +++ b/docs/_toc.md @@ -8,30 +8,11 @@ each of which is divided into several sections. 1. The \ref intro - \ref characteristics - - Preface - - Features - - Limitations - - Gotchas - - Comparison with other databases - \ref restrictions - \ref performance - - Integral performance - - Read Scalability - - Sync-write mode - - Lazy-write mode - - Async-write mode - - Cost comparison 2. \ref usage - \ref getting - - Embedding - - Building - \ref starting - - Opening - - Cursors - - Threads and processes - - Transactions - - Duplicate keys aka Multi-values - - Cleaning up - \ref bindings 3. The `C` API manual: From c17ab74521f9c1f5bcf522e0ecf998945096cfd2 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 7 Sep 2020 16:15:22 +0300 Subject: [PATCH 6/7] mdbx: add link to documentation & C++ API. Change-Id: Ib61ab37b9083ef088920cba8e331f71776b191cd --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index dcb6dbbe..236f328f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ libmdbx ======== +> Please refer to the online [documentation](https://erthink.github.io/libmdbx/) +> with [`C` API description](https://erthink.github.io/libmdbx/group__c__api.html) +> and pay attention to the preliminary [`C++` API](https://github.com/erthink/libmdbx/blob/c%2B%2B/mdbx.h%2B%2B). +> Feedback and suggestions are welcome! + _libmdbx_ is an extremely fast, compact, powerful, embedded, transactional [key-value database](https://en.wikipedia.org/wiki/Key-value_database), From 3fb12d1f5fc742ac073ef84ee929e9150096c9d3 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Tue, 8 Sep 2020 20:05:23 +0300 Subject: [PATCH 7/7] mdbx: adds explicit note about the telegram group. Change-Id: I7c48575c6a06822539c9abdeae334536266543e3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 236f328f..c17d15c8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ libmdbx > Please refer to the online [documentation](https://erthink.github.io/libmdbx/) > with [`C` API description](https://erthink.github.io/libmdbx/group__c__api.html) > and pay attention to the preliminary [`C++` API](https://github.com/erthink/libmdbx/blob/c%2B%2B/mdbx.h%2B%2B). -> Feedback and suggestions are welcome! +> Questions, feedback and suggestions are welcome to the [Telergam' group](https://t.me/libmdbx). _libmdbx_ is an extremely fast, compact, powerful, embedded,