mdbx: check env-flags while opening live db.

This commit is contained in:
Leo Yuriev 2017-04-21 19:00:33 +03:00
parent 36f1491ba8
commit c1ad75d810
2 changed files with 14 additions and 3 deletions

View File

@ -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;

View File

@ -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;