From d4e67d14ce2517d298c23d1f9e8afa2174d57761 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, 3 Nov 2022 17:23:32 +0300 Subject: [PATCH] =?UTF-8?q?mdbx:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=BE=D0=B6=D0=B8?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20`MDBX=5FBUSY`=20?= =?UTF-8?q?=D0=B8=D0=B7=20`mdbx=5Fenv=5Fset=5Foption()`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/core.c b/src/core.c index a7854b7f..80c320bf 100644 --- a/src/core.c +++ b/src/core.c @@ -23467,14 +23467,17 @@ __cold int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, return MDBX_EPERM; if (unlikely(value > SIZE_MAX - 65536)) return MDBX_TOO_LARGE; - if (atomic_store32(&env->me_lck->mti_autosync_threshold, - bytes2pgno(env, (size_t)value + env->me_psize - 1), - mo_Relaxed) != 0 && - (env->me_flags & MDBX_ENV_ACTIVE)) { - err = mdbx_env_sync_poll(env); - if (unlikely(MDBX_IS_ERROR(err))) - return err; - err = MDBX_SUCCESS; + value = bytes2pgno(env, (size_t)value + env->me_psize - 1); + if ((uint32_t)value != atomic_load32(&env->me_lck->mti_autosync_threshold, + mo_AcquireRelease) && + atomic_store32(&env->me_lck->mti_autosync_threshold, (uint32_t)value, + mo_Relaxed) + /* Дергаем sync(force=off) только если задано новое не-нулевое значение + * и мы вне транзакции */ + && lock_needed) { + err = env_sync(env, false, false); + if (err == /* нечего сбрасывать на диск */ MDBX_RESULT_TRUE) + err = MDBX_SUCCESS; } break; @@ -23487,14 +23490,16 @@ __cold int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, return MDBX_EPERM; if (unlikely(value > UINT32_MAX)) return MDBX_TOO_LARGE; - if (atomic_store64(&env->me_lck->mti_autosync_period, - osal_16dot16_to_monotime((uint32_t)value), - mo_Relaxed) != 0 && - (env->me_flags & MDBX_ENV_ACTIVE)) { - err = mdbx_env_sync_poll(env); - if (unlikely(MDBX_IS_ERROR(err))) - return err; - err = MDBX_SUCCESS; + value = osal_16dot16_to_monotime((uint32_t)value); + if (value != atomic_load64(&env->me_lck->mti_autosync_period, + mo_AcquireRelease) && + atomic_store64(&env->me_lck->mti_autosync_period, value, mo_Relaxed) + /* Дергаем sync(force=off) только если задано новое не-нулевое значение + * и мы вне транзакции */ + && lock_needed) { + err = env_sync(env, false, false); + if (err == /* нечего сбрасывать на диск */ MDBX_RESULT_TRUE) + err = MDBX_SUCCESS; } break;