From c1ad75d8107d9ff4e5e89df8058c65161d43a188 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Fri, 21 Apr 2017 19:00:33 +0300 Subject: [PATCH] mdbx: check env-flags while opening live db. --- src/bits.h | 2 ++ src/mdbx.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bits.h b/src/bits.h index 7b89604d..ca6dc06c 100644 --- a/src/bits.h +++ b/src/bits.h @@ -360,6 +360,8 @@ typedef struct MDBX_lockinfo { uint64_t mti_magic; /* Format of this lock file. Must be set to MDB_LOCK_FORMAT. */ uint64_t mti_format; + /* Flags which environment was opened. */ + uint64_t mti_envmode; #ifdef MDBX_OSAL_LOCK MDBX_OSAL_LOCK mti_wmutex; diff --git a/src/mdbx.c b/src/mdbx.c index 655c0534..fc7db92b 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -3994,6 +3994,7 @@ int __cold mdbx_env_open_ex(MDB_env *env, const char *path, unsigned flags, if (rc == MDB_SUCCESS) { mdbx_debug("opened dbenv %p", (void *)env); if (excl > 0) { + env->me_txns->mti_envmode = env->me_flags; if (exclusive == NULL || *exclusive < 2) { /* LY: downgrade lock only if exclusive access not requested. * in case exclusive==1, just leave value as is. */ @@ -4002,9 +4003,17 @@ int __cold mdbx_env_open_ex(MDB_env *env, const char *path, unsigned flags, goto bailout; excl = 0; } - } else if (exclusive) { - /* LY: just indicate that is not an exclusive access. */ - *exclusive = 0; + } else { + if (exclusive) { + /* LY: just indicate that is not an exclusive access. */ + *exclusive = 0; + } + if ((env->me_txns->mti_envmode ^ env->me_flags) & + (MDB_WRITEMAP | MDB_NOSYNC | MDB_NOMETASYNC | MDB_MAPASYNC)) { + /* LY: Current mode/flags incompatible with requested. */ + rc = MDB_INCOMPATIBLE; + goto bailout; + } } if (!(flags & MDB_RDONLY)) { MDB_txn *txn;