ITS#7829 fix rebalance

Fixup cursor state after node_move/page_merge
incre
Howard Chu 11 years ago
parent 13d6d59c51
commit ac3acc1218
  1. 18
      libraries/liblmdb/mdb.c

@ -7323,6 +7323,7 @@ mdb_rebalance(MDB_cursor *mc)
int rc; int rc;
unsigned int ptop, minkeys; unsigned int ptop, minkeys;
MDB_cursor mn; MDB_cursor mn;
indx_t oldki;
minkeys = 1 + (IS_BRANCH(mc->mc_pg[mc->mc_top])); minkeys = 1 + (IS_BRANCH(mc->mc_pg[mc->mc_top]));
DPRINTF(("rebalancing %s page %"Z"u (has %u keys, %.1f%% full)", DPRINTF(("rebalancing %s page %"Z"u (has %u keys, %.1f%% full)",
@ -7427,6 +7428,7 @@ mdb_rebalance(MDB_cursor *mc)
mdb_cursor_copy(mc, &mn); mdb_cursor_copy(mc, &mn);
mn.mc_xcursor = NULL; mn.mc_xcursor = NULL;
oldki = mc->mc_ki[mc->mc_top];
if (mc->mc_ki[ptop] == 0) { if (mc->mc_ki[ptop] == 0) {
/* We're the leftmost leaf in our parent. /* We're the leftmost leaf in our parent.
*/ */
@ -7460,17 +7462,21 @@ mdb_rebalance(MDB_cursor *mc)
* (A branch page must never have less than 2 keys.) * (A branch page must never have less than 2 keys.)
*/ */
minkeys = 1 + (IS_BRANCH(mn.mc_pg[mn.mc_top])); minkeys = 1 + (IS_BRANCH(mn.mc_pg[mn.mc_top]));
if (PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) >= FILL_THRESHOLD && NUMKEYS(mn.mc_pg[mn.mc_top]) > minkeys) if (PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) >= FILL_THRESHOLD && NUMKEYS(mn.mc_pg[mn.mc_top]) > minkeys) {
return mdb_node_move(&mn, mc); rc = mdb_node_move(&mn, mc);
else { mc->mc_ki[mc->mc_top] = oldki;
if (mc->mc_ki[ptop] == 0) } else {
if (mc->mc_ki[ptop] == 0) {
rc = mdb_page_merge(&mn, mc); rc = mdb_page_merge(&mn, mc);
else { mc->mc_ki[mc->mc_top] = oldki;
} else {
unsigned int nkeys = NUMKEYS(mn.mc_pg[mn.mc_top]);
mn.mc_ki[mn.mc_top] += mc->mc_ki[mn.mc_top] + 1; mn.mc_ki[mn.mc_top] += mc->mc_ki[mn.mc_top] + 1;
rc = mdb_page_merge(mc, &mn); rc = mdb_page_merge(mc, &mn);
mdb_cursor_copy(&mn, mc); mdb_cursor_copy(&mn, mc);
mc->mc_ki[mc->mc_top] = oldki + nkeys;
} }
mc->mc_flags &= ~(C_INITIALIZED|C_EOF); mc->mc_flags &= ~C_EOF;
} }
return rc; return rc;
} }

Loading…
Cancel
Save