]> git.sur5r.net Git - openldap/commitdiff
ITS#8321 simplify page_split fixups
authorHoward Chu <hyc@openldap.org>
Mon, 23 Nov 2015 01:33:00 +0000 (01:33 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 23 Nov 2015 01:40:56 +0000 (01:40 +0000)
libraries/liblmdb/mdb.c

index 7ac24610ff6e13013cd2ea34cab4cb0f78d6956e..fe97b3ce1092b64fccdc5720648daca78d21f468 100644 (file)
@@ -8727,7 +8727,7 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
                /* Adjust other cursors pointing to mp */
                MDB_cursor *m2, *m3;
                MDB_dbi dbi = mc->mc_dbi;
-               int fixup = NUMKEYS(mp);
+               nkeys = NUMKEYS(mp);
 
                for (m2 = mc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
                        if (mc->mc_flags & C_SUB)
@@ -8740,12 +8740,15 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
                                continue;
                        if (new_root) {
                                int k;
+                               /* sub cursors may be on different DB */
+                               if (m3->mc_pg[0] != mp)
+                                       continue;
                                /* root split */
                                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];
                                }
-                               if (m3->mc_ki[0] >= split_indx) {
+                               if (m3->mc_ki[0] > nkeys) {
                                        m3->mc_ki[0] = 1;
                                } else {
                                        m3->mc_ki[0] = 0;
@@ -8757,10 +8760,13 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
                        if (m3->mc_top >= mc->mc_top && m3->mc_pg[mc->mc_top] == mp) {
                                if (m3->mc_ki[mc->mc_top] >= newindx && !(nflags & MDB_SPLIT_REPLACE))
                                        m3->mc_ki[mc->mc_top]++;
-                               if (m3->mc_ki[mc->mc_top] >= fixup) {
+                               if (m3->mc_ki[mc->mc_top] >= nkeys) {
                                        m3->mc_pg[mc->mc_top] = rp;
-                                       m3->mc_ki[mc->mc_top] -= fixup;
-                                       m3->mc_ki[ptop] = mn.mc_ki[ptop];
+                                       m3->mc_ki[mc->mc_top] -= nkeys;
+                                       for (i=0; i<mc->mc_top; i++) {
+                                               m3->mc_ki[i] = mn.mc_ki[i];
+                                               m3->mc_pg[i] = mn.mc_pg[i];
+                                       }
                                }
                        } else if (!did_split && m3->mc_top >= ptop && m3->mc_pg[ptop] == mc->mc_pg[ptop] &&
                                m3->mc_ki[ptop] >= mc->mc_ki[ptop]) {