Skip to content

Commit

Permalink
mdbx: enable minicore by default (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Nov 1, 2023
1 parent 988db64 commit d1fe18f
Show file tree
Hide file tree
Showing 27 changed files with 2,958 additions and 1,047 deletions.
45 changes: 11 additions & 34 deletions mdbx/mdbx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* <http://www.OpenLDAP.org/license.html>. */

#define xMDBX_ALLOY 1
#define MDBX_BUILD_SOURCERY 748ccee885a921bfe8ef7b24e71957dd3922fe37083ceb8048cb89c28c5d8f9b_v0_12_7_20_g2b0eae08
#define MDBX_BUILD_SOURCERY d7603e99410126db376215bd0ceb9c2e32eba2af6c4988c85272497a38e29e56_v0_12_8_6_ged8c7ead
#ifdef MDBX_CONFIG_H
#include MDBX_CONFIG_H
#endif
Expand Down Expand Up @@ -2051,8 +2051,7 @@ extern LIBMDBX_API const char *const mdbx_sourcery_anchor;
/** Controls using Unix' mincore() to determine whether DB-pages
* are resident in memory. */
#ifndef MDBX_ENABLE_MINCORE
#if MDBX_ENABLE_PREFAULT && \
(defined(MINCORE_INCORE) || !(defined(_WIN32) || defined(_WIN64)))
#if defined(MINCORE_INCORE) || !(defined(_WIN32) || defined(_WIN64))
#define MDBX_ENABLE_MINCORE 1
#else
#define MDBX_ENABLE_MINCORE 0
Expand Down Expand Up @@ -20916,11 +20915,13 @@ static __hot int cursor_get(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
}
break;
case MDBX_GET_MULTIPLE:
if (unlikely(data == NULL || !(mc->mc_flags & C_INITIALIZED)))
if (unlikely(!data))
return MDBX_EINVAL;
if (unlikely(!(mc->mc_db->md_flags & MDBX_DUPFIXED)))
if (unlikely((mc->mc_db->md_flags & MDBX_DUPFIXED) == 0))
return MDBX_INCOMPATIBLE;
rc = MDBX_SUCCESS;
rc = (mc->mc_flags & C_INITIALIZED)
? MDBX_SUCCESS
: cursor_set(mc, key, data, MDBX_SET).err;
if ((mc->mc_xcursor->mx_cursor.mc_flags & (C_INITIALIZED | C_EOF)) !=
C_INITIALIZED)
break;
Expand Down Expand Up @@ -27101,30 +27102,6 @@ int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del) {
return rc;
}

int mdbx_set_compare(MDBX_txn *txn, MDBX_dbi dbi, MDBX_cmp_func *cmp) {
int rc = check_txn(txn, MDBX_TXN_BLOCKED - MDBX_TXN_ERROR);
if (unlikely(rc != MDBX_SUCCESS))
return rc;

if (unlikely(!check_dbi(txn, dbi, DBI_USRVALID)))
return MDBX_BAD_DBI;

txn->mt_dbxs[dbi].md_cmp = cmp;
return MDBX_SUCCESS;
}

int mdbx_set_dupsort(MDBX_txn *txn, MDBX_dbi dbi, MDBX_cmp_func *cmp) {
int rc = check_txn(txn, MDBX_TXN_BLOCKED - MDBX_TXN_ERROR);
if (unlikely(rc != MDBX_SUCCESS))
return rc;

if (unlikely(!check_dbi(txn, dbi, DBI_USRVALID)))
return MDBX_BAD_DBI;

txn->mt_dbxs[dbi].md_dcmp = cmp;
return MDBX_SUCCESS;
}

