More debug, fix MDB_DEL_DUP

vmware
Howard Chu 13 years ago
parent ee69051a7c
commit 94718fab00
  1. 27
      libraries/libmdb/mdb.c

@ -71,7 +71,7 @@ typedef ULONG pgno_t;
# define DPRINTF (void) /* Vararg macros may be unsupported */ # define DPRINTF (void) /* Vararg macros may be unsupported */
#elif DEBUG #elif DEBUG
# define DPRINTF(fmt, ...) /* Requires 2 or more args */ \ # define DPRINTF(fmt, ...) /* Requires 2 or more args */ \
fprintf(stderr, "%s:%d: " fmt "\n", __func__, __LINE__, __VA_ARGS__) fprintf(stderr, "%s:%d:(%p) " fmt "\n", __func__, __LINE__, pthread_self(), __VA_ARGS__)
#else #else
# define DPRINTF(fmt, ...) ((void) 0) # define DPRINTF(fmt, ...) ((void) 0)
#endif #endif
@ -421,7 +421,8 @@ static int mdb_cursor_last(MDB_cursor *cursor,
MDB_val *key, MDB_val *data); MDB_val *key, MDB_val *data);
static void mdb_xcursor_init0(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx); static void mdb_xcursor_init0(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx);
static void mdb_xcursor_init1(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx, MDB_node *node); static void mdb_xcursor_init1(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx,
MDB_page *mp, MDB_node *node);
static void mdb_xcursor_fini(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx); static void mdb_xcursor_fini(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx);
static size_t mdb_leaf_size(MDB_env *env, MDB_val *key, static size_t mdb_leaf_size(MDB_env *env, MDB_val *key,
@ -1921,7 +1922,7 @@ mdb_get(MDB_txn *txn, MDB_dbi dbi,
MDB_xcursor mx; MDB_xcursor mx;
mdb_xcursor_init0(txn, dbi, &mx); mdb_xcursor_init0(txn, dbi, &mx);
mdb_xcursor_init1(txn, dbi, &mx, leaf); mdb_xcursor_init1(txn, dbi, &mx, mpp.mp_page, leaf);
rc = mdb_search_page(&mx.mx_txn, mx.mx_cursor.mc_dbi, NULL, NULL, 0, &mpp); rc = mdb_search_page(&mx.mx_txn, mx.mx_cursor.mc_dbi, NULL, NULL, 0, &mpp);
if (rc != MDB_SUCCESS) if (rc != MDB_SUCCESS)
return rc; return rc;
@ -2049,7 +2050,7 @@ mdb_cursor_next(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op o
leaf = NODEPTR(mp, top->mp_ki); leaf = NODEPTR(mp, top->mp_ki);
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, leaf); mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, mp, leaf);
} }
if (data) { if (data) {
if ((rc = mdb_read_data(cursor->mc_txn, leaf, data) != MDB_SUCCESS)) if ((rc = mdb_read_data(cursor->mc_txn, leaf, data) != MDB_SUCCESS))
@ -2124,7 +2125,7 @@ mdb_cursor_prev(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op o
leaf = NODEPTR(mp, top->mp_ki); leaf = NODEPTR(mp, top->mp_ki);
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, leaf); mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, mp, leaf);
} }
if (data) { if (data) {
if ((rc = mdb_read_data(cursor->mc_txn, leaf, data) != MDB_SUCCESS)) if ((rc = mdb_read_data(cursor->mc_txn, leaf, data) != MDB_SUCCESS))
@ -2214,7 +2215,7 @@ set2:
} }
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, leaf); mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, mpp.mp_page, leaf);
} }
if (data) { if (data) {
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
@ -2281,7 +2282,7 @@ mdb_cursor_first(MDB_cursor *cursor, MDB_val *key, MDB_val *data)
if (data) { if (data) {
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, leaf); mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, mpp.mp_page, leaf);
rc = mdb_cursor_first(&cursor->mc_xcursor->mx_cursor, data, NULL); rc = mdb_cursor_first(&cursor->mc_xcursor->mx_cursor, data, NULL);
if (rc) if (rc)
return rc; return rc;
@ -2330,7 +2331,7 @@ mdb_cursor_last(MDB_cursor *cursor, MDB_val *key, MDB_val *data)
if (data) { if (data) {
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, leaf); mdb_xcursor_init1(cursor->mc_txn, cursor->mc_dbi, cursor->mc_xcursor, mpp.mp_page, leaf);
rc = mdb_cursor_last(&cursor->mc_xcursor->mx_cursor, data, NULL); rc = mdb_cursor_last(&cursor->mc_xcursor->mx_cursor, data, NULL);
if (rc) if (rc)
return rc; return rc;
@ -2677,7 +2678,7 @@ mdb_xcursor_init0(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx)
} }
static void static void
mdb_xcursor_init1(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx, MDB_node *node) mdb_xcursor_init1(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx, MDB_page *mp, MDB_node *node)
{ {
MDB_db *db = NODEDATA(node); MDB_db *db = NODEDATA(node);
MDB_dbi dbn; MDB_dbi dbn;
@ -2691,6 +2692,8 @@ mdb_xcursor_init1(MDB_txn *txn, MDB_dbi dbi, MDB_xcursor *mx, MDB_node *node)
} }
DPRINTF("Sub-db %u for db %u root page %lu", dbn, dbi, db->md_root); DPRINTF("Sub-db %u for db %u root page %lu", dbn, dbi, db->md_root);
mx->mx_dbs[dbn] = *db; mx->mx_dbs[dbn] = *db;
if (F_ISSET(mp->mp_flags, P_DIRTY))
mx->mx_dbxs[dbn].md_dirty = 1;
mx->mx_dbxs[dbn].md_name.mv_data = NODEKEY(node); mx->mx_dbxs[dbn].md_name.mv_data = NODEKEY(node);
mx->mx_dbxs[dbn].md_name.mv_size = node->mn_ksize; mx->mx_dbxs[dbn].md_name.mv_size = node->mn_ksize;
mx->mx_txn.mt_next_pgno = txn->mt_next_pgno; mx->mx_txn.mt_next_pgno = txn->mt_next_pgno;
@ -3150,12 +3153,10 @@ mdb_del(MDB_txn *txn, MDB_dbi dbi,
MDB_pageparent mp2; MDB_pageparent mp2;
mdb_xcursor_init0(txn, dbi, &mx); mdb_xcursor_init0(txn, dbi, &mx);
mdb_xcursor_init1(txn, dbi, &mx, leaf); mdb_xcursor_init1(txn, dbi, &mx, mpp.mp_page, leaf);
if (flags == MDB_DEL_DUP) { if (flags == MDB_DEL_DUP) {
rc = mdb_del(&mx.mx_txn, mx.mx_cursor.mc_dbi, data, NULL, 0); rc = mdb_del(&mx.mx_txn, mx.mx_cursor.mc_dbi, data, NULL, 0);
mdb_xcursor_fini(txn, dbi, &mx); mdb_xcursor_fini(txn, dbi, &mx);
if (rc != MDB_SUCCESS)
return rc;
/* If sub-DB still has entries, we're done */ /* If sub-DB still has entries, we're done */
if (mx.mx_txn.mt_dbs[mx.mx_cursor.mc_dbi].md_root != P_INVALID) { if (mx.mx_txn.mt_dbs[mx.mx_cursor.mc_dbi].md_root != P_INVALID) {
memcpy(NODEDATA(leaf), &mx.mx_txn.mt_dbs[mx.mx_cursor.mc_dbi], memcpy(NODEDATA(leaf), &mx.mx_txn.mt_dbs[mx.mx_cursor.mc_dbi],
@ -3535,7 +3536,7 @@ new_sub:
leaf = NODEPTR(mpp.mp_page, ki); leaf = NODEPTR(mpp.mp_page, ki);
put_sub: put_sub:
mdb_xcursor_init0(txn, dbi, &mx); mdb_xcursor_init0(txn, dbi, &mx);
mdb_xcursor_init1(txn, dbi, &mx, leaf); mdb_xcursor_init1(txn, dbi, &mx, mpp.mp_page, leaf);
xdata.mv_size = 0; xdata.mv_size = 0;
xdata.mv_data = ""; xdata.mv_data = "";
if (flags == MDB_NODUPDATA) if (flags == MDB_NODUPDATA)

Loading…
Cancel
Save