mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +08:00
mdbx: don't block close_env() if other write-txn running.
Change-Id: I1d19afcc245578681b8bc3ee3966ac38bc596ec4
This commit is contained in:
parent
fdc248384e
commit
634efbe34b
20
src/mdbx.c
20
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user