Fix rebalance/cursor adjust

When collapsing root, must also move cursor index down,
not just the page pointer.

Also in mtest, break from NEXT loops on error, otherwise it just
prints the previous key/data again, which looks confusing.
vmware
Howard Chu 12 years ago
parent f81eb631ff
commit b711c07f34
  1. 2
      libraries/liblmdb/mdb.c
  2. 4
      libraries/liblmdb/mtest.c

@ -6451,6 +6451,7 @@ mdb_rebalance(MDB_cursor *mc)
return rc; return rc;
mc->mc_db->md_depth--; mc->mc_db->md_depth--;
mc->mc_db->md_branch_pages--; mc->mc_db->md_branch_pages--;
mc->mc_ki[0] = mc->mc_ki[1];
{ {
/* Adjust other cursors pointing to mp */ /* Adjust other cursors pointing to mp */
MDB_cursor *m2, *m3; MDB_cursor *m2, *m3;
@ -6469,6 +6470,7 @@ mdb_rebalance(MDB_cursor *mc)
m3->mc_pg[0] = mc->mc_pg[0]; m3->mc_pg[0] = mc->mc_pg[0];
m3->mc_snum = 1; m3->mc_snum = 1;
m3->mc_top = 0; m3->mc_top = 0;
m3->mc_ki[0] = m3->mc_ki[1];
} }
} }
} }

@ -129,6 +129,8 @@ int main(int argc,char * argv[])
rc = mdb_cursor_open(txn, dbi, &cur2); rc = mdb_cursor_open(txn, dbi, &cur2);
for (i=0; i<50; i++) { for (i=0; i<50; i++) {
rc = mdb_cursor_get(cur2, &key, &data, MDB_NEXT); rc = mdb_cursor_get(cur2, &key, &data, MDB_NEXT);
if (rc)
break;
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
@ -142,6 +144,7 @@ int main(int argc,char * argv[])
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
for (i=0; i<32; i++) { for (i=0; i<32; i++) {
rc = mdb_cursor_get(cur2, &key, &data, MDB_NEXT); rc = mdb_cursor_get(cur2, &key, &data, MDB_NEXT);
if (rc) break;
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
@ -158,6 +161,7 @@ int main(int argc,char * argv[])
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
for (i=0; i<32; i++) { for (i=0; i<32; i++) {
rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT); rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT);
if (rc) break;
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);

Loading…
Cancel
Save