github.com/moontrade/mdbx-go@v0.4.0/options.h (about) 1 /******************************************************************************* 2 ******************************************************************************* 3 ******************************************************************************* 4 * 5 * 6 * #### ##### ##### # #### # # #### 7 * # # # # # # # # ## # # 8 * # # # # # # # # # # # #### 9 * # # ##### # # # # # # # # 10 * # # # # # # # # ## # # 11 * #### # # # #### # # #### 12 * 13 * 14 */ 15 16 /** \defgroup build_option Build options 17 * The libmdbx build options. 18 @{ */ 19 20 /** Using fcntl(F_FULLFSYNC) with 5-10 times slowdown */ 21 #define MDBX_OSX_WANNA_DURABILITY 0 22 /** Using fsync() with chance of data lost on power failure */ 23 #define MDBX_OSX_WANNA_SPEED 1 24 25 #ifndef MDBX_OSX_SPEED_INSTEADOF_DURABILITY 26 /** Choices \ref MDBX_OSX_WANNA_DURABILITY or \ref MDBX_OSX_WANNA_SPEED 27 * for OSX & iOS */ 28 #define MDBX_OSX_SPEED_INSTEADOF_DURABILITY MDBX_OSX_WANNA_DURABILITY 29 #endif /* MDBX_OSX_SPEED_INSTEADOF_DURABILITY */ 30 31 /** Controls checking PID against reuse DB environment after the fork() */ 32 #ifndef MDBX_ENV_CHECKPID 33 #if defined(MADV_DONTFORK) || defined(_WIN32) || defined(_WIN64) 34 /* PID check could be omitted: 35 * - on Linux when madvise(MADV_DONTFORK) is available, i.e. after the fork() 36 * mapped pages will not be available for child process. 37 * - in Windows where fork() not available. */ 38 #define MDBX_ENV_CHECKPID 0 39 #else 40 #define MDBX_ENV_CHECKPID 1 41 #endif 42 #define MDBX_ENV_CHECKPID_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_ENV_CHECKPID) 43 #else 44 #define MDBX_ENV_CHECKPID_CONFIG MDBX_STRINGIFY(MDBX_ENV_CHECKPID) 45 #endif /* MDBX_ENV_CHECKPID */ 46 47 /** Controls checking transaction owner thread against misuse transactions from 48 * other threads. */ 49 #ifndef MDBX_TXN_CHECKOWNER 50 #define MDBX_TXN_CHECKOWNER 1 51 #define MDBX_TXN_CHECKOWNER_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_TXN_CHECKOWNER) 52 #else 53 #define MDBX_TXN_CHECKOWNER_CONFIG MDBX_STRINGIFY(MDBX_TXN_CHECKOWNER) 54 #endif /* MDBX_TXN_CHECKOWNER */ 55 56 /** Does a system have battery-backed Real-Time Clock or just a fake. */ 57 #ifndef MDBX_TRUST_RTC 58 #if defined(__linux__) || defined(__gnu_linux__) || defined(__NetBSD__) || \ 59 defined(__OpenBSD__) 60 #define MDBX_TRUST_RTC 0 /* a lot of embedded systems have a fake RTC */ 61 #else 62 #define MDBX_TRUST_RTC 1 63 #endif 64 #define MDBX_TRUST_RTC_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_TRUST_RTC) 65 #else 66 #define MDBX_TRUST_RTC_CONFIG MDBX_STRINGIFY(MDBX_TRUST_RTC) 67 #endif /* MDBX_TRUST_RTC */ 68 69 /** Controls online database auto-compactification during write-transactions. */ 70 #ifndef MDBX_ENABLE_REFUND 71 #define MDBX_ENABLE_REFUND 1 72 #elif !(MDBX_ENABLE_REFUND == 0 || MDBX_ENABLE_REFUND == 1) 73 #error MDBX_ENABLE_REFUND must be defined as 0 or 1 74 #endif /* MDBX_ENABLE_REFUND */ 75 76 /** Controls gathering statistics for page operations. */ 77 #ifndef MDBX_ENABLE_PGOP_STAT 78 #define MDBX_ENABLE_PGOP_STAT 1 79 #elif !(MDBX_ENABLE_PGOP_STAT == 0 || MDBX_ENABLE_PGOP_STAT == 1) 80 #error MDBX_ENABLE_PGOP_STAT must be defined as 0 or 1 81 #endif /* MDBX_ENABLE_PGOP_STAT */ 82 83 /** Controls use of POSIX madvise() hints and friends. */ 84 #ifndef MDBX_ENABLE_MADVISE 85 #define MDBX_ENABLE_MADVISE 1 86 #elif !(MDBX_ENABLE_MADVISE == 0 || MDBX_ENABLE_MADVISE == 1) 87 #error MDBX_ENABLE_MADVISE must be defined as 0 or 1 88 #endif /* MDBX_ENABLE_MADVISE */ 89 90 /** Disable some checks to reduce an overhead and detection probability of 91 * database corruption to a values closer to the LMDB. */ 92 #ifndef MDBX_DISABLE_PAGECHECKS 93 #define MDBX_DISABLE_PAGECHECKS 0 94 #elif !(MDBX_DISABLE_PAGECHECKS == 0 || MDBX_DISABLE_PAGECHECKS == 1) 95 #error MDBX_DISABLE_PAGECHECKS must be defined as 0 or 1 96 #endif /* MDBX_DISABLE_PAGECHECKS */ 97 98 #ifndef MDBX_PNL_PREALLOC_FOR_RADIXSORT 99 #define MDBX_PNL_PREALLOC_FOR_RADIXSORT 1 100 #elif !(MDBX_PNL_PREALLOC_FOR_RADIXSORT == 0 || \ 101 MDBX_PNL_PREALLOC_FOR_RADIXSORT == 1) 102 #error MDBX_PNL_PREALLOC_FOR_RADIXSORT must be defined as 0 or 1 103 #endif /* MDBX_PNL_PREALLOC_FOR_RADIXSORT */ 104 105 #ifndef MDBX_DPL_PREALLOC_FOR_RADIXSORT 106 #define MDBX_DPL_PREALLOC_FOR_RADIXSORT 1 107 #elif !(MDBX_DPL_PREALLOC_FOR_RADIXSORT == 0 || \ 108 MDBX_DPL_PREALLOC_FOR_RADIXSORT == 1) 109 #error MDBX_DPL_PREALLOC_FOR_RADIXSORT must be defined as 0 or 1 110 #endif /* MDBX_DPL_PREALLOC_FOR_RADIXSORT */ 111 112 /** Basically, this build-option is for TODO. Guess it should be replaced 113 * with MDBX_ENABLE_WRITEMAP_SPILLING with the three variants: 114 * 0/OFF = Don't track dirty pages at all and don't spilling ones. 115 * This should be by-default on Linux and may-be other systems 116 * (not sure: Darwin/OSX, FreeBSD, Windows 10) where kernel provides 117 * properly LRU tracking and async writing on-demand. 118 * 1/ON = Lite tracking of dirty pages but with LRU labels and explicit 119 * spilling with msync(MS_ASYNC). */ 120 #ifndef MDBX_FAKE_SPILL_WRITEMAP 121 #if defined(__linux__) || defined(__gnu_linux__) 122 #define MDBX_FAKE_SPILL_WRITEMAP 1 /* msync(MS_ASYNC) is no-op on Linux */ 123 #else 124 #define MDBX_FAKE_SPILL_WRITEMAP 0 125 #endif 126 #elif !(MDBX_FAKE_SPILL_WRITEMAP == 0 || MDBX_FAKE_SPILL_WRITEMAP == 1) 127 #error MDBX_FAKE_SPILL_WRITEMAP must be defined as 0 or 1 128 #endif /* MDBX_FAKE_SPILL_WRITEMAP */ 129 130 /** Controls sort order of internal page number lists. 131 * This mostly experimental/advanced option with not for regular MDBX users. 132 * \warning The database format depend on this option and libmdbx builded with 133 * different option value are incompatible. */ 134 #ifndef MDBX_PNL_ASCENDING 135 #define MDBX_PNL_ASCENDING 0 136 #elif !(MDBX_PNL_ASCENDING == 0 || MDBX_PNL_ASCENDING == 1) 137 #error MDBX_PNL_ASCENDING must be defined as 0 or 1 138 #endif /* MDBX_PNL_ASCENDING */ 139 140 /** Avoid dependence from MSVC CRT and use ntdll.dll instead. */ 141 #ifndef MDBX_WITHOUT_MSVC_CRT 142 #define MDBX_WITHOUT_MSVC_CRT 1 143 #elif !(MDBX_WITHOUT_MSVC_CRT == 0 || MDBX_WITHOUT_MSVC_CRT == 1) 144 #error MDBX_WITHOUT_MSVC_CRT must be defined as 0 or 1 145 #endif /* MDBX_WITHOUT_MSVC_CRT */ 146 147 /** Size of buffer used during copying a environment/database file. */ 148 #ifndef MDBX_ENVCOPY_WRITEBUF 149 #define MDBX_ENVCOPY_WRITEBUF 1048576u 150 #elif MDBX_ENVCOPY_WRITEBUF < 65536u || MDBX_ENVCOPY_WRITEBUF > 1073741824u || \ 151 MDBX_ENVCOPY_WRITEBUF % 65536u 152 #error MDBX_ENVCOPY_WRITEBUF must be defined in range 65536..1073741824 and be multiple of 65536 153 #endif /* MDBX_ENVCOPY_WRITEBUF */ 154 155 /** Forces assertion checking */ 156 #ifndef MDBX_FORCE_ASSERTIONS 157 #define MDBX_FORCE_ASSERTIONS 0 158 #elif !(MDBX_FORCE_ASSERTIONS == 0 || MDBX_FORCE_ASSERTIONS == 1) 159 #error MDBX_FORCE_ASSERTIONS must be defined as 0 or 1 160 #endif /* MDBX_FORCE_ASSERTIONS */ 161 162 /** Presumed malloc size overhead for each allocation 163 * to adjust allocations to be more aligned. */ 164 #ifndef MDBX_ASSUME_MALLOC_OVERHEAD 165 #ifdef __SIZEOF_POINTER__ 166 #define MDBX_ASSUME_MALLOC_OVERHEAD (__SIZEOF_POINTER__ * 2u) 167 #else 168 #define MDBX_ASSUME_MALLOC_OVERHEAD (sizeof(void *) * 2u) 169 #endif 170 #elif MDBX_ASSUME_MALLOC_OVERHEAD < 0 || MDBX_ASSUME_MALLOC_OVERHEAD > 64 || \ 171 MDBX_ASSUME_MALLOC_OVERHEAD % 4 172 #error MDBX_ASSUME_MALLOC_OVERHEAD must be defined in range 0..64 and be multiple of 4 173 #endif /* MDBX_ASSUME_MALLOC_OVERHEAD */ 174 175 /** If defined then enables integration with Valgrind, 176 * a memory analyzing tool. */ 177 #ifndef MDBX_USE_VALGRIND 178 #endif /* MDBX_USE_VALGRIND */ 179 180 /** If defined then enables use C11 atomics, 181 * otherwise detects ones availability automatically. */ 182 #ifndef MDBX_HAVE_C11ATOMICS 183 #endif /* MDBX_HAVE_C11ATOMICS */ 184 185 //------------------------------------------------------------------------------ 186 187 /** Win32 File Locking API for \ref MDBX_LOCKING */ 188 #define MDBX_LOCKING_WIN32FILES -1 189 190 /** SystemV IPC semaphores for \ref MDBX_LOCKING */ 191 #define MDBX_LOCKING_SYSV 5 192 193 /** POSIX-1 Shared anonymous semaphores for \ref MDBX_LOCKING */ 194 #define MDBX_LOCKING_POSIX1988 1988 195 196 /** POSIX-2001 Shared Mutexes for \ref MDBX_LOCKING */ 197 #define MDBX_LOCKING_POSIX2001 2001 198 199 /** POSIX-2008 Robust Mutexes for \ref MDBX_LOCKING */ 200 #define MDBX_LOCKING_POSIX2008 2008 201 202 /** BeOS Benaphores, aka Futexes for \ref MDBX_LOCKING */ 203 #define MDBX_LOCKING_BENAPHORE 1995 204 205 /** Advanced: Choices the locking implementation (autodetection by default). */ 206 #if defined(_WIN32) || defined(_WIN64) 207 #define MDBX_LOCKING MDBX_LOCKING_WIN32FILES 208 #else 209 #ifndef MDBX_LOCKING 210 #if defined(_POSIX_THREAD_PROCESS_SHARED) && \ 211 _POSIX_THREAD_PROCESS_SHARED >= 200112L && !defined(__FreeBSD__) 212 213 /* Some platforms define the EOWNERDEAD error code even though they 214 * don't support Robust Mutexes. If doubt compile with -MDBX_LOCKING=2001. */ 215 #if defined(EOWNERDEAD) && _POSIX_THREAD_PROCESS_SHARED >= 200809L && \ 216 ((defined(_POSIX_THREAD_ROBUST_PRIO_INHERIT) && \ 217 _POSIX_THREAD_ROBUST_PRIO_INHERIT > 0) || \ 218 (defined(_POSIX_THREAD_ROBUST_PRIO_PROTECT) && \ 219 _POSIX_THREAD_ROBUST_PRIO_PROTECT > 0) || \ 220 defined(PTHREAD_MUTEX_ROBUST) || defined(PTHREAD_MUTEX_ROBUST_NP)) && \ 221 (!defined(__GLIBC__) || \ 222 __GLIBC_PREREQ(2, 10) /* troubles with Robust mutexes before 2.10 */) 223 #define MDBX_LOCKING MDBX_LOCKING_POSIX2008 224 #else 225 #define MDBX_LOCKING MDBX_LOCKING_POSIX2001 226 #endif 227 #elif defined(__sun) || defined(__SVR4) || defined(__svr4__) 228 #define MDBX_LOCKING MDBX_LOCKING_POSIX1988 229 #else 230 #define MDBX_LOCKING MDBX_LOCKING_SYSV 231 #endif 232 #define MDBX_LOCKING_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_LOCKING) 233 #else 234 #define MDBX_LOCKING_CONFIG MDBX_STRINGIFY(MDBX_LOCKING) 235 #endif /* MDBX_LOCKING */ 236 #endif /* !Windows */ 237 238 /** Advanced: Using POSIX OFD-locks (autodetection by default). */ 239 #ifndef MDBX_USE_OFDLOCKS 240 #if defined(F_OFD_SETLK) && defined(F_OFD_SETLKW) && defined(F_OFD_GETLK) && \ 241 !defined(MDBX_SAFE4QEMU) && \ 242 !defined(__sun) /* OFD-lock are broken on Solaris */ 243 #define MDBX_USE_OFDLOCKS 1 244 #else 245 #define MDBX_USE_OFDLOCKS 0 246 #endif 247 #define MDBX_USE_OFDLOCKS_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_USE_OFDLOCKS) 248 #else 249 #define MDBX_USE_OFDLOCKS_CONFIG MDBX_STRINGIFY(MDBX_USE_OFDLOCKS) 250 #endif /* MDBX_USE_OFDLOCKS */ 251 252 /** Advanced: Using sendfile() syscall (autodetection by default). */ 253 #ifndef MDBX_USE_SENDFILE 254 #if ((defined(__linux__) || defined(__gnu_linux__)) && \ 255 !defined(__ANDROID_API__)) || \ 256 (defined(__ANDROID_API__) && __ANDROID_API__ >= 21) 257 #define MDBX_USE_SENDFILE 1 258 #else 259 #define MDBX_USE_SENDFILE 0 260 #endif 261 #endif /* MDBX_USE_SENDFILE */ 262 263 /** Advanced: Using copy_file_range() syscall (autodetection by default). */ 264 #ifndef MDBX_USE_COPYFILERANGE 265 #if __GLIBC_PREREQ(2, 27) && defined(_GNU_SOURCE) 266 #define MDBX_USE_COPYFILERANGE 1 267 #else 268 #define MDBX_USE_COPYFILERANGE 0 269 #endif 270 #endif /* MDBX_USE_COPYFILERANGE */ 271 272 /** Advanced: Using sync_file_range() syscall (autodetection by default). */ 273 #ifndef MDBX_USE_SYNCFILERANGE 274 #if ((defined(__linux__) || defined(__gnu_linux__)) && \ 275 defined(SYNC_FILE_RANGE_WRITE) && !defined(__ANDROID_API__)) || \ 276 (defined(__ANDROID_API__) && __ANDROID_API__ >= 26) 277 #define MDBX_USE_SYNCFILERANGE 1 278 #else 279 #define MDBX_USE_SYNCFILERANGE 0 280 #endif 281 #endif /* MDBX_USE_SYNCFILERANGE */ 282 283 //------------------------------------------------------------------------------ 284 285 #ifndef MDBX_CPU_WRITEBACK_INCOHERENT 286 #if defined(__ia32__) || defined(__e2k__) || defined(__hppa) || \ 287 defined(__hppa__) || defined(DOXYGEN) 288 #define MDBX_CPU_WRITEBACK_INCOHERENT 0 289 #else 290 #define MDBX_CPU_WRITEBACK_INCOHERENT 1 291 #endif 292 #endif /* MDBX_CPU_WRITEBACK_INCOHERENT */ 293 294 #ifndef MDBX_MMAP_INCOHERENT_FILE_WRITE 295 #ifdef __OpenBSD__ 296 #define MDBX_MMAP_INCOHERENT_FILE_WRITE 1 297 #else 298 #define MDBX_MMAP_INCOHERENT_FILE_WRITE 0 299 #endif 300 #endif /* MDBX_MMAP_INCOHERENT_FILE_WRITE */ 301 302 #ifndef MDBX_MMAP_INCOHERENT_CPU_CACHE 303 #if defined(__mips) || defined(__mips__) || defined(__mips64) || \ 304 defined(__mips64__) || defined(_M_MRX000) || defined(_MIPS_) || \ 305 defined(__MWERKS__) || defined(__sgi) 306 /* MIPS has cache coherency issues. */ 307 #define MDBX_MMAP_INCOHERENT_CPU_CACHE 1 308 #else 309 /* LY: assume no relevant mmap/dcache issues. */ 310 #define MDBX_MMAP_INCOHERENT_CPU_CACHE 0 311 #endif 312 #endif /* MDBX_MMAP_INCOHERENT_CPU_CACHE */ 313 314 #ifndef MDBX_64BIT_ATOMIC 315 #if MDBX_WORDBITS >= 64 || defined(DOXYGEN) 316 #define MDBX_64BIT_ATOMIC 1 317 #else 318 #define MDBX_64BIT_ATOMIC 0 319 #endif 320 #define MDBX_64BIT_ATOMIC_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_64BIT_ATOMIC) 321 #else 322 #define MDBX_64BIT_ATOMIC_CONFIG MDBX_STRINGIFY(MDBX_64BIT_ATOMIC) 323 #endif /* MDBX_64BIT_ATOMIC */ 324 325 #ifndef MDBX_64BIT_CAS 326 #if defined(ATOMIC_LLONG_LOCK_FREE) 327 #if ATOMIC_LLONG_LOCK_FREE > 1 328 #define MDBX_64BIT_CAS 1 329 #else 330 #define MDBX_64BIT_CAS 0 331 #endif 332 #elif defined(__GCC_ATOMIC_LLONG_LOCK_FREE) 333 #if __GCC_ATOMIC_LLONG_LOCK_FREE > 1 334 #define MDBX_64BIT_CAS 1 335 #else 336 #define MDBX_64BIT_CAS 0 337 #endif 338 #elif defined(__CLANG_ATOMIC_LLONG_LOCK_FREE) 339 #if __CLANG_ATOMIC_LLONG_LOCK_FREE > 1 340 #define MDBX_64BIT_CAS 1 341 #else 342 #define MDBX_64BIT_CAS 0 343 #endif 344 #elif defined(_MSC_VER) || defined(__APPLE__) || defined(DOXYGEN) 345 #define MDBX_64BIT_CAS 1 346 #else 347 #define MDBX_64BIT_CAS MDBX_64BIT_ATOMIC 348 #endif 349 #define MDBX_64BIT_CAS_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_64BIT_CAS) 350 #else 351 #define MDBX_64BIT_CAS_CONFIG MDBX_STRINGIFY(MDBX_64BIT_CAS) 352 #endif /* MDBX_64BIT_CAS */ 353 354 #ifndef MDBX_UNALIGNED_OK 355 #if defined(__ALIGNED__) || defined(__SANITIZE_UNDEFINED__) 356 #define MDBX_UNALIGNED_OK 0 /* no unaligned access allowed */ 357 #elif defined(__ARM_FEATURE_UNALIGNED) 358 #define MDBX_UNALIGNED_OK 4 /* ok unaligned for 32-bit words */ 359 #elif __CLANG_PREREQ(5, 0) || __GNUC_PREREQ(5, 0) 360 /* expecting an optimization will well done, also this 361 * hushes false-positives from UBSAN (undefined behaviour sanitizer) */ 362 #define MDBX_UNALIGNED_OK 0 363 #elif defined(__e2k__) || defined(__elbrus__) 364 #if __iset__ > 4 365 #define MDBX_UNALIGNED_OK 8 /* ok unaligned for 64-bit words */ 366 #else 367 #define MDBX_UNALIGNED_OK 4 /* ok unaligned for 32-bit words */ 368 #endif 369 #elif defined(__ia32__) 370 #define MDBX_UNALIGNED_OK 8 /* ok unaligned for 64-bit words */ 371 #else 372 #define MDBX_UNALIGNED_OK 0 /* no unaligned access allowed */ 373 #endif 374 #elif MDBX_UNALIGNED_OK == 1 375 #undef MDBX_UNALIGNED_OK 376 #define MDBX_UNALIGNED_OK 32 /* any unaligned access allowed */ 377 #endif /* MDBX_UNALIGNED_OK */ 378 379 #ifndef MDBX_CACHELINE_SIZE 380 #if defined(SYSTEM_CACHE_ALIGNMENT_SIZE) 381 #define MDBX_CACHELINE_SIZE SYSTEM_CACHE_ALIGNMENT_SIZE 382 #elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64) 383 #define MDBX_CACHELINE_SIZE 128 384 #else 385 #define MDBX_CACHELINE_SIZE 64 386 #endif 387 #endif /* MDBX_CACHELINE_SIZE */ 388 389 /** @} end of build options */ 390 /******************************************************************************* 391 ******************************************************************************* 392 ******************************************************************************/ 393 394 #ifndef DOXYGEN 395 396 /* In case the MDBX_DEBUG is undefined set it corresponding to NDEBUG */ 397 #ifndef MDBX_DEBUG 398 #ifdef NDEBUG 399 #define MDBX_DEBUG 0 400 #else 401 #define MDBX_DEBUG 1 402 #endif 403 #endif /* MDBX_DEBUG */ 404 405 #else 406 407 /* !!! Actually this is a fake definitions for Doxygen !!! */ 408 409 /** Controls enabling of debugging features. 410 * 411 * - `MDBX_DEBUG = 0` (by default) Disables any debugging features at all, 412 * including logging and assertion controls. 413 * Logging level and corresponding debug flags changing 414 * by \ref mdbx_setup_debug() will not have effect. 415 * - `MDBX_DEBUG > 0` Enables code for the debugging features (logging, 416 * assertions checking and internal audit). 417 * Simultaneously sets the default logging level 418 * to the `MDBX_DEBUG` value. 419 * Also enables \ref MDBX_DBG_AUDIT if `MDBX_DEBUG >= 2`. 420 * 421 * \ingroup build_option */ 422 #define MDBX_DEBUG 0...7 423 424 /** Disables using of GNU libc extensions. */ 425 #define MDBX_DISABLE_GNU_SOURCE 0 or 1 426 427 #endif /* DOXYGEN */