lmdb: ITS#8258 fix rebalance/split.

The tree height can also increase during rebalance, not just shrink.
This can happen if update_key needs to split a parent branch page.

Change-Id: Ie232bd9f4a6225b912b912a68f0b35411a632317
This commit is contained in:
Howard Chu 2015-10-04 01:56:25 +01:00 committed by Leo Yuriev
parent 305ba98967
commit f2d0824bdb

13
mdb.c
View File

@ -7846,9 +7846,9 @@ mdb_page_merge(MDB_cursor *csrc, MDB_cursor *cdst)
uint16_t depth = cdst->mc_db->md_depth;
mdb_cursor_pop(cdst);
rc = mdb_rebalance(cdst);
/* Did the tree shrink? */
if (depth > cdst->mc_db->md_depth)
snum--;
/* Did the tree height change? */
if (depth != cdst->mc_db->md_depth)
snum += cdst->mc_db->md_depth - depth;
cdst->mc_snum = snum;
cdst->mc_top = snum-1;
}
@ -8040,7 +8040,7 @@ mdb_rebalance(MDB_cursor *mc)
*/
if (PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) >= thresh && NUMKEYS(mn.mc_pg[mn.mc_top]) > minkeys) {
rc = mdb_node_move(&mn, mc);
if (mc->mc_ki[ptop]) {
if (mc->mc_ki[mc->mc_top-1]) {
oldki++;
}
} else {
@ -8254,8 +8254,7 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
mc->mc_ki[0] = 0;
mc->mc_db->md_root = pp->mp_pgno;
mdb_debug("root split! new root = %zu", pp->mp_pgno);
mc->mc_db->md_depth++;
new_root = 1;
new_root = mc->mc_db->md_depth++;
/* Add left (implicit) pointer. */
if (unlikely((rc = mdb_node_add(mc, 0, NULL, NULL, mp->mp_pgno, 0)) != MDB_SUCCESS)) {
@ -8568,7 +8567,7 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
if (new_root) {
int k;
/* root split */
for (k=m3->mc_top; k>=0; k--) {
for (k=new_root; k>=0; k--) {
m3->mc_ki[k+1] = m3->mc_ki[k];
m3->mc_pg[k+1] = m3->mc_pg[k];
}