]> git.sur5r.net Git - openldap/commitdiff
ITS#8300 more for node_move fixups
authorHoward Chu <hyc@openldap.org>
Wed, 4 Nov 2015 22:31:01 +0000 (22:31 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 4 Nov 2015 22:32:05 +0000 (22:32 +0000)
When moving a node from the right neighbor, a different
adjustment is needed.

libraries/liblmdb/mdb.c

index 0054f62b5a5d07928143b67e55d23c6587ceeafc..2617513f9473a2e6f3cb8307b86421828db4defc 100644 (file)
@@ -7733,19 +7733,38 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst)
                                        m3->mc_ki[csrc->mc_top]++;
                                }
                        }
-               }
 
-               mp = csrc->mc_pg[csrc->mc_top];
-               for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
-                       if (csrc->mc_flags & C_SUB)
-                               m3 = &m2->mc_xcursor->mx_cursor;
-                       else
-                               m3 = m2;
-                       if (m3 == csrc) continue;
-                       if (m3->mc_pg[csrc->mc_top] == mp && m3->mc_ki[csrc->mc_top] ==
-                               csrc->mc_ki[csrc->mc_top]) {
-                               m3->mc_pg[csrc->mc_top] = cdst->mc_pg[cdst->mc_top];
-                               m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
+                       mp = csrc->mc_pg[csrc->mc_top];
+                       for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
+                               if (csrc->mc_flags & C_SUB)
+                                       m3 = &m2->mc_xcursor->mx_cursor;
+                               else
+                                       m3 = m2;
+                               if (m3 == csrc) continue;
+                               if (m3->mc_pg[csrc->mc_top] == mp && m3->mc_ki[csrc->mc_top] ==
+                                       csrc->mc_ki[csrc->mc_top]) {
+                                       m3->mc_pg[csrc->mc_top] = cdst->mc_pg[cdst->mc_top];
+                                       m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
+                               }
+                       }
+               } else
+               /* Adding on the right, bump others down */
+               {
+                       mp = csrc->mc_pg[csrc->mc_top];
+                       for (m2 = csrc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
+                               if (csrc->mc_flags & C_SUB)
+                                       m3 = &m2->mc_xcursor->mx_cursor;
+                               else
+                                       m3 = m2;
+                               if (m3 == csrc) continue;
+                               if (m3->mc_pg[csrc->mc_top] == mp) {
+                                       if (!m3->mc_ki[csrc->mc_top]) {
+                                               m3->mc_pg[csrc->mc_top] = cdst->mc_pg[cdst->mc_top];
+                                               m3->mc_ki[csrc->mc_top] = cdst->mc_ki[cdst->mc_top];
+                                       } else {
+                                               m3->mc_ki[csrc->mc_top]--;
+                                       }
+                               }
                        }
                }
        }