From 634efbe34bdd26c262378cbc857e70f7c0d39142 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Tue, 12 Jun 2018 13:18:17 +0300 Subject: [PATCH 1/4] mdbx: don't block close_env() if other write-txn running. Change-Id: I1d19afcc245578681b8bc3ee3966ac38bc596ec4 --- src/mdbx.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index 2ac91e9e..be93a46c 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -2711,7 +2711,7 @@ fail: return rc; } -int mdbx_env_sync(MDBX_env *env, int force) { +static int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock) { if (unlikely(!env)) return MDBX_EINVAL; @@ -2729,7 +2729,7 @@ int mdbx_env_sync(MDBX_env *env, int force) { (!env->me_txn0 || env->me_txn0->mt_owner != mdbx_thread_self()); if (outside_txn) { - int rc = mdbx_txn_lock(env, false); + int rc = mdbx_txn_lock(env, nonblock); if (unlikely(rc != MDBX_SUCCESS)) return rc; } @@ -2758,7 +2758,7 @@ int mdbx_env_sync(MDBX_env *env, int force) { if (unlikely(rc != MDBX_SUCCESS)) return rc; - rc = mdbx_txn_lock(env, false); + rc = mdbx_txn_lock(env, nonblock); if (unlikely(rc != MDBX_SUCCESS)) return rc; @@ -2785,6 +2785,10 @@ int mdbx_env_sync(MDBX_env *env, int force) { return MDBX_SUCCESS; } +int mdbx_env_sync(MDBX_env *env, int force) { + return mdbx_env_sync_ex(env, force, false); +} + /* Back up parent txn's cursors, then grab the originals for tracking */ static int mdbx_cursor_shadow(MDBX_txn *src, MDBX_txn *dst) { MDBX_cursor *mc, *bk; @@ -5940,8 +5944,10 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) { if (env->me_txn0 && env->me_txn0->mt_owner && env->me_txn0->mt_owner != mdbx_thread_self()) return MDBX_BUSY; - if (!dont_sync) - rc = mdbx_env_sync(env, true); + if (!dont_sync) { + rc = mdbx_env_sync_ex(env, true, true); + rc = (rc == MDBX_BUSY) ? MDBX_SUCCESS : rc; + } } VALGRIND_DESTROY_MEMPOOL(env); @@ -5968,7 +5974,7 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) { return rc; } -int mdbx_env_close(MDBX_env *env) { return mdbx_env_close_ex(env, 0); } +int mdbx_env_close(MDBX_env *env) { return mdbx_env_close_ex(env, false); } /* Compare two items pointing at aligned unsigned int's. */ static int __hot mdbx_cmp_int_ai(const MDBX_val *a, const MDBX_val *b) { @@ -11473,7 +11479,7 @@ int __cold mdbx_env_set_syncbytes(MDBX_env *env, size_t bytes) { return MDBX_EBADSIGN; env->me_sync_threshold = bytes; - return env->me_map ? mdbx_env_sync(env, 0) : MDBX_SUCCESS; + return env->me_map ? mdbx_env_sync(env, false) : MDBX_SUCCESS; } int __cold mdbx_env_set_oomfunc(MDBX_env *env, MDBX_oom_func *oomfunc) { From efdcbd8c356fbf619c9e7968e95a4d8629a180f8 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 13 Jun 2018 02:43:44 +0300 Subject: [PATCH 2/4] mdbx: disable non-blocking DB-close under Windows. Change-Id: If6579467132439b6b627e756f67f6bd35fed8b4f --- src/mdbx.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mdbx.c b/src/mdbx.c index be93a46c..82ca0aad 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -5945,8 +5945,19 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) { env->me_txn0->mt_owner != mdbx_thread_self()) return MDBX_BUSY; if (!dont_sync) { +#if defined(_WIN32) || defined(_WIN64) + /* On windows, without blocking is impossible to determine whether another + * process is running a writing transaction or not. + * Because in the "owner died" condition kernel don't release + * file lock immediately. */ + rc = mdbx_env_sync_ex(env, true, false); +#else rc = mdbx_env_sync_ex(env, true, true); - rc = (rc == MDBX_BUSY) ? MDBX_SUCCESS : rc; + rc = (rc == MDBX_BUSY || rc == EAGAIN || rc == EACCES || rc == EBUSY || + rc == EWOULDBLOCK) + ? MDBX_SUCCESS + : rc; +#endif } } From 2f983b281d3390e70f50c5996b7361f3aab9ef2f Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 13 Jun 2018 11:37:56 +0300 Subject: [PATCH 3/4] mdbx: drop MDBX_DEVEL. Change-Id: I5fc1a240e7909b8ecaf2ef19a83a9e59ea5609ba --- src/bits.h | 13 +++---------- src/mdbx.c | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/bits.h b/src/bits.h index ea8e2731..4c92e4af 100644 --- a/src/bits.h +++ b/src/bits.h @@ -23,11 +23,6 @@ # undef NDEBUG #endif -/* Features under development */ -#ifndef MDBX_DEVEL -# define MDBX_DEVEL 0 -#endif - /*----------------------------------------------------------------------------*/ /* Should be defined before any includes */ @@ -144,9 +139,9 @@ #define MDBX_MAGIC UINT64_C(/* 56-bit prime */ 0x59659DBDEF4C11) /* The version number for a database's datafile format. */ -#define MDBX_DATA_VERSION ((MDBX_DEVEL) ? 255 : 2) +#define MDBX_DATA_VERSION 2 /* The version number for a database's lockfile format. */ -#define MDBX_LOCK_VERSION ((MDBX_DEVEL) ? 255 : 2) +#define MDBX_LOCK_VERSION 2 /* handle for the DB used to track free pages. */ #define FREE_DBI 0 @@ -171,9 +166,7 @@ typedef uint32_t pgno_t; /* A transaction ID. */ typedef uint64_t txnid_t; #define PRIaTXN PRIi64 -#if MDBX_DEVEL -#define MIN_TXNID (UINT64_MAX - UINT32_MAX) -#elif MDBX_DEBUG +#if MDBX_DEBUG #define MIN_TXNID UINT64_C(0x100000000) #else #define MIN_TXNID UINT64_C(1) diff --git a/src/mdbx.c b/src/mdbx.c index 82ca0aad..e4c5248c 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -4342,8 +4342,8 @@ static int __cold mdbx_read_header(MDBX_env *env, MDBX_meta *meta, } if (page.mp_meta.mm_magic_and_version != MDBX_DATA_MAGIC) { - mdbx_error("meta[%u] has invalid magic/version MDBX_DEVEL=%d", - meta_number, MDBX_DEVEL); + mdbx_error("meta[%u] has invalid magic/version %" PRIx64, meta_number, + page.mp_meta.mm_magic_and_version); return ((page.mp_meta.mm_magic_and_version >> 8) != MDBX_MAGIC) ? MDBX_INVALID : MDBX_VERSION_MISMATCH; From b6e605b8da13694a34b64e609a09262994fea7eb Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Thu, 14 Jun 2018 13:53:05 +0300 Subject: [PATCH 4/4] mdbx: bump version to v0.1.5 --- appveyor.yml | 2 +- src/version.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 032a38c5..ce817b23 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.1.4.{build} +version: 0.1.5.{build} environment: matrix: diff --git a/src/version.c b/src/version.c index 3272ff61..aeb15bed 100644 --- a/src/version.c +++ b/src/version.c @@ -18,7 +18,7 @@ #error "API version mismatch!" #endif -#define MDBX_VERSION_RELEASE 4 +#define MDBX_VERSION_RELEASE 5 #define MDBX_VERSION_REVISION 1 /*LIBMDBX_EXPORTS*/ const mdbx_version_info mdbx_version = {