From: Howard Chu Date: Tue, 9 Jul 2013 21:21:35 +0000 (-0700) Subject: Fixup other cursors after delete op X-Git-Tag: OPENLDAP_REL_ENG_2_4_36~32^2~25 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=64676da8d9c46d5a40eaca713bf0735e241ea4cf;p=openldap Fixup other cursors after delete op --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 96ac9521f2..17ff40cd89 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -6544,9 +6544,14 @@ static int mdb_cursor_del0(MDB_cursor *mc, MDB_node *leaf) { int rc; + MDB_page *mp; + indx_t ki; + + mp = mc->mc_pg[mc->mc_top]; + ki = mc->mc_ki[mc->mc_top]; /* add overflow pages to free list */ - if (!IS_LEAF2(mc->mc_pg[mc->mc_top]) && F_ISSET(leaf->mn_flags, F_BIGDATA)) { + if (!IS_LEAF2(mp) && F_ISSET(leaf->mn_flags, F_BIGDATA)) { MDB_page *omp; pgno_t pg; @@ -6555,7 +6560,7 @@ mdb_cursor_del0(MDB_cursor *mc, MDB_node *leaf) (rc = mdb_ovpage_free(mc, omp))) return rc; } - mdb_node_del(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top], mc->mc_db->md_pad); + mdb_node_del(mp, ki, mc->mc_db->md_pad); mc->mc_db->md_entries--; rc = mdb_rebalance(mc); if (rc != MDB_SUCCESS) @@ -6564,6 +6569,28 @@ mdb_cursor_del0(MDB_cursor *mc, MDB_node *leaf) else if (mc->mc_ki[mc->mc_top] >= NUMKEYS(mc->mc_pg[mc->mc_top])) mc->mc_flags &= ~C_INITIALIZED; + { + /* Adjust other cursors pointing to mp */ + MDB_cursor *m2; + unsigned int nkeys; + MDB_dbi dbi = mc->mc_dbi; + + mp = mc->mc_pg[mc->mc_top]; + nkeys = NUMKEYS(mp); + for (m2 = mc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) { + if (m2 == mc) + continue; + if (!(m2->mc_flags & C_INITIALIZED)) + continue; + if (m2->mc_pg[mc->mc_top] == mp) { + if (m2->mc_ki[mc->mc_top] > ki) + m2->mc_ki[mc->mc_top]--; + if (m2->mc_ki[mc->mc_top] >= nkeys) + m2->mc_flags &= ~C_INITIALIZED; + } + } + } + return rc; }