]> git.sur5r.net Git - openldap/blobdiff - libraries/liblmdb/mdb.c
Fix prev commit, cursor depth comparison
[openldap] / libraries / liblmdb / mdb.c
index ff4c12441bad9eb987dbb9eb61777df8efc35298..7a8ca3fde60a35eed55bf31e35f15a12c27678e3 100644 (file)
@@ -6079,8 +6079,7 @@ mdb_cursor_del(MDB_cursor *mc, unsigned int flags)
        if (!(mc->mc_flags & C_INITIALIZED))
                return EINVAL;
 
-       mp = mc->mc_pg[mc->mc_top];
-       if (mc->mc_ki[mc->mc_top] >= NUMKEYS(mp))
+       if (mc->mc_ki[mc->mc_top] >= NUMKEYS(mc->mc_pg[mc->mc_top]))
                return MDB_NOTFOUND;
 
        if (!(flags & MDB_NOSPILL) && (rc = mdb_page_spill(mc, NULL, NULL)))
@@ -6090,6 +6089,7 @@ mdb_cursor_del(MDB_cursor *mc, unsigned int flags)
        if (rc)
                return rc;
 
+       mp = mc->mc_pg[mc->mc_top];
        leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
 
        if (!IS_LEAF2(mp) && F_ISSET(leaf->mn_flags, F_DUPDATA)) {
@@ -6107,13 +6107,13 @@ mdb_cursor_del(MDB_cursor *mc, unsigned int flags)
                                } else {
                                        MDB_cursor *m2;
                                        /* shrink fake page */
-                                       mdb_node_shrink(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
-                                       leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
+                                       mdb_node_shrink(mp, mc->mc_ki[mc->mc_top]);
+                                       leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
                                        mc->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(leaf);
                                        /* fix other sub-DB cursors pointed at this fake page */
                                        for (m2 = mc->mc_txn->mt_cursors[mc->mc_dbi]; m2; m2=m2->mc_next) {
                                                if (m2 == mc || m2->mc_snum < mc->mc_snum) continue;
-                                               if (m2->mc_pg[mc->mc_top] == mc->mc_pg[mc->mc_top] &&
+                                               if (m2->mc_pg[mc->mc_top] == mp &&
                                                        m2->mc_ki[mc->mc_top] == mc->mc_ki[mc->mc_top])
                                                        m2->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(leaf);
                                        }
@@ -7291,7 +7291,7 @@ mdb_cursor_del0(MDB_cursor *mc, MDB_node *leaf)
 
                /* Adjust other cursors pointing to mp */
                for (m2 = mc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
-                       if (m2 == mc)
+                       if (m2 == mc || m2->mc_snum < mc->mc_snum)
                                continue;
                        if (!(m2->mc_flags & C_INITIALIZED))
                                continue;
@@ -7542,7 +7542,7 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
                                psize = 0;
                                if (newindx <= split_indx || newindx >= nkeys) {
                                        i = 0; j = 1;
-                                       k = newindx >= nkeys ? nkeys : split_indx+1;
+                                       k = newindx >= nkeys ? nkeys : split_indx+2;
                                } else {
                                        i = nkeys; j = -1;
                                        k = split_indx-1;
@@ -7562,18 +7562,11 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
                                                }
                                                psize += psize & 1;
                                        }
-                                       if (psize > pmax) {
+                                       if (psize > pmax || i == k-j) {
                                                split_indx = i + (j<0);
                                                break;
                                        }
                                }
-                               /* special case: when the new node was on the last
-                                * slot we may not have tripped the break inside the loop.
-                                * In all other cases we either hit the break condition,
-                                * or the original split_indx was already safe.
-                                */
-                               if (newindx >= nkeys && i == k)
-                                       split_indx = nkeys-1;
                        }
                        if (split_indx == newindx) {
                                sepkey.mv_size = newkey->mv_size;