mdbx: rename MDBX_NOSYNC to MDBX_SAFE_NOSYNC for clarity.

Change-Id: I1d04600832cb7c86c578d72f3d6163ee22d134b7
This commit is contained in:
Leonid Yuriev 2019-12-15 15:13:46 +03:00
parent a77921dc67
commit 4eccf901ea
7 changed files with 104 additions and 96 deletions

135
mdbx.h
View File

@ -1071,11 +1071,11 @@ LIBMDBX_API const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
* conditions for the efficient operation of the disk write-back cache. * conditions for the efficient operation of the disk write-back cache.
* *
* MDBX_LIFORECLAIM is compatible with all no-sync flags (i.e. MDBX_NOMETASYNC, * MDBX_LIFORECLAIM is compatible with all no-sync flags (i.e. MDBX_NOMETASYNC,
* MDBX_NOSYNC, MDBX_UTTERLY_NOSYNC, MDBX_MAPASYNC), but gives no noticeable * MDBX_SAFE_NOSYNC, MDBX_UTTERLY_NOSYNC, MDBX_MAPASYNC), but gives no
* impact in combination with MDB_NOSYNC and MDX_MAPASYNC. Because MDBX will * noticeable impact in combination with MDBX_SAFE_NOSYNC. Because MDBX will
* not reused paged from the last "steady" MVCC-snapshot and later, i.e. the * reused pages only before the last "steady" MVCC-snapshot, i.e. the loop
* loop length of database pages circulation will be mostly defined by frequency * length of database pages circulation will be mostly defined by frequency of
* of calling mdbx_env_sync() rather than LIFO and FIFO difference. * calling mdbx_env_sync() rather than LIFO and FIFO difference.
* *
* This flag may be changed at any time using mdbx_env_set_flags(). */ * This flag may be changed at any time using mdbx_env_set_flags(). */
#define MDBX_LIFORECLAIM 0x4000000u #define MDBX_LIFORECLAIM 0x4000000u
@ -1084,12 +1084,12 @@ LIBMDBX_API const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
#define MDBX_PAGEPERTURB 0x8000000u #define MDBX_PAGEPERTURB 0x8000000u
/**** SYNC MODES *************************************************************** /**** SYNC MODES ***************************************************************
* (!!!) Using any combination of MDBX_NOSYNC, MDBX_NOMETASYNC, MDBX_MAPASYNC * (!!!) Using any combination of MDBX_SAFE_NOSYNC, MDBX_NOMETASYNC,
* and especially MDBX_UTTERLY_NOSYNC is always a deal to reduce durability * MDBX_MAPASYNC and especially MDBX_UTTERLY_NOSYNC is always a deal to reduce
* for gain write performance. You must know exactly what you are doing and * durability for gain write performance. You must know exactly what you are
* what risks you are taking! * doing and what risks you are taking!
* *
* NOTE for LMDB users: MDBX_NOSYNC is NOT similar to LMDB_NOSYNC, but * NOTE for LMDB users: MDBX_SAFE_NOSYNC is NOT similar to LMDB_NOSYNC, but
* MDBX_UTTERLY_NOSYNC is exactly match LMDB_NOSYNC. * MDBX_UTTERLY_NOSYNC is exactly match LMDB_NOSYNC.
* See details below. * See details below.
* *
@ -1179,24 +1179,25 @@ LIBMDBX_API const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
* for particular write transaction. * for particular write transaction.
* *
* *
* MDBX_NOSYNC = don't sync anything but keep previous steady commits. * MDBX_SAFE_NOSYNC = don't sync anything but keep previous steady commits.
* *
* Like MDBX_UTTERLY_NOSYNC the MDBX_NOSYNC flag similarly disable flush * Like MDBX_UTTERLY_NOSYNC the MDBX_SAFE_NOSYNC flag similarly disable
* system buffers to disk when committing a transaction. But there is a * flush system buffers to disk when committing a transaction. But there
* huge difference in how are recycled the MVCC snapshots corresponding * is a huge difference in how are recycled the MVCC snapshots
* to previous "steady" transactions (see below). * corresponding to previous "steady" transactions (see below).
* *
* Depending on the platform and hardware, with MDBX_NOSYNC you may get * Depending on the platform and hardware, with MDBX_SAFE_NOSYNC you may
* a multiple increase of write performance, even 10 times or more. * get a multiple increase of write performance, even 10 times or more.
* NOTE that (MDBX_NOSYNC | MDBX_WRITEMAP) leaves the system with no hint * NOTE that (MDBX_SAFE_NOSYNC | MDBX_WRITEMAP) leaves the system with no
* for when to write transactions to disk. Therefore the (MDBX_MAPASYNC | * hint for when to write transactions to disk. Therefore the
* MDBX_WRITEMAP) may be preferable, but without MDBX_NOSYNC because * (MDBX_MAPASYNC | MDBX_WRITEMAP) may be preferable, but without
* the (MDBX_MAPASYNC | MDBX_NOSYNC) actually gives MDBX_UTTERLY_NOSYNC. * MDBX_SAFE_NOSYNC because the (MDBX_MAPASYNC | MDBX_SAFE_NOSYNC) actually
* gives MDBX_UTTERLY_NOSYNC.
* *
* In contrast to MDBX_UTTERLY_NOSYNC mode, with MDBX_NOSYNC flag MDBX will * In contrast to MDBX_UTTERLY_NOSYNC mode, with MDBX_SAFE_NOSYNC flag MDBX
* keeps untouched pages within B-tree of the last transaction "steady" * will keeps untouched pages within B-tree of the last transaction
* which was synced to disk completely. This has big implications for both * "steady" which was synced to disk completely. This has big implications
* data durability and (unfortunately) performance: * for both data durability and (unfortunately) performance:
* - a system crash can't corrupt the database, but you will lose the * - a system crash can't corrupt the database, but you will lose the
* last transactions; because MDBX will rollback to last steady commit * last transactions; because MDBX will rollback to last steady commit
* since it kept explicitly. * since it kept explicitly.
@ -1209,22 +1210,22 @@ LIBMDBX_API const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
* insufficient space and before increasing the size of the file on * insufficient space and before increasing the size of the file on
* disk. * disk.
* *
* In other words, with MDBX_NOSYNC flag MDBX insures you from the whole * In other words, with MDBX_SAFE_NOSYNC flag MDBX insures you from the
* database corruption, at the cost increasing database size and/or number * whole database corruption, at the cost increasing database size and/or
* of disk IOPS. So, MDBX_NOSYNC flag could be used with mdbx_env_synv() * number of disk IOPS. So, MDBX_SAFE_NOSYNC flag could be used with
* as alternatively for batch committing or nested transaction (in some * mdbx_env_synv() as alternatively for batch committing or nested
* cases). As well, auto-sync feature exposed by mdbx_env_set_syncbytes() * transaction (in some cases). As well, auto-sync feature exposed by
* and mdbx_env_set_syncperiod() functions could be very usefull with * mdbx_env_set_syncbytes() and mdbx_env_set_syncperiod() functions could
* MDBX_NOSYNC flag. * be very usefull with MDBX_SAFE_NOSYNC flag.
* *
* The number and volume of of disk IOPS with MDBX_NOSYNC flag will * The number and volume of of disk IOPS with MDBX_SAFE_NOSYNC flag will
* exactly the as without any no-sync flags. However, you should expect * exactly the as without any no-sync flags. However, you should expect a
* a larger process's work set (https://bit.ly/2kA2tFX) and significantly * larger process's work set (https://bit.ly/2kA2tFX) and significantly
* worse a locality of reference (https://bit.ly/2mbYq2J), due to the * worse a locality of reference (https://bit.ly/2mbYq2J), due to the more
* more intensive allocation of previously unused pages and increase the * intensive allocation of previously unused pages and increase the size of
* size of the database. * the database.
* *
* MDBX_NOSYNC flag may be changed at any time using * MDBX_SAFE_NOSYNC flag may be changed at any time using
* mdbx_env_set_flags() or by passing to mdbx_txn_begin() for particular * mdbx_env_set_flags() or by passing to mdbx_txn_begin() for particular
* write transaction. * write transaction.
* *
@ -1232,12 +1233,13 @@ LIBMDBX_API const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
* MDBX_MAPASYNC = use asynchronous msync when MDBX_WRITEMAP is used. * MDBX_MAPASYNC = use asynchronous msync when MDBX_WRITEMAP is used.
* *
* MDBX_MAPASYNC meaningful and give effect only in conjunction * MDBX_MAPASYNC meaningful and give effect only in conjunction
* with MDBX_WRITEMAP or MDBX_NOSYNC: * with MDBX_WRITEMAP or MDBX_SAFE_NOSYNC:
* - with MDBX_NOSYNC actually gives MDBX_UTTERLY_NOSYNC, which * - with MDBX_SAFE_NOSYNC actually gives MDBX_UTTERLY_NOSYNC, which
* wipe previous steady commits for reuse pages as described above. * wipe previous steady commits for reuse pages as described above.
* - with MDBX_WRITEMAP but without MDBX_NOSYNC instructs MDBX to use * - with MDBX_WRITEMAP but without MDBX_SAFE_NOSYNC instructs MDBX to use
* asynchronous mmap-flushes to disk as described below. * asynchronous mmap-flushes to disk as described below.
* - with both MDBX_WRITEMAP and MDBX_NOSYNC you get the both effects. * - with both MDBX_WRITEMAP and MDBX_SAFE_NOSYNC you get the both
* effects.
* *
* Asynchronous mmap-flushes means that actually all writes will scheduled * Asynchronous mmap-flushes means that actually all writes will scheduled
* and performed by operation system on it own manner, i.e. unordered. * and performed by operation system on it own manner, i.e. unordered.
@ -1245,10 +1247,10 @@ LIBMDBX_API const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
* data to disk, but no more. * data to disk, but no more.
* *
* With MDBX_MAPASYNC flag, but without MDBX_UTTERLY_NOSYNC (i.e. without * With MDBX_MAPASYNC flag, but without MDBX_UTTERLY_NOSYNC (i.e. without
* OR'ing with MDBX_NOSYNC) MDBX will keeps untouched pages within B-tree * OR'ing with MDBX_SAFE_NOSYNC) MDBX will keeps untouched pages within
* of the last transaction "steady" which was synced to disk completely. * B-tree of the last transaction "steady" which was synced to disk
* So, this makes exactly the same "long-lived" impact and the same * completely. So, this makes exactly the same "long-lived" impact and the
* consequences as described above for MDBX_NOSYNC flag. * same consequences as described above for MDBX_SAFE_NOSYNC flag.
* *
* Depending on the platform and hardware, with combination of * Depending on the platform and hardware, with combination of
* MDBX_WRITEMAP and MDBX_MAPASYNC you may get a multiple increase of write * MDBX_WRITEMAP and MDBX_MAPASYNC you may get a multiple increase of write
@ -1266,18 +1268,18 @@ LIBMDBX_API const char *mdbx_dump_val(const MDBX_val *key, char *const buf,
* *
* (!) don't combine this flag with MDBX_MAPASYNC * (!) don't combine this flag with MDBX_MAPASYNC
* since you will got MDBX_UTTERLY_NOSYNC in that way (see below) */ * since you will got MDBX_UTTERLY_NOSYNC in that way (see below) */
#define MDBX_NOSYNC 0x10000u #define MDBX_SAFE_NOSYNC 0x10000u
/* Use asynchronous msync when MDBX_WRITEMAP is used, /* Use asynchronous msync when MDBX_WRITEMAP is used,
* see description in the "SYNC MODES" section above. * see description in the "SYNC MODES" section above.
* *
* (!) don't combine this flag with MDBX_NOSYNC * (!) don't combine this flag with MDBX_SAFE_NOSYNC
* since you will got MDBX_UTTERLY_NOSYNC in that way (see below) */ * since you will got MDBX_UTTERLY_NOSYNC in that way (see below) */
#define MDBX_MAPASYNC 0x100000u #define MDBX_MAPASYNC 0x100000u
/* Don't sync anything and wipe previous steady commits, /* Don't sync anything and wipe previous steady commits,
* see description in the "SYNC MODES" section above. */ * see description in the "SYNC MODES" section above. */
#define MDBX_UTTERLY_NOSYNC (MDBX_NOSYNC | MDBX_MAPASYNC) #define MDBX_UTTERLY_NOSYNC (MDBX_SAFE_NOSYNC | MDBX_MAPASYNC)
/**** DATABASE FLAGS **********************************************************/ /**** DATABASE FLAGS **********************************************************/
/* Use reverse string keys */ /* Use reverse string keys */
@ -1514,14 +1516,14 @@ LIBMDBX_API int mdbx_env_create(MDBX_env **penv);
* MDBX_NORDAHEAD, MDBX_NOMEMINIT, MDBX_COALESCE, MDBX_LIFORECLAIM. * MDBX_NORDAHEAD, MDBX_NOMEMINIT, MDBX_COALESCE, MDBX_LIFORECLAIM.
* See "ENVIRONMENT FLAGS" section above. * See "ENVIRONMENT FLAGS" section above.
* *
* - MDBX_NOMETASYNC, MDBX_NOSYNC, MDBX_UTTERLY_NOSYNC, MDBX_MAPASYNC. * - MDBX_NOMETASYNC, MDBX_SAFE_NOSYNC, MDBX_UTTERLY_NOSYNC, MDBX_MAPASYNC.
* See "SYNC MODES" section above. * See "SYNC MODES" section above.
* *
* NOTE: MDB_NOLOCK flag don't supported by MDBX, * NOTE: MDB_NOLOCK flag don't supported by MDBX,
* try use MDBX_EXCLUSIVE as a replacement. * try use MDBX_EXCLUSIVE as a replacement.
* *
* NOTE: MDBX don't allow to mix processes with different MDBX_WRITEMAP, * NOTE: MDBX don't allow to mix processes with different MDBX_WRITEMAP,
* MDBX_NOSYNC, MDBX_NOMETASYNC, MDBX_MAPASYNC flags onthe same * MDBX_SAFE_NOSYNC, MDBX_NOMETASYNC, MDBX_MAPASYNC flags on the same
* environment. In such case MDBX_INCOMPATIBLE will be returned. * environment. In such case MDBX_INCOMPATIBLE will be returned.
* *
* If the database is already exist and parameters specified early by * If the database is already exist and parameters specified early by
@ -1547,7 +1549,7 @@ LIBMDBX_API int mdbx_env_create(MDBX_env **penv);
* more than once. * more than once.
* - MDBX_INCOMPATIBLE = Environment is already opened by another process, * - MDBX_INCOMPATIBLE = Environment is already opened by another process,
* but with different set of MDBX_WRITEMAP, * but with different set of MDBX_WRITEMAP,
* MDBX_NOSYNC, MDBX_NOMETASYNC, MDBX_MAPASYNC * MDBX_SAFE_NOSYNC, MDBX_NOMETASYNC, MDBX_MAPASYNC
* flags. * flags.
* Or if the database is already exist and * Or if the database is already exist and
* parameters specified early by * parameters specified early by
@ -1722,7 +1724,7 @@ __deprecated LIBMDBX_API int mdbx_env_info(MDBX_env *env, MDBX_envinfo *info,
/* Flush the environment data buffers to disk. /* Flush the environment data buffers to disk.
* *
* Unless the environment was opened with no-sync flags (MDBX_NOMETASYNC, * Unless the environment was opened with no-sync flags (MDBX_NOMETASYNC,
* MDBX_NOSYNC, MDBX_UTTERLY_NOSYNC and MDBX_MAPASYNC), then data is always * MDBX_SAFE_NOSYNC, MDBX_UTTERLY_NOSYNC and MDBX_MAPASYNC), then data is always
* written an flushed to disk when mdbx_txn_commit() is called. Otherwise * written an flushed to disk when mdbx_txn_commit() is called. Otherwise
* mdbx_env_sync() may be called to manually write and flush unsynced data to * mdbx_env_sync() may be called to manually write and flush unsynced data to
* disk. * disk.
@ -1758,14 +1760,15 @@ LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock);
LIBMDBX_API int mdbx_env_sync(MDBX_env *env); LIBMDBX_API int mdbx_env_sync(MDBX_env *env);
LIBMDBX_API int mdbx_env_sync_poll(MDBX_env *env); LIBMDBX_API int mdbx_env_sync_poll(MDBX_env *env);
/* Sets threshold to force flush the data buffers to disk, even of MDBX_NOSYNC, /* Sets threshold to force flush the data buffers to disk, even of
* MDBX_NOMETASYNC and MDBX_MAPASYNC flags in the environment. The threshold * MDBX_SAFE_NOSYNC, MDBX_NOMETASYNC and MDBX_MAPASYNC flags in the environment.
* value affects all processes which operates with given environment until the * The threshold value affects all processes which operates with given
* last process close environment or a new value will be settled. * environment until the last process close environment or a new value will be
* settled.
* *
* Data is always written to disk when mdbx_txn_commit() is called, but the * Data is always written to disk when mdbx_txn_commit() is called, but the
* operating system may keep it buffered. MDBX always flushes the OS buffers * operating system may keep it buffered. MDBX always flushes the OS buffers
* upon commit as well, unless the environment was opened with MDBX_NOSYNC, * upon commit as well, unless the environment was opened with MDBX_SAFE_NOSYNC,
* MDBX_MAPASYNC or in part MDBX_NOMETASYNC. * MDBX_MAPASYNC or in part MDBX_NOMETASYNC.
* *
* The default is 0, than mean no any threshold checked, and no additional * The default is 0, than mean no any threshold checked, and no additional
@ -1779,14 +1782,14 @@ LIBMDBX_API int mdbx_env_sync_poll(MDBX_env *env);
LIBMDBX_API int mdbx_env_set_syncbytes(MDBX_env *env, size_t threshold); LIBMDBX_API int mdbx_env_set_syncbytes(MDBX_env *env, size_t threshold);
/* Sets relative period since the last unsteay commit to force flush the data /* Sets relative period since the last unsteay commit to force flush the data
* buffers to disk, even of MDBX_NOSYNC, MDBX_NOMETASYNC and MDBX_MAPASYNC flags * buffers to disk, even of MDBX_SAFE_NOSYNC, MDBX_NOMETASYNC and MDBX_MAPASYNC
* in the environment. The relative period value affects all processes which * flags in the environment. The relative period value affects all processes
* operates with given environment until the last process close environment or a * which operates with given environment until the last process close
* new value will be settled. * environment or a new value will be settled.
* *
* Data is always written to disk when mdbx_txn_commit() is called, but the * Data is always written to disk when mdbx_txn_commit() is called, but the
* operating system may keep it buffered. MDBX always flushes the OS buffers * operating system may keep it buffered. MDBX always flushes the OS buffers
* upon commit as well, unless the environment was opened with MDBX_NOSYNC, * upon commit as well, unless the environment was opened with MDBX_SAFE_NOSYNC,
* MDBX_MAPASYNC or in part MDBX_NOMETASYNC. * MDBX_MAPASYNC or in part MDBX_NOMETASYNC.
* *
* Settled period don't checked asynchronously, but only by the * Settled period don't checked asynchronously, but only by the
@ -2218,9 +2221,9 @@ LIBMDBX_API void *mdbx_env_get_userctx(MDBX_env *env);
* - MDBX_TRYTXN * - MDBX_TRYTXN
* Do not block when starting a write transaction. * Do not block when starting a write transaction.
* *
* - MDBX_NOSYNC, MDBX_NOMETASYNC or MDBX_MAPASYNC * - MDBX_SAFE_NOSYNC, MDBX_NOMETASYNC or MDBX_MAPASYNC
* Do not sync data to disk corresponding to MDBX_NOMETASYNC * Do not sync data to disk corresponding to MDBX_NOMETASYNC
* or MDBX_NOSYNC description (see abobe). * or MDBX_SAFE_NOSYNC description (see abobe).
* *
* [out] txn Address where the new MDBX_txn handle will be stored * [out] txn Address where the new MDBX_txn handle will be stored
* *

View File

@ -4631,7 +4631,7 @@ __cold int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock) {
if (outside_txn) { if (outside_txn) {
if (unsynced_pages > /* FIXME: define threshold */ 16 && if (unsynced_pages > /* FIXME: define threshold */ 16 &&
(flags & (MDBX_NOSYNC | MDBX_MAPASYNC)) == 0) { (flags & (MDBX_SAFE_NOSYNC | MDBX_MAPASYNC)) == 0) {
mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0); mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0);
const size_t usedbytes = pgno_align2os_bytes(env, head->mm_geo.next); const size_t usedbytes = pgno_align2os_bytes(env, head->mm_geo.next);
@ -4658,7 +4658,7 @@ __cold int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock) {
} }
if (!META_IS_STEADY(head) || if (!META_IS_STEADY(head) ||
((flags & (MDBX_NOSYNC | MDBX_MAPASYNC)) == 0 && unsynced_pages)) { ((flags & (MDBX_SAFE_NOSYNC | MDBX_MAPASYNC)) == 0 && unsynced_pages)) {
mdbx_debug("meta-head %" PRIaPGNO ", %s, sync_pending %" PRIaPGNO, mdbx_debug("meta-head %" PRIaPGNO ", %s, sync_pending %" PRIaPGNO,
data_page(head)->mp_pgno, mdbx_durable_str(head), data_page(head)->mp_pgno, mdbx_durable_str(head),
unsynced_pages); unsynced_pages);
@ -5329,9 +5329,10 @@ int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, unsigned flags,
if (txn != env->me_txn0) if (txn != env->me_txn0)
mdbx_free(txn); mdbx_free(txn);
} else { } else {
mdbx_assert(env, (txn->mt_flags & mdbx_assert(env,
(txn->mt_flags &
~(MDBX_RDONLY | MDBX_WRITEMAP | MDBX_SHRINK_ALLOWED | ~(MDBX_RDONLY | MDBX_WRITEMAP | MDBX_SHRINK_ALLOWED |
MDBX_NOMETASYNC | MDBX_NOSYNC | MDBX_MAPASYNC)) == 0); MDBX_NOMETASYNC | MDBX_SAFE_NOSYNC | MDBX_MAPASYNC)) == 0);
txn->mt_signature = MDBX_MT_SIGNATURE; txn->mt_signature = MDBX_MT_SIGNATURE;
*ret = txn; *ret = txn;
mdbx_debug("begin txn %" PRIaTXN "%c %p on env %p, root page %" PRIaPGNO mdbx_debug("begin txn %" PRIaTXN "%c %p on env %p, root page %" PRIaPGNO
@ -7396,7 +7397,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
mdbx_assert(env, (env->me_flags & (MDBX_RDONLY | MDBX_FATAL_ERROR)) == 0); mdbx_assert(env, (env->me_flags & (MDBX_RDONLY | MDBX_FATAL_ERROR)) == 0);
mdbx_assert(env, pending->mm_geo.next <= pending->mm_geo.now); mdbx_assert(env, pending->mm_geo.next <= pending->mm_geo.now);
if (flags & (MDBX_NOSYNC | MDBX_MAPASYNC)) { if (flags & (MDBX_SAFE_NOSYNC | MDBX_MAPASYNC)) {
/* Check auto-sync conditions */ /* Check auto-sync conditions */
const pgno_t autosync_threshold = *env->me_autosync_threshold; const pgno_t autosync_threshold = *env->me_autosync_threshold;
const uint64_t autosync_period = *env->me_autosync_period; const uint64_t autosync_period = *env->me_autosync_period;
@ -7488,7 +7489,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
/* LY: step#1 - sync previously written/updated data-pages */ /* LY: step#1 - sync previously written/updated data-pages */
int rc = *env->me_unsynced_pages ? MDBX_RESULT_TRUE /* carry non-steady */ int rc = *env->me_unsynced_pages ? MDBX_RESULT_TRUE /* carry non-steady */
: MDBX_RESULT_FALSE /* carry steady */; : MDBX_RESULT_FALSE /* carry steady */;
if (rc != MDBX_RESULT_FALSE && (flags & MDBX_NOSYNC) == 0) { if (rc != MDBX_RESULT_FALSE && (flags & MDBX_SAFE_NOSYNC) == 0) {
mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0); mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0);
MDBX_meta *const recent_steady_meta = mdbx_meta_steady(env); MDBX_meta *const recent_steady_meta = mdbx_meta_steady(env);
if (flags & MDBX_WRITEMAP) { if (flags & MDBX_WRITEMAP) {
@ -7642,7 +7643,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
/* LY: step#3 - sync meta-pages. */ /* LY: step#3 - sync meta-pages. */
mdbx_assert(env, ((env->me_flags ^ flags) & MDBX_WRITEMAP) == 0); mdbx_assert(env, ((env->me_flags ^ flags) & MDBX_WRITEMAP) == 0);
if ((flags & (MDBX_NOSYNC | MDBX_NOMETASYNC)) == 0) { if ((flags & (MDBX_SAFE_NOSYNC | MDBX_NOMETASYNC)) == 0) {
mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0); mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0);
if (flags & MDBX_WRITEMAP) { if (flags & MDBX_WRITEMAP) {
const size_t offset = (uint8_t *)data_page(head) - env->me_dxb_mmap.dxb; const size_t offset = (uint8_t *)data_page(head) - env->me_dxb_mmap.dxb;
@ -8873,7 +8874,7 @@ __cold int mdbx_is_readahead_reasonable(size_t volume, intptr_t redundancy) {
* at runtime. Changing other flags requires closing the * at runtime. Changing other flags requires closing the
* environment and re-opening it with the new flags. */ * environment and re-opening it with the new flags. */
#define CHANGEABLE \ #define CHANGEABLE \
(MDBX_NOSYNC | MDBX_NOMETASYNC | MDBX_MAPASYNC | MDBX_NOMEMINIT | \ (MDBX_SAFE_NOSYNC | MDBX_NOMETASYNC | MDBX_MAPASYNC | MDBX_NOMEMINIT | \
MDBX_COALESCE | MDBX_PAGEPERTURB | MDBX_ACCEDE) MDBX_COALESCE | MDBX_PAGEPERTURB | MDBX_ACCEDE)
#define CHANGELESS \ #define CHANGELESS \
(MDBX_NOSUBDIR | MDBX_RDONLY | MDBX_WRITEMAP | MDBX_NOTLS | MDBX_NORDAHEAD | \ (MDBX_NOSUBDIR | MDBX_RDONLY | MDBX_WRITEMAP | MDBX_NOTLS | MDBX_NORDAHEAD | \
@ -8924,7 +8925,8 @@ int __cold mdbx_env_open(MDBX_env *env, const char *path, unsigned flags,
if (flags & MDBX_RDONLY) { if (flags & MDBX_RDONLY) {
/* LY: silently ignore irrelevant flags when /* LY: silently ignore irrelevant flags when
* we're only getting read access */ * we're only getting read access */
flags &= ~(MDBX_WRITEMAP | MDBX_MAPASYNC | MDBX_NOSYNC | MDBX_NOMETASYNC | flags &=
~(MDBX_WRITEMAP | MDBX_MAPASYNC | MDBX_SAFE_NOSYNC | MDBX_NOMETASYNC |
MDBX_COALESCE | MDBX_LIFORECLAIM | MDBX_NOMEMINIT | MDBX_ACCEDE); MDBX_COALESCE | MDBX_LIFORECLAIM | MDBX_NOMEMINIT | MDBX_ACCEDE);
} else { } else {
#ifdef __OpenBSD__ #ifdef __OpenBSD__
@ -9022,7 +9024,8 @@ int __cold mdbx_env_open(MDBX_env *env, const char *path, unsigned flags,
goto bailout; goto bailout;
} }
const unsigned rigorous_flags = MDBX_WRITEMAP | MDBX_NOSYNC | MDBX_MAPASYNC; const unsigned rigorous_flags =
MDBX_WRITEMAP | MDBX_SAFE_NOSYNC | MDBX_MAPASYNC;
const unsigned mode_flags = rigorous_flags | MDBX_NOMETASYNC | const unsigned mode_flags = rigorous_flags | MDBX_NOMETASYNC |
MDBX_LIFORECLAIM | MDBX_COALESCE | MDBX_NORDAHEAD; MDBX_LIFORECLAIM | MDBX_COALESCE | MDBX_NORDAHEAD;

View File

@ -703,7 +703,8 @@ struct MDBX_txn {
/* Transaction Flags */ /* Transaction Flags */
/* mdbx_txn_begin() flags */ /* mdbx_txn_begin() flags */
#define MDBX_TXN_BEGIN_FLAGS \ #define MDBX_TXN_BEGIN_FLAGS \
(MDBX_NOMETASYNC | MDBX_NOSYNC | MDBX_MAPASYNC | MDBX_RDONLY | MDBX_TRYTXN) (MDBX_NOMETASYNC | MDBX_SAFE_NOSYNC | MDBX_MAPASYNC | MDBX_RDONLY | \
MDBX_TRYTXN)
/* internal txn flags */ /* internal txn flags */
#define MDBX_TXN_FINISHED 0x01 /* txn is finished or never began */ #define MDBX_TXN_FINISHED 0x01 /* txn is finished or never began */
#define MDBX_TXN_ERROR 0x02 /* txn is unusable after an error */ #define MDBX_TXN_ERROR 0x02 /* txn is unusable after an error */

View File

@ -296,9 +296,9 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
const struct option_verb mode_bits[] = {{"rdonly", MDBX_RDONLY}, const struct option_verb mode_bits[] = {{"rdonly", MDBX_RDONLY},
{"mapasync", MDBX_MAPASYNC}, {"mapasync", MDBX_MAPASYNC},
{"utterly", MDBX_UTTERLY_NOSYNC}, {"nosync-utterly", MDBX_UTTERLY_NOSYNC},
{"nosubdir", MDBX_NOSUBDIR}, {"nosubdir", MDBX_NOSUBDIR},
{"nosync", MDBX_NOSYNC}, {"nosync-safe", MDBX_SAFE_NOSYNC},
{"nometasync", MDBX_NOMETASYNC}, {"nometasync", MDBX_NOMETASYNC},
{"writemap", MDBX_WRITEMAP}, {"writemap", MDBX_WRITEMAP},
{"notls", MDBX_NOTLS}, {"notls", MDBX_NOTLS},

View File

@ -92,10 +92,10 @@ void __noreturn usage(void) {
" nometasync == MDBX_NOMETASYNC\n" " nometasync == MDBX_NOMETASYNC\n"
" lifo == MDBX_LIFORECLAIM\n" " lifo == MDBX_LIFORECLAIM\n"
" coalesce == MDBX_COALESCE\n" " coalesce == MDBX_COALESCE\n"
" nosync == MDBX_NOSYNC\n" " nosync-safe == MDBX_SAFE_NOSYNC\n"
" writemap == MDBX_WRITEMAP\n" " writemap == MDBX_WRITEMAP\n"
" mapasync == MDBX_MAPASYNC\n" " mapasync == MDBX_MAPASYNC\n"
" utterly == MDBX_UTTERLY_NOSYNC\n" " nosync-utterly == MDBX_UTTERLY_NOSYNC\n"
" perturb == MDBX_PAGEPERTURB\n" " perturb == MDBX_PAGEPERTURB\n"
" notls == MDBX_NOTLS\n" " notls == MDBX_NOTLS\n"
" nordahead == MDBX_NORDAHEAD\n" " nordahead == MDBX_NORDAHEAD\n"

View File

@ -70,7 +70,8 @@ static unsigned edge2count(uint64_t edge, unsigned count_max) {
void testcase_nested::push_txn() { void testcase_nested::push_txn() {
MDBX_txn *txn; MDBX_txn *txn;
unsigned flags = prng32() & (MDBX_NOSYNC | MDBX_NOMETASYNC | MDBX_MAPASYNC); unsigned flags =
prng32() & (MDBX_SAFE_NOSYNC | MDBX_NOMETASYNC | MDBX_MAPASYNC);
int err = mdbx_txn_begin(db_guard.get(), txn_guard.get(), flags, &txn); int err = mdbx_txn_begin(db_guard.get(), txn_guard.get(), flags, &txn);
if (unlikely(err != MDBX_SUCCESS)) if (unlikely(err != MDBX_SUCCESS))
failure_perror("mdbx_txn_begin(nested)", err); failure_perror("mdbx_txn_begin(nested)", err);

View File

@ -110,7 +110,7 @@ static void db_connect() {
MDBX_CHECK(mdbx_env_set_maxdbs(env, 30)); MDBX_CHECK(mdbx_env_set_maxdbs(env, 30));
MDBX_CHECK(mdbx_env_open(env, opt_db_path, MDBX_CHECK(mdbx_env_open(env, opt_db_path,
MDBX_CREATE | MDBX_WRITEMAP | MDBX_MAPASYNC | MDBX_CREATE | MDBX_WRITEMAP | MDBX_MAPASYNC |
MDBX_NOSYNC | MDBX_LIFORECLAIM, MDBX_SAFE_NOSYNC | MDBX_LIFORECLAIM,
0664)); 0664));
MDBX_txn *txn; MDBX_txn *txn;