From 7fcf11013e34db0ba0601880fc7ed7e515c7a6e9 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Wed, 10 Feb 2021 02:36:47 +0300 Subject: [PATCH 1/3] mdbx: minor fix likely/unlikely inside `mdbx_cursor_del()`. Change-Id: I86cfc755eef7371ea96c0feb39bffd3ec5298b71 --- src/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.c b/src/core.c index 9865cb8d..fdeb733e 100644 --- a/src/core.c +++ b/src/core.c @@ -14608,8 +14608,8 @@ int mdbx_cursor_del(MDBX_cursor *mc, MDBX_put_flags_t flags) { if (unlikely(mc->mc_ki[mc->mc_top] >= page_numkeys(mc->mc_pg[mc->mc_top]))) return MDBX_NOTFOUND; - if (unlikely(!(flags & MDBX_NOSPILL) && - (rc = mdbx_cursor_spill(mc, NULL, NULL)))) + if (likely((flags & MDBX_NOSPILL) == 0) && + unlikely(rc = mdbx_cursor_spill(mc, NULL, NULL))) return rc; rc = mdbx_cursor_touch(mc); From 72d978ee485b8a10f49b3f94af8565ba4e890a51 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Thu, 11 Feb 2021 13:07:41 +0300 Subject: [PATCH 2/3] mdbx: weakens checks during set the `MDBX_opt_txn_dp_limit` to avoid `MDBX_EINVAL`. Change-Id: I4852261d0c45b726c60792463ab698538fa447e5 --- src/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core.c b/src/core.c index fdeb733e..046c2fd0 100644 --- a/src/core.c +++ b/src/core.c @@ -20902,8 +20902,7 @@ __cold int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, case MDBX_opt_txn_dp_limit: case MDBX_opt_txn_dp_initial: - if (unlikely(value > MDBX_PGL_LIMIT || value < CURSOR_STACK * 4 || - value > bytes2pgno(env, env->me_dbgeo.upper) - NUM_METAS)) + if (unlikely(value > MDBX_PGL_LIMIT || value < CURSOR_STACK * 4)) return MDBX_EINVAL; if (unlikely(env->me_txn0 == NULL)) return MDBX_EACCESS; From c8dccc9bc41c4f1d5ce2a479d3afda5d7a95926b Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Thu, 11 Feb 2021 15:20:37 +0300 Subject: [PATCH 3/3] mdbx: limits the initial size of dpl-list to the current db-size. Change-Id: I5f575fc6168f50786b6f8a82ae020d323530a12e --- src/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core.c b/src/core.c index 046c2fd0..fb5822a7 100644 --- a/src/core.c +++ b/src/core.c @@ -3293,8 +3293,10 @@ static MDBX_dpl *mdbx_dpl_reserve(MDBX_txn *txn, size_t size) { static int mdbx_dpl_alloc(MDBX_txn *txn) { mdbx_tassert(txn, (txn->mt_flags & MDBX_TXN_RDONLY) == 0 && !txn->tw.dirtylist); - MDBX_dpl *const dl = - mdbx_dpl_reserve(txn, txn->mt_env->me_options.dp_initial); + const size_t len = (txn->mt_env->me_options.dp_initial < txn->mt_geo.upper) + ? txn->mt_env->me_options.dp_initial + : txn->mt_geo.upper; + MDBX_dpl *const dl = mdbx_dpl_reserve(txn, len); if (unlikely(!dl)) return MDBX_ENOMEM; mdbx_dpl_clear(dl);