mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 02:14:12 +08:00
mdbx: rename MDBX_ENV_CHECKPID.
Change-Id: Id0afbea99b0747c6d7a5062c1c4a82ebc69f4f40
This commit is contained in:
parent
1e3c4dc0ef
commit
0387d6f6d4
@ -379,9 +379,9 @@ add_mdbx_option(MDBX_INSTALL_STATIC "Build and install libmdbx for static linkin
|
||||
add_mdbx_option(MDBX_BUILD_SHARED_LIBRARY "Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS})
|
||||
add_mdbx_option(MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy)" ${MDBX_BUILD_TOOLS_DEFAULT})
|
||||
add_mdbx_option(MDBX_TXN_CHECKOWNER "Checking transaction matches the calling thread inside libmdbx's API" ON)
|
||||
add_mdbx_option(MDBX_TXN_CHECKPID "Paranoid checking PID inside libmdbx's API" AUTO)
|
||||
add_mdbx_option(MDBX_ENV_CHECKPID "Paranoid checking PID inside libmdbx's API" AUTO)
|
||||
add_mdbx_option(MDBX_HUGE_TRANSACTIONS "Support for huge write-transactions" OFF)
|
||||
mark_as_advanced(MDBX_TXN_CHECKPID)
|
||||
mark_as_advanced(MDBX_ENV_CHECKPID)
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions" OFF)
|
||||
mark_as_advanced(MDBX_DISABLE_GNU_SOURCE)
|
||||
|
@ -56,7 +56,7 @@ It would be insane to call fork() and any MDBX-functions simultaneously
|
||||
from multiple threads. The best way is to prevent the presence of open
|
||||
MDBX-instances during `fork()`.
|
||||
|
||||
The `MDBX_TXN_CHECKPID` build-time option, which is ON by default on
|
||||
The `MDBX_ENV_CHECKPID` build-time option, which is ON by default on
|
||||
non-Windows platforms (i.e. where `fork()` is available), enables PID
|
||||
checking at a few critical points. But this does not give any guarantees,
|
||||
but only allows you to detect such errors a little sooner. Depending on
|
||||
|
@ -14,9 +14,9 @@
|
||||
/* Common */
|
||||
#cmakedefine01 MDBX_HUGE_TRANSACTIONS
|
||||
#cmakedefine01 MDBX_TXN_CHECKOWNER
|
||||
#cmakedefine MDBX_TXN_CHECKPID_AUTO
|
||||
#ifndef MDBX_TXN_CHECKPID_AUTO
|
||||
#cmakedefine01 MDBX_TXN_CHECKPID
|
||||
#cmakedefine MDBX_ENV_CHECKPID_AUTO
|
||||
#ifndef MDBX_ENV_CHECKPID_AUTO
|
||||
#cmakedefine01 MDBX_ENV_CHECKPID
|
||||
#endif
|
||||
#cmakedefine MDBX_LOCKING_AUTO
|
||||
#ifndef MDBX_LOCKING_AUTO
|
||||
|
40
src/core.c
40
src/core.c
@ -5714,12 +5714,12 @@ __cold int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock) {
|
||||
if (unlikely(env->me_signature != MDBX_ME_SIGNATURE))
|
||||
return MDBX_EBADSIGN;
|
||||
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(env->me_pid != mdbx_getpid())) {
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
return MDBX_PANIC;
|
||||
}
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
return mdbx_env_sync_internal(env, force, nonblock);
|
||||
}
|
||||
@ -5896,12 +5896,12 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
|
||||
MDBX_env *env = txn->mt_env;
|
||||
int rc;
|
||||
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(env->me_pid != mdbx_getpid())) {
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
return MDBX_PANIC;
|
||||
}
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
STATIC_ASSERT(sizeof(MDBX_reader) == 32);
|
||||
#if MDBX_LOCKING > 0
|
||||
@ -6264,10 +6264,10 @@ int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, unsigned flags,
|
||||
if (unlikely(env->me_signature != MDBX_ME_SIGNATURE))
|
||||
return MDBX_EBADSIGN;
|
||||
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(env->me_pid != mdbx_getpid()))
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
if (unlikely(env->me_flags & MDBX_FATAL_ERROR))
|
||||
return MDBX_PANIC;
|
||||
@ -6417,12 +6417,12 @@ int mdbx_txn_info(const MDBX_txn *txn, MDBX_txn_info *info, bool scan_rlt) {
|
||||
return MDBX_EINVAL;
|
||||
|
||||
MDBX_env *const env = txn->mt_env;
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(env->me_pid != mdbx_getpid())) {
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
return MDBX_PANIC;
|
||||
}
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
info->txn_id = txn->mt_txnid;
|
||||
info->txn_space_used = pgno2bytes(env, txn->mt_geo.next);
|
||||
@ -6588,12 +6588,12 @@ static int mdbx_txn_end(MDBX_txn *txn, unsigned mode) {
|
||||
MDBX_env *env = txn->mt_env;
|
||||
static const char *const names[] = MDBX_END_NAMES;
|
||||
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(txn->mt_env->me_pid != mdbx_getpid())) {
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
return MDBX_PANIC;
|
||||
}
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
mdbx_debug("%s txn %" PRIaTXN "%c %p on mdbenv %p, root page %" PRIaPGNO
|
||||
"/%" PRIaPGNO,
|
||||
@ -7781,12 +7781,12 @@ int mdbx_txn_commit(MDBX_txn *txn) {
|
||||
}
|
||||
|
||||
MDBX_env *env = txn->mt_env;
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(env->me_pid != mdbx_getpid())) {
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
return MDBX_PANIC;
|
||||
}
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
/* mdbx_txn_end() mode for a commit which writes nothing */
|
||||
unsigned end_mode =
|
||||
@ -8912,10 +8912,10 @@ mdbx_env_set_geometry(MDBX_env *env, intptr_t size_lower, intptr_t size_now,
|
||||
if (unlikely(env->me_signature != MDBX_ME_SIGNATURE))
|
||||
return MDBX_EBADSIGN;
|
||||
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(env->me_pid != mdbx_getpid()))
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
if (unlikely(env->me_flags & MDBX_FATAL_ERROR))
|
||||
return MDBX_PANIC;
|
||||
@ -10431,14 +10431,14 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) {
|
||||
if (unlikely(env->me_signature != MDBX_ME_SIGNATURE))
|
||||
return MDBX_EBADSIGN;
|
||||
|
||||
#if MDBX_TXN_CHECKPID || !(defined(_WIN32) || defined(_WIN64))
|
||||
/* Check the PID even if MDBX_TXN_CHECKPID=0 on non-Windows
|
||||
#if MDBX_ENV_CHECKPID || !(defined(_WIN32) || defined(_WIN64))
|
||||
/* Check the PID even if MDBX_ENV_CHECKPID=0 on non-Windows
|
||||
* platforms (i.e. where fork() is available).
|
||||
* This is required to legitimize a call after fork()
|
||||
* from a child process, that should be allowed to free resources. */
|
||||
if (unlikely(env->me_pid != mdbx_getpid()))
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
if ((env->me_flags & (MDBX_RDONLY | MDBX_FATAL_ERROR)) == 0 && env->me_txn0) {
|
||||
if (env->me_txn0->mt_owner && env->me_txn0->mt_owner != mdbx_thread_self())
|
||||
@ -17053,12 +17053,12 @@ int __cold mdbx_reader_check(MDBX_env *env, int *dead) {
|
||||
int __cold mdbx_reader_check0(MDBX_env *env, int rdt_locked, int *dead) {
|
||||
mdbx_assert(env, rdt_locked >= 0);
|
||||
|
||||
#if MDBX_TXN_CHECKPID
|
||||
#if MDBX_ENV_CHECKPID
|
||||
if (unlikely(env->me_pid != mdbx_getpid())) {
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
return MDBX_PANIC;
|
||||
}
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
MDBX_lockinfo *const lck = env->me_lck;
|
||||
if (unlikely(lck == NULL)) {
|
||||
@ -18942,7 +18942,7 @@ __dll_export
|
||||
#if MDBX_HUGE_TRANSACTIONS
|
||||
" MDBX_HUGE_TRANSACTIONS=YES"
|
||||
#endif /* MDBX_HUGE_TRANSACTIONS */
|
||||
" MDBX_TXN_CHECKPID=" MDBX_TXN_CHECKPID_CONFIG
|
||||
" MDBX_ENV_CHECKPID=" MDBX_ENV_CHECKPID_CONFIG
|
||||
" MDBX_TXN_CHECKOWNER=" MDBX_TXN_CHECKOWNER_CONFIG
|
||||
" MDBX_64BIT_ATOMIC=" MDBX_64BIT_ATOMIC_CONFIG
|
||||
" MDBX_64BIT_CAS=" MDBX_64BIT_CAS_CONFIG
|
||||
|
@ -58,20 +58,20 @@
|
||||
#endif /* MDBX_OSX_SPEED_INSTEADOF_DURABILITY */
|
||||
|
||||
/** Controls checking PID against reuse DB environment after the fork() */
|
||||
#ifndef MDBX_TXN_CHECKPID
|
||||
#ifndef MDBX_ENV_CHECKPID
|
||||
#if defined(MADV_DONTFORK) || defined(_WIN32) || defined(_WIN64)
|
||||
/* PID check could be ommited:
|
||||
* - on Linux when madvise(MADV_DONTFORK) is available. i.e. after the fork()
|
||||
* mapped pages will not be available for child process.
|
||||
* - in Windows where fork() not available. */
|
||||
#define MDBX_TXN_CHECKPID 0
|
||||
#define MDBX_ENV_CHECKPID 0
|
||||
#else
|
||||
#define MDBX_TXN_CHECKPID 1
|
||||
#define MDBX_ENV_CHECKPID 1
|
||||
#endif
|
||||
#define MDBX_TXN_CHECKPID_CONFIG "AUTO=" STRINGIFY(MDBX_TXN_CHECKPID)
|
||||
#define MDBX_ENV_CHECKPID_CONFIG "AUTO=" STRINGIFY(MDBX_ENV_CHECKPID)
|
||||
#else
|
||||
#define MDBX_TXN_CHECKPID_CONFIG STRINGIFY(MDBX_TXN_CHECKPID)
|
||||
#endif /* MDBX_TXN_CHECKPID */
|
||||
#define MDBX_ENV_CHECKPID_CONFIG STRINGIFY(MDBX_ENV_CHECKPID)
|
||||
#endif /* MDBX_ENV_CHECKPID */
|
||||
|
||||
/** Controls checking transaction owner thread against misuse transactions from
|
||||
* other threads. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user