From 36a86bbc6e3462a91cb67876dca128bcc87d927d Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Mon, 26 Mar 2018 20:16:18 +0300 Subject: [PATCH] mdbx: fix cursor tracking inside mdbx_rebalance(). --- src/mdbx.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index 2c52f7c3..c414266b 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -8935,27 +8935,22 @@ static int mdbx_rebalance(MDBX_cursor *mc) { if (unlikely(rc)) return rc; /* Adjust cursors pointing to mp */ + const MDBX_dbi dbi = mc->mc_dbi; + for (MDBX_cursor *m2 = mc->mc_txn->mt_cursors[dbi]; m2; + m2 = m2->mc_next) { + MDBX_cursor *m3 = + (mc->mc_flags & C_SUB) ? &m2->mc_xcursor->mx_cursor : m2; + if (!(m3->mc_flags & C_INITIALIZED) || (m3->mc_snum < mc->mc_snum)) + continue; + if (m3->mc_pg[0] == mp) { + m3->mc_snum = 0; + m3->mc_top = 0; + m3->mc_flags &= ~C_INITIALIZED; + } + } mc->mc_snum = 0; mc->mc_top = 0; mc->mc_flags &= ~C_INITIALIZED; - { - MDBX_cursor *m2, *m3; - MDBX_dbi dbi = mc->mc_dbi; - - for (m2 = mc->mc_txn->mt_cursors[dbi]; m2; m2 = m2->mc_next) { - if (mc->mc_flags & C_SUB) - m3 = &m2->mc_xcursor->mx_cursor; - else - m3 = m2; - if (!(m3->mc_flags & C_INITIALIZED) || (m3->mc_snum < mc->mc_snum)) - continue; - if (m3->mc_pg[0] == mp) { - m3->mc_snum = 0; - m3->mc_top = 0; - m3->mc_flags &= ~C_INITIALIZED; - } - } - } } else if (IS_BRANCH(mp) && NUMKEYS(mp) == 1) { int i; mdbx_debug("collapsing root page!");