mdbx: use enums & bool in the C API.

Change-Id: I952f578cceb7d02ade16f545d47245d4d9106441
This commit is contained in:
Leonid Yuriev 2020-08-04 01:06:01 +03:00
parent 3bcf808005
commit ffa10a25d6
15 changed files with 124 additions and 99 deletions

View File

@ -75,7 +75,7 @@ int main(int argc, char *argv[]) {
}
txn = NULL;
rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn);
rc = mdbx_txn_begin(env, NULL, MDBX_TXN_RDONLY, &txn);
if (rc != MDBX_SUCCESS) {
fprintf(stderr, "mdbx_txn_begin: (%d) %s\n", rc, mdbx_strerror(rc));
goto bailout;

57
mdbx.h
View File

@ -1526,7 +1526,7 @@ LIBMDBX_API int mdbx_env_create(MDBX_env **penv);
* i.e. 32-bit process tries to open >4Gb database.
*/
LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *pathname,
unsigned flags, mode_t mode);
MDBX_env_flags_t flags, mode_t mode);
/** Copy an MDBX environment to the specified path, with options.
* \ingroup c_extra
@ -1556,7 +1556,8 @@ LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *pathname,
* Force to make resizeable copy, i.e. dynamic size instead of fixed.
*
* \returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest, unsigned flags);
LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest,
MDBX_copy_flags_t flags);
/** Copy an MDBX environment to the specified file descriptor, with options.
* \ingroup c_extra
@ -1582,7 +1583,7 @@ LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest, unsigned flags);
*
* \returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_env_copy2fd(MDBX_env *env, mdbx_filehandle_t fd,
unsigned flags);
MDBX_copy_flags_t flags);
/** Statistics for a database in the environment
* \ingroup c_statinfo */
@ -1748,7 +1749,7 @@ MDBX_DEPRECATED LIBMDBX_API int mdbx_env_info(MDBX_env *env, MDBX_envinfo *info,
* and `nonblock=true`.
* \retval MDBX_EINVAL an invalid parameter was specified.
* \retval MDBX_EIO an error occurred during synchronization. */
LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock);
LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, bool force, bool nonblock);
/** The shortcut to calling \ref mdbx_env_sync_ex() with
* the `force=true` and `nonblock=false` arguments.
@ -1853,7 +1854,7 @@ LIBMDBX_API int mdbx_env_set_syncperiod(MDBX_env *env,
* proper manner.
*
* \retval MDBX_EIO An error occurred during synchronization. */
LIBMDBX_API int mdbx_env_close_ex(MDBX_env *env, int dont_sync);
LIBMDBX_API int mdbx_env_close_ex(MDBX_env *env, bool dont_sync);
/** The shortcut to calling \ref mdbx_env_close_ex() with
* the `dont_sync=false` argument.
@ -1880,7 +1881,8 @@ LIBMDBX_API int mdbx_env_close(MDBX_env *env);
* \returns A non-zero error value on failure and 0 on success,
* some possible errors are:
* \retval MDBX_EINVAL An invalid parameter was specified. */
LIBMDBX_API int mdbx_env_set_flags(MDBX_env *env, unsigned flags, int onoff);
LIBMDBX_API int mdbx_env_set_flags(MDBX_env *env, MDBX_env_flags_t flags,
bool onoff);
/** Get environment flags.
* \ingroup c_statinfo
@ -2155,13 +2157,15 @@ LIBMDBX_API intptr_t mdbx_limits_dbsize_max(intptr_t pagesize);
* and database flags, or -1 if pagesize is invalid.
* \ingroup c_statinfo
* \see db_flags */
LIBMDBX_API intptr_t mdbx_limits_keysize_max(intptr_t pagesize, unsigned flags);
LIBMDBX_API intptr_t mdbx_limits_keysize_max(intptr_t pagesize,
MDBX_db_flags_t flags);
/** Returns maximal data size in bytes for given page size
* and database flags, or -1 if pagesize is invalid.
* \ingroup c_statinfo
* \see db_flags */
LIBMDBX_API intptr_t mdbx_limits_valsize_max(intptr_t pagesize, unsigned flags);
LIBMDBX_API intptr_t mdbx_limits_valsize_max(intptr_t pagesize,
MDBX_db_flags_t flags);
/** Returns maximal write transaction size (i.e. limit for summary volume of
* dirty pages) in bytes for given page size, or -1 if pagesize is invalid.
@ -2248,7 +2252,8 @@ LIBMDBX_API int mdbx_env_get_maxdbs(MDBX_env *env, MDBX_dbi *dbs);
*
* \returns The maximum size of a key can write,
* or -1 if something is wrong. */
LIBMDBX_API int mdbx_env_get_maxkeysize_ex(const MDBX_env *env, unsigned flags);
LIBMDBX_API int mdbx_env_get_maxkeysize_ex(const MDBX_env *env,
MDBX_db_flags_t flags);
/** Get the maximum size of data we can write.
* \ingroup c_statinfo
@ -2259,7 +2264,8 @@ LIBMDBX_API int mdbx_env_get_maxkeysize_ex(const MDBX_env *env, unsigned flags);
*
* \returns The maximum size of a data can write,
* or -1 if something is wrong. */
LIBMDBX_API int mdbx_env_get_maxvalsize_ex(const MDBX_env *env, unsigned flags);
LIBMDBX_API int mdbx_env_get_maxvalsize_ex(const MDBX_env *env,
MDBX_db_flags_t flags);
/** \deprecated Please use \ref mdbx_env_get_maxkeysize_ex()
* and/or \ref mdbx_env_get_maxvalsize_ex()
@ -2334,8 +2340,8 @@ LIBMDBX_API void *mdbx_env_get_userctx(const MDBX_env *env);
* \retval MDBX_ENOMEM Out of memory.
* \retval MDBX_BUSY The write transaction is already started by the
* current thread. */
LIBMDBX_API int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, unsigned flags,
MDBX_txn **txn);
LIBMDBX_API int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent,
MDBX_txn_flags_t flags, MDBX_txn **txn);
/** Information about the transaction
* \ingroup c_statinfo */
@ -2712,8 +2718,8 @@ typedef int(MDBX_cmp_func)(const MDBX_val *a, const MDBX_val *b);
* opened with a different comparison function(s).
* \retval MDBX_THREAD_MISMATCH Given transaction is not owned
* by current thread. */
LIBMDBX_API int mdbx_dbi_open(MDBX_txn *txn, const char *name, unsigned flags,
MDBX_dbi *dbi);
LIBMDBX_API int mdbx_dbi_open(MDBX_txn *txn, const char *name,
MDBX_db_flags_t flags, MDBX_dbi *dbi);
/** \deprecated Please avoid using custom comparators
* and use mdbx_dbi_open() instead.
@ -2729,8 +2735,8 @@ LIBMDBX_API int mdbx_dbi_open(MDBX_txn *txn, const char *name, unsigned flags,
* \param [out] dbi Address where the new MDBX_dbi handle will be stored.
* \returns A non-zero error value on failure and 0 on success. */
MDBX_DEPRECATED LIBMDBX_API int
mdbx_dbi_open_ex(MDBX_txn *txn, const char *name, unsigned flags, MDBX_dbi *dbi,
MDBX_cmp_func *keycmp, MDBX_cmp_func *datacmp);
mdbx_dbi_open_ex(MDBX_txn *txn, const char *name, MDBX_db_flags_t flags,
MDBX_dbi *dbi, MDBX_cmp_func *keycmp, MDBX_cmp_func *datacmp);
/** \defgroup value2key Value-to-Key functions to avoid custom comparators
* \see key2value
@ -3029,7 +3035,7 @@ LIBMDBX_API int mdbx_get_nearest(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
* in a read-only transaction.
* \retval MDBX_EINVAL An invalid parameter was specified. */
LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *data, unsigned flags);
MDBX_val *data, MDBX_put_flags_t flags);
/** Replace items in a database.
* \ingroup c_crud
@ -3074,7 +3080,7 @@ LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
* \returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_replace(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *new_data, MDBX_val *old_data,
unsigned flags);
MDBX_put_flags_t flags);
/** Delete items from a database.
* \ingroup c_crud
@ -3281,7 +3287,7 @@ LIBMDBX_API int mdbx_cursor_get(MDBX_cursor *cursor, MDBX_val *key,
* transaction.
* \retval MDBX_EINVAL An invalid parameter was specified. */
LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key,
MDBX_val *data, unsigned flags);
MDBX_val *data, MDBX_put_flags_t flags);
/** Delete current key/data pair.
* \ingroup c_crud
@ -3309,7 +3315,7 @@ LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key,
* \retval MDBX_EACCES An attempt was made to write in a read-only
* transaction.
* \retval MDBX_EINVAL An invalid parameter was specified. */
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, unsigned flags);
LIBMDBX_API int mdbx_cursor_del(MDBX_cursor *cursor, MDBX_put_flags_t flags);
/** Return count of duplicates for current key.
* \ingroup c_crud
@ -3550,7 +3556,7 @@ LIBMDBX_API int mdbx_cmp(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
/** Returns default internal key's comparator for given database flags.
* \ingroup c_extra */
LIBMDBX_API MDBX_cmp_func *mdbx_get_keycmp(unsigned flags);
LIBMDBX_API MDBX_cmp_func *mdbx_get_keycmp(MDBX_db_flags_t flags);
/** Compare two data items according to a particular database.
* \ingroup c_crud
@ -3571,7 +3577,7 @@ LIBMDBX_API int mdbx_dcmp(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
/** Returns default internal data's comparator for given database flags
* \ingroup c_extra */
LIBMDBX_API MDBX_cmp_func *mdbx_get_datacmp(unsigned flags);
LIBMDBX_API MDBX_cmp_func *mdbx_get_datacmp(MDBX_db_flags_t flags);
/** A callback function used to enumerate the reader lock table.
* \ingroup c_statinfo
@ -3797,7 +3803,7 @@ MDBX_pgvisitor_func(const uint64_t pgno, const unsigned number, void *const ctx,
/** B-tree traversal function. */
LIBMDBX_API int mdbx_env_pgwalk(MDBX_txn *txn, MDBX_pgvisitor_func *visitor,
void *ctx, int dont_check_keys_ordering);
void *ctx, bool dont_check_keys_ordering);
/** @} B-tree Traversal */
/**** Attribute support functions for Nexenta
@ -3843,7 +3849,7 @@ typedef uint_fast64_t mdbx_attr_t;
* \retval MDBX_EINVAL an invalid parameter was specified. */
LIBMDBX_API int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key,
MDBX_val *data, mdbx_attr_t attr,
unsigned flags);
MDBX_put_flags_t flags);
/** Store items and attributes into a database.
*
@ -3889,7 +3895,8 @@ LIBMDBX_API int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key,
* in a read-only transaction.
* \retval MDBX_EINVAL An invalid parameter was specified. */
LIBMDBX_API int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
MDBX_val *data, mdbx_attr_t attr, unsigned flags);
MDBX_val *data, mdbx_attr_t attr,
MDBX_put_flags_t flags);
/** Set items attribute from a database.
*

View File

@ -338,14 +338,16 @@ __cold int mdbx_env_get_maxkeysize(const MDBX_env *env) {
return mdbx_env_get_maxkeysize_ex(env, MDBX_DUPSORT);
}
__cold int mdbx_env_get_maxkeysize_ex(const MDBX_env *env, unsigned flags) {
__cold int mdbx_env_get_maxkeysize_ex(const MDBX_env *env,
MDBX_db_flags_t flags) {
if (unlikely(!env || env->me_signature != MDBX_ME_SIGNATURE))
return -1;
return (int)mdbx_limits_keysize_max((intptr_t)env->me_psize, flags);
}
__cold intptr_t mdbx_limits_keysize_max(intptr_t pagesize, unsigned flags) {
__cold intptr_t mdbx_limits_keysize_max(intptr_t pagesize,
MDBX_db_flags_t flags) {
if (pagesize < 1)
pagesize = (intptr_t)mdbx_syspagesize();
if (unlikely(pagesize < (intptr_t)MIN_PAGESIZE ||
@ -370,14 +372,16 @@ __cold intptr_t mdbx_limits_keysize_max(intptr_t pagesize, unsigned flags) {
return BRANCH_NODEMAX(pagesize) - NODESIZE - sizeof(pgno_t);
}
__cold int mdbx_env_get_maxvalsize_ex(const MDBX_env *env, unsigned flags) {
__cold int mdbx_env_get_maxvalsize_ex(const MDBX_env *env,
MDBX_db_flags_t flags) {
if (unlikely(!env || env->me_signature != MDBX_ME_SIGNATURE))
return -1;
return (int)mdbx_limits_valsize_max((intptr_t)env->me_psize, flags);
}
__cold intptr_t mdbx_limits_valsize_max(intptr_t pagesize, unsigned flags) {
__cold intptr_t mdbx_limits_valsize_max(intptr_t pagesize,
MDBX_db_flags_t flags) {
if (pagesize < 1)
pagesize = (intptr_t)mdbx_syspagesize();
if (unlikely(pagesize < (intptr_t)MIN_PAGESIZE ||
@ -5612,8 +5616,8 @@ fail:
return rc;
}
__cold static int mdbx_env_sync_internal(MDBX_env *env, int force,
int nonblock) {
__cold static int mdbx_env_sync_internal(MDBX_env *env, bool force,
bool nonblock) {
unsigned flags = env->me_flags & ~MDBX_NOMETASYNC;
if (unlikely(flags & (MDBX_RDONLY | MDBX_FATAL_ERROR)))
return MDBX_EACCESS;
@ -5727,7 +5731,7 @@ static __inline int check_env(const MDBX_env *env) {
return MDBX_SUCCESS;
}
__cold int mdbx_env_sync_ex(MDBX_env *env, int force, int nonblock) {
__cold int mdbx_env_sync_ex(MDBX_env *env, bool force, bool nonblock) {
int rc = check_env(env);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -6352,7 +6356,7 @@ int mdbx_txn_renew(MDBX_txn *txn) {
return rc;
}
int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, unsigned flags,
int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, MDBX_txn_flags_t flags,
MDBX_txn **ret) {
MDBX_txn *txn;
unsigned size, tsize;
@ -10122,8 +10126,8 @@ static uint32_t merge_sync_flags(const uint32_t a, const uint32_t b) {
return r;
}
int __cold mdbx_env_open(MDBX_env *env, const char *pathname, unsigned flags,
mode_t mode) {
int __cold mdbx_env_open(MDBX_env *env, const char *pathname,
MDBX_env_flags_t flags, mode_t mode) {
int rc = check_env(env);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -10312,9 +10316,11 @@ int __cold mdbx_env_open(MDBX_env *env, const char *pathname, unsigned flags,
goto bailout;
}
const unsigned rigorous_flags = MDBX_SAFE_NOSYNC | MDBX_DEPRECATED_MAPASYNC;
const unsigned mode_flags = rigorous_flags | MDBX_NOMETASYNC |
MDBX_LIFORECLAIM | MDBX_COALESCE | MDBX_NORDAHEAD;
const MDBX_env_flags_t rigorous_flags =
MDBX_SAFE_NOSYNC | MDBX_DEPRECATED_MAPASYNC;
const MDBX_env_flags_t mode_flags = rigorous_flags | MDBX_NOMETASYNC |
MDBX_LIFORECLAIM | MDBX_COALESCE |
MDBX_NORDAHEAD;
if (env->me_lck && lck_rc != MDBX_RESULT_TRUE &&
(env->me_flags & MDBX_RDONLY) == 0) {
@ -10503,7 +10509,7 @@ static int __cold mdbx_env_close0(MDBX_env *env) {
return rc;
}
int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) {
int __cold mdbx_env_close_ex(MDBX_env *env, bool dont_sync) {
MDBX_page *dp;
int rc = MDBX_SUCCESS;
@ -12770,7 +12776,7 @@ fail:
return rc;
}
int mdbx_cursor_del(MDBX_cursor *mc, unsigned flags) {
int mdbx_cursor_del(MDBX_cursor *mc, MDBX_put_flags_t flags) {
if (unlikely(!mc))
return MDBX_EINVAL;
@ -16085,7 +16091,8 @@ int __cold mdbx_env_copy2fd(MDBX_env *env, mdbx_filehandle_t fd,
return rc;
}
int __cold mdbx_env_copy(MDBX_env *env, const char *dest_path, unsigned flags) {
int __cold mdbx_env_copy(MDBX_env *env, const char *dest_path,
MDBX_copy_flags_t flags) {
int rc = check_env(env);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -16120,7 +16127,8 @@ int __cold mdbx_env_copy(MDBX_env *env, const char *dest_path, unsigned flags) {
/******************************************************************************/
int __cold mdbx_env_set_flags(MDBX_env *env, unsigned flags, int onoff) {
int __cold mdbx_env_set_flags(MDBX_env *env, MDBX_env_flags_t flags,
bool onoff) {
int rc = check_env(env);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -16732,14 +16740,14 @@ static int dbi_open(MDBX_txn *txn, const char *table_name, unsigned user_flags,
return rc;
}
int mdbx_dbi_open(MDBX_txn *txn, const char *table_name, unsigned table_flags,
MDBX_dbi *dbi) {
int mdbx_dbi_open(MDBX_txn *txn, const char *table_name,
MDBX_db_flags_t table_flags, MDBX_dbi *dbi) {
return dbi_open(txn, table_name, table_flags, dbi, nullptr, nullptr);
}
int mdbx_dbi_open_ex(MDBX_txn *txn, const char *table_name,
unsigned table_flags, MDBX_dbi *dbi, MDBX_cmp_func *keycmp,
MDBX_cmp_func *datacmp) {
MDBX_db_flags_t table_flags, MDBX_dbi *dbi,
MDBX_cmp_func *keycmp, MDBX_cmp_func *datacmp) {
return dbi_open(txn, table_name, table_flags, dbi, keycmp, datacmp);
}
@ -17124,7 +17132,8 @@ int __cold mdbx_reader_check(MDBX_env *env, int *dead) {
* MDBX_RESULT_TRUE - done and mutex recovered
* MDBX_SUCCESS - done
* Otherwise errcode. */
int __cold mdbx_reader_check0(MDBX_env *env, int rdt_locked, int *dead) {
MDBX_INTERNAL_FUNC int __cold mdbx_reader_check0(MDBX_env *env, int rdt_locked,
int *dead) {
int rc = check_env(env);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -17701,7 +17710,7 @@ static int __cold mdbx_walk_sdb(mdbx_walk_ctx_t *ctx, MDBX_db *const db,
}
int __cold mdbx_env_pgwalk(MDBX_txn *txn, MDBX_pgvisitor_func *visitor,
void *user, int dont_check_keys_ordering) {
void *user, bool dont_check_keys_ordering) {
int rc = check_txn(txn, MDBX_TXN_BLOCKED);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -17711,7 +17720,7 @@ int __cold mdbx_env_pgwalk(MDBX_txn *txn, MDBX_pgvisitor_func *visitor,
ctx.mw_txn = txn;
ctx.mw_user = user;
ctx.mw_visitor = visitor;
ctx.mw_dont_check_keys_ordering = dont_check_keys_ordering != 0;
ctx.mw_dont_check_keys_ordering = dont_check_keys_ordering;
rc = visitor(0, NUM_METAS, user, 0, MDBX_PGWALK_META,
pgno2bytes(txn->mt_env, NUM_METAS), MDBX_page_meta, NUM_METAS,
@ -18225,7 +18234,8 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
* - получения статуса страницы по адресу (знать о P_DIRTY).
*/
int mdbx_replace(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *new_data, MDBX_val *old_data, unsigned flags) {
MDBX_val *new_data, MDBX_val *old_data,
MDBX_put_flags_t flags) {
int rc = check_txn_rw(txn, MDBX_TXN_BLOCKED);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
@ -18757,7 +18767,7 @@ static __inline int mdbx_attr_peek(MDBX_val *data, mdbx_attr_t *attrptr) {
}
static __inline int mdbx_attr_poke(MDBX_val *reserved, MDBX_val *data,
mdbx_attr_t attr, unsigned flags) {
mdbx_attr_t attr, MDBX_put_flags_t flags) {
mdbx_attr_t *space = reserved->iov_base;
if (flags & MDBX_RESERVE) {
if (likely(data != NULL)) {
@ -18792,7 +18802,7 @@ int mdbx_get_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
}
int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr, unsigned flags) {
mdbx_attr_t attr, MDBX_put_flags_t flags) {
MDBX_val reserve;
reserve.iov_base = NULL;
reserve.iov_len = (data ? data->iov_len : 0) + sizeof(mdbx_attr_t);
@ -18805,7 +18815,7 @@ int mdbx_put_attr(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
}
int mdbx_cursor_put_attr(MDBX_cursor *cursor, MDBX_val *key, MDBX_val *data,
mdbx_attr_t attr, unsigned flags) {
mdbx_attr_t attr, MDBX_put_flags_t flags) {
MDBX_val reserve;
reserve.iov_base = NULL;
reserve.iov_len = (data ? data->iov_len : 0) + sizeof(mdbx_attr_t);

View File

@ -350,13 +350,13 @@ int main(int argc, char *argv[]) {
goto env_close;
}
rc = mdbx_txn_begin(env, nullptr, MDBX_RDONLY, &txn);
rc = mdbx_txn_begin(env, nullptr, MDBX_TXN_RDONLY, &txn);
if (unlikely(rc != MDBX_SUCCESS)) {
error("mdbx_txn_begin", rc);
goto env_close;
}
rc = mdbx_dbi_open(txn, subname, MDBX_ACCEDE, &dbi);
rc = mdbx_dbi_open(txn, subname, MDBX_DB_ACCEDE, &dbi);
if (unlikely(rc != MDBX_SUCCESS)) {
error("mdbx_dbi_open", rc);
goto txn_abort;
@ -394,7 +394,7 @@ int main(int argc, char *argv[]) {
subname[key.iov_len] = '\0';
MDBX_dbi sub_dbi;
rc = mdbx_dbi_open_ex(txn, subname, MDBX_ACCEDE, &sub_dbi,
rc = mdbx_dbi_open_ex(txn, subname, MDBX_DB_ACCEDE, &sub_dbi,
rescue ? equal_or_greater : nullptr,
rescue ? equal_or_greater : nullptr);
if (unlikely(rc != MDBX_SUCCESS)) {

View File

@ -193,7 +193,7 @@ int main(int argc, char *argv[]) {
goto env_close;
}
rc = mdbx_txn_begin(env, nullptr, MDBX_RDONLY, &txn);
rc = mdbx_txn_begin(env, nullptr, MDBX_TXN_RDONLY, &txn);
if (unlikely(rc != MDBX_SUCCESS)) {
error("mdbx_txn_begin", rc);
goto txn_abort;
@ -396,7 +396,7 @@ int main(int argc, char *argv[]) {
printf(" GC: %" PRIaPGNO " pages\n", pages);
}
rc = mdbx_dbi_open(txn, subname, MDBX_ACCEDE, &dbi);
rc = mdbx_dbi_open(txn, subname, MDBX_DB_ACCEDE, &dbi);
if (unlikely(rc != MDBX_SUCCESS)) {
error("mdbx_dbi_open", rc);
goto txn_abort;
@ -426,7 +426,7 @@ int main(int argc, char *argv[]) {
subname = mdbx_malloc(key.iov_len + 1);
memcpy(subname, key.iov_base, key.iov_len);
subname[key.iov_len] = '\0';
rc = mdbx_dbi_open(txn, subname, MDBX_ACCEDE, &subdbi);
rc = mdbx_dbi_open(txn, subname, MDBX_DB_ACCEDE, &subdbi);
if (rc == MDBX_SUCCESS)
printf("Status of %s\n", subname);
mdbx_free(subname);

View File

@ -24,9 +24,9 @@ bool testcase_append::run() {
keyvalue_maker.setup(config.params, config.actor_id, 0 /* thread_number */);
/* LY: тест наполнения таблиц в append-режиме,
* при котором записи добавляются строго в конец (в порядке сортировки) */
const unsigned flags = (config.params.table_flags & MDBX_DUPSORT)
? MDBX_APPEND | MDBX_APPENDDUP
: MDBX_APPEND;
const MDBX_put_flags_t flags = (config.params.table_flags & MDBX_DUPSORT)
? MDBX_APPEND | MDBX_APPENDDUP
: MDBX_APPEND;
keyvalue_maker.make_ordered();
key = keygen::alloc(config.params.keylen_max);

View File

@ -6,7 +6,7 @@ void testcase_copy::copy_db(const bool with_compaction) {
failure_perror("mdbx_removefile()", err);
err = mdbx_env_copy(db_guard.get(), copy_pathname.c_str(),
with_compaction ? MDBX_CP_COMPACT : 0);
with_compaction ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS);
if (unlikely(err != MDBX_SUCCESS))
failure_perror(with_compaction ? "mdbx_env_copy(MDBX_CP_COMPACT)"
: "mdbx_env_copy(MDBX_CP_ASIS)",

View File

@ -52,10 +52,11 @@ bool testcase_hill::run() {
keygen::buffer b_key = keygen::alloc(config.params.keylen_max);
keygen::buffer b_data = keygen::alloc(config.params.datalen_max);
const unsigned insert_flags = (config.params.table_flags & MDBX_DUPSORT)
? MDBX_NODUPDATA
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
const unsigned update_flags =
const MDBX_put_flags_t insert_flags =
(config.params.table_flags & MDBX_DUPSORT)
? MDBX_NODUPDATA
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
const MDBX_put_flags_t update_flags =
(config.params.table_flags & MDBX_DUPSORT)
? MDBX_CURRENT | MDBX_NODUPDATA | MDBX_NOOVERWRITE
: MDBX_NODUPDATA;

View File

@ -212,18 +212,20 @@ void maker::setup(const config::actor_params_pod &actor, unsigned actor_id,
assert(actor.keylen_min <= UINT16_MAX);
key_essentials.minlen = (uint16_t)actor.keylen_min;
assert(actor.keylen_max <= UINT32_MAX);
key_essentials.maxlen = std::min(
(uint32_t)actor.keylen_max,
(uint32_t)mdbx_limits_keysize_max(actor.pagesize, key_essentials.flags));
key_essentials.maxlen =
std::min((uint32_t)actor.keylen_max,
(uint32_t)mdbx_limits_keysize_max(
actor.pagesize, MDBX_db_flags_t(key_essentials.flags)));
value_essentials.flags =
actor.table_flags & uint16_t(MDBX_INTEGERDUP | MDBX_REVERSEDUP);
assert(actor.datalen_min <= UINT16_MAX);
value_essentials.minlen = (uint16_t)actor.datalen_min;
assert(actor.datalen_max <= UINT32_MAX);
value_essentials.maxlen = std::min(
(uint32_t)actor.datalen_max,
(uint32_t)mdbx_limits_valsize_max(actor.pagesize, key_essentials.flags));
value_essentials.maxlen =
std::min((uint32_t)actor.datalen_max,
(uint32_t)mdbx_limits_valsize_max(
actor.pagesize, MDBX_db_flags_t(key_essentials.flags)));
if (!actor.keygen.zero_fill) {
key_essentials.flags |= essentials::prng_fill_flag;

View File

@ -77,7 +77,8 @@ bool testcase_nested::teardown() {
void testcase_nested::push_txn() {
MDBX_txn *txn;
unsigned flags = prng32() & (MDBX_SAFE_NOSYNC | MDBX_NOMETASYNC);
MDBX_txn_flags_t flags =
MDBX_txn_flags_t(prng32() & (MDBX_TXN_NOSYNC | MDBX_TXN_NOMETASYNC));
int err = mdbx_txn_begin(db_guard.get(), txn_guard.get(), flags, &txn);
if (unlikely(err != MDBX_SUCCESS))
failure_perror("mdbx_txn_begin(nested)", err);
@ -189,9 +190,10 @@ bool testcase_nested::trim_tail(unsigned window_width) {
}
bool testcase_nested::grow_head(unsigned head_count) {
const unsigned insert_flags = (config.params.table_flags & MDBX_DUPSORT)
? MDBX_NODUPDATA
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
const MDBX_put_flags_t insert_flags =
(config.params.table_flags & MDBX_DUPSORT)
? MDBX_NODUPDATA
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
retry:
fifo.push_front(std::make_pair(serial, head_count));
for (unsigned n = 0; n < head_count; ++n) {

View File

@ -239,7 +239,7 @@ static void get_db_stat(const char *db, int64_t *ms_branch_pages,
MDBX_stat stat;
MDBX_dbi dbi;
MDBX_CHECK(mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn));
MDBX_CHECK(mdbx_txn_begin(env, NULL, MDBX_TXN_RDONLY, &txn));
MDBX_CHECK(mdbx_dbi_open(txn, db, MDBX_CREATE, &dbi));
MDBX_CHECK(mdbx_dbi_stat(txn, dbi, &stat, sizeof(stat)));
mdbx_txn_abort(txn);

View File

@ -145,11 +145,11 @@ void testcase::db_open() {
jitter_delay(true);
unsigned mode = (unsigned)config.params.mode_flags;
MDBX_env_flags_t mode = config.params.mode_flags;
if (config.params.random_writemap && flipcoin())
mode ^= MDBX_WRITEMAP;
actual_db_mode = mode;
actual_env_mode = mode;
int rc = mdbx_env_open(db_guard.get(), config.params.pathname_db.c_str(),
mode, 0640);
if (unlikely(rc != MDBX_SUCCESS))
@ -166,15 +166,15 @@ void testcase::db_close() {
log_trace("<< db_close");
}
void testcase::txn_begin(bool readonly, unsigned flags) {
assert((flags & MDBX_RDONLY) == 0);
void testcase::txn_begin(bool readonly, MDBX_txn_flags_t flags) {
assert((flags & MDBX_TXN_RDONLY) == 0);
log_trace(">> txn_begin(%s, 0x%04X)", readonly ? "read-only" : "read-write",
flags);
assert(!txn_guard);
MDBX_txn *txn = nullptr;
int rc = mdbx_txn_begin(db_guard.get(), nullptr,
readonly ? flags | MDBX_RDONLY : flags, &txn);
readonly ? flags | MDBX_TXN_RDONLY : flags, &txn);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror("mdbx_txn_begin()", rc);
txn_guard.reset(txn);
@ -272,11 +272,11 @@ int testcase::breakable_restart() {
rc = breakable_commit();
if (cursor_guard)
cursor_close();
txn_begin(false, 0);
txn_begin(false, MDBX_TXN_READWRITE);
return rc;
}
void testcase::txn_restart(bool abort, bool readonly, unsigned flags) {
void testcase::txn_restart(bool abort, bool readonly, MDBX_txn_flags_t flags) {
if (txn_guard)
txn_end(abort);
if (cursor_guard)
@ -485,7 +485,8 @@ MDBX_dbi testcase::db_table_open(bool create) {
MDBX_dbi handle = 0;
int rc = mdbx_dbi_open(txn_guard.get(), tablename,
(create ? MDBX_CREATE : 0) | config.params.table_flags,
(create ? MDBX_CREATE : MDBX_DB_DEFAULTS) |
config.params.table_flags,
&handle);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror("mdbx_dbi_open()", rc);
@ -625,7 +626,7 @@ bool test_execute(const actor_config &config_const) {
//-----------------------------------------------------------------------------
int testcase::insert(const keygen::buffer &akey, const keygen::buffer &adata,
unsigned flags) {
MDBX_put_flags_t flags) {
int err = mdbx_put(txn_guard.get(), dbi, &akey->value, &adata->value, flags);
if (err == MDBX_SUCCESS && config.params.speculum) {
const auto S_key = S(akey);
@ -639,7 +640,7 @@ int testcase::insert(const keygen::buffer &akey, const keygen::buffer &adata,
int testcase::replace(const keygen::buffer &akey,
const keygen::buffer &new_data,
const keygen::buffer &old_data, unsigned flags) {
const keygen::buffer &old_data, MDBX_put_flags_t flags) {
if (config.params.speculum) {
const auto S_key = S(akey);
const auto S_old = S(old_data);

View File

@ -161,27 +161,28 @@ protected:
SET speculum{ItemCompare(this)}, speculum_commited{ItemCompare(this)};
bool speculum_verify();
int insert(const keygen::buffer &akey, const keygen::buffer &adata,
unsigned flags);
MDBX_put_flags_t flags);
int replace(const keygen::buffer &akey, const keygen::buffer &new_value,
const keygen::buffer &old_value, unsigned flags);
const keygen::buffer &old_value, MDBX_put_flags_t flags);
int remove(const keygen::buffer &akey, const keygen::buffer &adata);
static int oom_callback(MDBX_env *env, mdbx_pid_t pid, mdbx_tid_t tid,
uint64_t txn, unsigned gap, size_t space, int retry);
unsigned actual_db_mode{0};
MDBX_env_flags_t actual_env_mode{MDBX_ENV_DEFAULTS};
bool is_nested_txn_available() const {
return (actual_db_mode & MDBX_WRITEMAP) == 0;
return (actual_env_mode & MDBX_WRITEMAP) == 0;
}
void kick_progress(bool active) const;
void db_prepare();
void db_open();
void db_close();
void txn_begin(bool readonly, unsigned flags = 0);
void txn_begin(bool readonly, MDBX_txn_flags_t flags = MDBX_TXN_READWRITE);
int breakable_commit();
void txn_end(bool abort);
int breakable_restart();
void txn_restart(bool abort, bool readonly, unsigned flags = 0);
void txn_restart(bool abort, bool readonly,
MDBX_txn_flags_t flags = MDBX_TXN_READWRITE);
void cursor_open(MDBX_dbi handle);
void cursor_close();
void txn_inject_writefault(void);

View File

@ -6,7 +6,7 @@ bool testcase_try::run() {
MDBX_txn *txn = nullptr;
MDBX_txn *txn2 = nullptr;
int rc = mdbx_txn_begin(db_guard.get(), nullptr, 0, &txn);
int rc = mdbx_txn_begin(db_guard.get(), nullptr, MDBX_TXN_READWRITE, &txn);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror("mdbx_txn_begin(MDBX_TXN_TRY)", rc);
else {

View File

@ -121,9 +121,10 @@ bool testcase_ttl::run() {
keyvalue_maker.setup(config.params, config.actor_id, 0 /* thread_number */);
key = keygen::alloc(config.params.keylen_max);
data = keygen::alloc(config.params.datalen_max);
const unsigned insert_flags = (config.params.table_flags & MDBX_DUPSORT)
? MDBX_NODUPDATA
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
const MDBX_put_flags_t insert_flags =
(config.params.table_flags & MDBX_DUPSORT)
? MDBX_NODUPDATA
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
std::deque<std::pair<uint64_t, unsigned>> fifo;
uint64_t serial = 0;