From f0c43fb24aa2b679d54cdf9db8274cc6589e2081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Thu, 29 Dec 2022 00:38:50 +0300 Subject: [PATCH] =?UTF-8?q?mdbx:=20=D0=B1=D0=B5=D0=B7=20=D0=BD=D0=B5=D0=BE?= =?UTF-8?q?=D0=B1=D1=85=D0=BE=D0=B4=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8=D0=BD=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BD=D0=B5-=D0=B3=D1=80=D1=8F=D0=B7=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= =?UTF-8?q?=20=D0=B2=20=D0=B4=D0=B5=D1=80=D0=B5=D0=B2=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/core.c b/src/core.c index 2758e524..bc5021a6 100644 --- a/src/core.c +++ b/src/core.c @@ -19488,6 +19488,7 @@ static int rebalance(MDBX_cursor *mc) { (pagetype & P_LEAF) ? "leaf" : "branch", tp->mp_pgno, numkeys, page_fill(mc->mc_txn->mt_env, tp), page_used(mc->mc_txn->mt_env, tp), room); + cASSERT(mc, IS_MODIFIABLE(mc->mc_txn, tp)); if (unlikely(numkeys < minkeys)) { DEBUG("page %" PRIaPGNO " must be merged due keys < %zu threshold", @@ -19576,8 +19577,9 @@ static int rebalance(MDBX_cursor *mc) { IS_LEAF(mc->mc_pg[mc->mc_db->md_depth - 1])); rc = page_retire(mc, mp); - if (unlikely(rc != MDBX_SUCCESS)) - return rc; + if (likely(rc == MDBX_SUCCESS)) + rc = page_touch(mc); + return rc; } else { DEBUG("root page %" PRIaPGNO " doesn't need rebalancing (flags 0x%x)", mp->mp_pgno, mp->mp_flags); @@ -19627,8 +19629,10 @@ static int rebalance(MDBX_cursor *mc) { const size_t right_room = right ? page_room(right) : 0; const size_t left_nkeys = left ? page_numkeys(left) : 0; const size_t right_nkeys = right ? page_numkeys(right) : 0; + bool involve = false; retry: - if (left_room > room_threshold && left_room >= right_room) { + if (left_room > room_threshold && left_room >= right_room && + (IS_MODIFIABLE(mc->mc_txn, left) || involve)) { /* try merge with left */ cASSERT(mc, left_nkeys >= minkeys); mn.mc_pg[mn.mc_top] = left; @@ -19646,7 +19650,8 @@ retry: return rc; } } - if (right_room > room_threshold) { + if (right_room > room_threshold && + (IS_MODIFIABLE(mc->mc_txn, right) || involve)) { /* try merge with right */ cASSERT(mc, right_nkeys >= minkeys); mn.mc_pg[mn.mc_top] = right; @@ -19662,7 +19667,8 @@ retry: } if (left_nkeys > minkeys && - (right_nkeys <= left_nkeys || right_room >= left_room)) { + (right_nkeys <= left_nkeys || right_room >= left_room) && + (IS_MODIFIABLE(mc->mc_txn, left) || involve)) { /* try move from left */ mn.mc_pg[mn.mc_top] = left; mn.mc_ki[mn.mc_top - 1] = (indx_t)(ki_pre_top - 1); @@ -19675,7 +19681,7 @@ retry: return rc; } } - if (right_nkeys > minkeys) { + if (right_nkeys > minkeys && (IS_MODIFIABLE(mc->mc_txn, right) || involve)) { /* try move from right */ mn.mc_pg[mn.mc_top] = right; mn.mc_ki[mn.mc_top - 1] = (indx_t)(ki_pre_top + 1); @@ -19696,6 +19702,10 @@ retry: return MDBX_SUCCESS; } + if (likely(!involve)) { + involve = true; + goto retry; + } if (likely(room_threshold > 0)) { room_threshold = 0; goto retry;