__cold int mdbx_reader_list(const MDBX_env *env, MDBX_reader_list_func *func,
void *ctx) {
int rc = check_env(env, true);
Expand Down Expand Up @@ -33363,10 +33340,10 @@ __dll_export
const struct MDBX_version_info mdbx_version = {
0,
12,
7,
20,
{"2023-10-09T22:12:06+03:00", "1f76e0a48d39074b6ca2a30b74c31b858d09cb2b", "2b0eae08f565b55d035d08cb87dea89566cf0747",
"v0.12.7-20-g2b0eae08"},
8,
6,
{"2023-10-29T12:20:54+03:00", "551a22197e35ee5c5902f8fe0c4dbf4da99722a4", "ed8c7ead4e0f7afc50491d34918eae85dff64b86",
"v0.12.8-6-ged8c7ead"},
sourcery};

__dll_export
Expand Down
51 changes: 28 additions & 23 deletions mdbx/mdbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,8 @@ enum MDBX_error_t {
MDBX_BAD_RSLOT = -30783,

/** Transaction is not valid for requested operation,
* e.g. had errored and be must aborted, has a child, or is invalid */
* e.g. had errored and be must aborted, has a child/nested transaction,
* or is invalid */
MDBX_BAD_TXN = -30782,

/** Invalid size or alignment of key or data for target database,
Expand Down Expand Up @@ -1936,7 +1937,7 @@ enum MDBX_error_t {
MDBX_DUPLICATED_CLK = -30413,

/* The last of MDBX-added error codes */
MDBX_LAST_ADDED_ERRCODE = MDBX_TXN_OVERLAPPING,
MDBX_LAST_ADDED_ERRCODE = MDBX_DUPLICATED_CLK,

#if defined(_WIN32) || defined(_WIN64)
MDBX_ENODATA = ERROR_HANDLE_EOF,
Expand Down Expand Up @@ -2699,11 +2700,12 @@ MDBX_DEPRECATED LIBMDBX_INLINE_API(int, mdbx_env_info,
* success. The \ref MDBX_RESULT_TRUE means no data pending for flush
* to disk, and 0 otherwise. Some possible errors are:
*
* \retval MDBX_EACCES the environment is read-only.
* \retval MDBX_BUSY the environment is used by other thread
* \retval MDBX_EACCES The environment is read-only.
* \retval MDBX_BUSY The environment is used by other thread
* and `nonblock=true`.
* \retval MDBX_EINVAL an invalid parameter was specified.
* \retval MDBX_EIO an error occurred during synchronization. */
* \retval MDBX_EINVAL An invalid parameter was specified.
* \retval MDBX_EIO An error occurred during the flushing/writing data
* to a storage medium/disk. */
LIBMDBX_API int mdbx_env_sync_ex(MDBX_env *env, bool force, bool nonblock);

/** \brief The shortcut to calling \ref mdbx_env_sync_ex() with
Expand Down Expand Up @@ -2878,7 +2880,8 @@ LIBMDBX_INLINE_API(int, mdbx_env_get_syncperiod,
* is expected, i.e. \ref MDBX_env instance was freed in
* proper manner.
*
* \retval MDBX_EIO An error occurred during synchronization. */
* \retval MDBX_EIO An error occurred during the flushing/writing data
* to a storage medium/disk. */
LIBMDBX_API int mdbx_env_close_ex(MDBX_env *env, bool dont_sync);

/** \brief The shortcut to calling \ref mdbx_env_close_ex() with
Expand Down Expand Up @@ -3918,7 +3921,8 @@ LIBMDBX_API int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency);
* by current thread.
* \retval MDBX_EINVAL Transaction handle is NULL.
* \retval MDBX_ENOSPC No more disk space.
* \retval MDBX_EIO A system-level I/O error occurred.
* \retval MDBX_EIO An error occurred during the flushing/writing
* data to a storage medium/disk.
* \retval MDBX_ENOMEM Out of memory. */
LIBMDBX_INLINE_API(int, mdbx_txn_commit, (MDBX_txn * txn)) {
return mdbx_txn_commit_ex(txn, NULL);
Expand Down Expand Up @@ -4084,9 +4088,9 @@ LIBMDBX_API int mdbx_canary_get(const MDBX_txn *txn, MDBX_canary *canary);
* \see mdbx_get_datacmp \see mdbx_dcmp()
*
* \anchor avoid_custom_comparators
* It is recommend not using custom comparison functions, but instead
* converting the keys to one of the forms that are suitable for built-in
* comparators (for instance take look to the \ref value2key).
* \deprecated It is recommend not using custom comparison functions, but
* instead converting the keys to one of the forms that are suitable for
* built-in comparators (for instance take look to the \ref value2key).
* The reasons to not using custom comparators are:
* - The order of records could not be validated without your code.
* So `mdbx_chk` utility will reports "wrong order" errors
Expand Down Expand Up @@ -4316,7 +4320,7 @@ LIBMDBX_API int mdbx_dbi_dupsort_depthmask(MDBX_txn *txn, MDBX_dbi dbi,
enum MDBX_dbi_state_t {
/** DB was written in this txn */
MDBX_DBI_DIRTY = 0x01,
/** Named-DB record is older than txnID */
/** Cached Named-DB record is older than txnID */
MDBX_DBI_STALE = 0x02,
/** Named-DB handle opened in this txn */
MDBX_DBI_FRESH = 0x04,
Expand Down Expand Up @@ -4655,7 +4659,7 @@ LIBMDBX_API int mdbx_replace_ex(MDBX_txn *txn, MDBX_dbi dbi,
LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
const MDBX_val *data);

/** \brief Create a cursor handle but not bind it to transaction nor DBI handle.
/** \brief Create a cursor handle but not bind it to transaction nor DBI-handle.
* \ingroup c_cursors
*
* A cursor cannot be used when its database handle is closed. Nor when its
Expand All @@ -4679,7 +4683,7 @@ LIBMDBX_API int mdbx_del(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
* \returns Created cursor handle or NULL in case out of memory. */
LIBMDBX_API MDBX_cursor *mdbx_cursor_create(void *context);

/** \brief Set application information associated with the \ref MDBX_cursor.
/** \brief Set application information associated with the cursor.
* \ingroup c_cursors
* \see mdbx_cursor_get_userctx()
*
Expand All @@ -4702,11 +4706,11 @@ LIBMDBX_API int mdbx_cursor_set_userctx(MDBX_cursor *cursor, void *ctx);
MDBX_NOTHROW_PURE_FUNCTION LIBMDBX_API void *
mdbx_cursor_get_userctx(const MDBX_cursor *cursor);

/** \brief Bind cursor to specified transaction and DBI handle.
/** \brief Bind cursor to specified transaction and DBI-handle.
* \ingroup c_cursors
*
* Using of the `mdbx_cursor_bind()` is equivalent to calling
* \ref mdbx_cursor_renew() but with specifying an arbitrary dbi handle.
* \ref mdbx_cursor_renew() but with specifying an arbitrary DBI-handle.
*
* A cursor may be associated with a new transaction, and referencing a new or
* the same database handle as it was created with. This may be done whether the
Expand All @@ -4720,7 +4724,7 @@ mdbx_cursor_get_userctx(const MDBX_cursor *cursor);
*
* \param [in] txn A transaction handle returned by \ref mdbx_txn_begin().
* \param [in] dbi A database handle returned by \ref mdbx_dbi_open().
* \param [out] cursor A cursor handle returned by \ref mdbx_cursor_create().
* \param [in] cursor A cursor handle returned by \ref mdbx_cursor_create().
*
* \returns A non-zero error value on failure and 0 on success,
* some possible errors are:
Expand Down Expand Up @@ -4779,15 +4783,14 @@ LIBMDBX_API int mdbx_cursor_open(MDBX_txn *txn, MDBX_dbi dbi,
* or \ref mdbx_cursor_create(). */
LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor);

/** \brief Renew a cursor handle.
/** \brief Renew a cursor handle for use within the given transaction.
* \ingroup c_cursors
*
* The cursor may be associated with a new transaction, and referencing a new or
* the same database handle as it was created with. This may be done whether the
* previous transaction is live or dead.
* A cursor may be associated with a new transaction whether the previous
* transaction is running or finished.
*
* Using of the `mdbx_cursor_renew()` is equivalent to calling
* \ref mdbx_cursor_bind() with the DBI handle that previously
* \ref mdbx_cursor_bind() with the DBI-handle that previously
* the cursor was used with.
*
* \note In contrast to LMDB, the MDBX allow any cursor to be re-used by using
Expand All @@ -4801,7 +4804,9 @@ LIBMDBX_API void mdbx_cursor_close(MDBX_cursor *cursor);
* some possible errors are:
* \retval MDBX_THREAD_MISMATCH Given transaction is not owned
* by current thread.
* \retval MDBX_EINVAL An invalid parameter was specified. */
* \retval MDBX_EINVAL An invalid parameter was specified.
* \retval MDBX_BAD_DBI The cursor was not bound to a DBI-handle
* or such a handle became invalid. */
LIBMDBX_API int mdbx_cursor_renew(MDBX_txn *txn, MDBX_cursor *cursor);

/** \brief Return the cursor's transaction handle.
Expand Down
Loading

0 comments on commit d1fe18f

Please sign in to comment.