Pass cursor to mdb_page_get(), mdb_node_read().

No change in behavior.
rawpart
Hallvard Furuseth 9 years ago committed by Howard Chu
parent 209b56fead
commit 397d85d13c
  1. 70
      libraries/liblmdb/mdb.c

@ -1444,7 +1444,7 @@ enum {
#define MDB_END_SLOT MDB_NOTLS /**< release any reader slot if #MDB_NOTLS */ #define MDB_END_SLOT MDB_NOTLS /**< release any reader slot if #MDB_NOTLS */
static void mdb_txn_end(MDB_txn *txn, unsigned mode); static void mdb_txn_end(MDB_txn *txn, unsigned mode);
static int mdb_page_get(MDB_txn *txn, pgno_t pgno, MDB_page **mp, int *lvl); static int mdb_page_get(MDB_cursor *mc, pgno_t pgno, MDB_page **mp, int *lvl);
static int mdb_page_search_root(MDB_cursor *mc, static int mdb_page_search_root(MDB_cursor *mc,
MDB_val *key, int modify); MDB_val *key, int modify);
#define MDB_PS_MODIFY 1 #define MDB_PS_MODIFY 1
@ -1473,7 +1473,7 @@ static int mdb_node_add(MDB_cursor *mc, indx_t indx,
static void mdb_node_del(MDB_cursor *mc, int ksize); static void mdb_node_del(MDB_cursor *mc, int ksize);
static void mdb_node_shrink(MDB_page *mp, indx_t indx); static void mdb_node_shrink(MDB_page *mp, indx_t indx);
static int mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft); static int mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft);
static int mdb_node_read(MDB_txn *txn, MDB_node *leaf, MDB_val *data); static int mdb_node_read(MDB_cursor *mc, MDB_node *leaf, MDB_val *data);
static size_t mdb_leaf_size(MDB_env *env, MDB_val *key, MDB_val *data); static size_t mdb_leaf_size(MDB_env *env, MDB_val *key, MDB_val *data);
static size_t mdb_branch_size(MDB_env *env, MDB_val *key); static size_t mdb_branch_size(MDB_env *env, MDB_val *key);
@ -2023,7 +2023,7 @@ mdb_pages_xkeep(MDB_cursor *mc, unsigned pflags, int all)
{ {
enum { Mask = P_SUBP|P_DIRTY|P_LOOSE|P_KEEP }; enum { Mask = P_SUBP|P_DIRTY|P_LOOSE|P_KEEP };
MDB_txn *txn = mc->mc_txn; MDB_txn *txn = mc->mc_txn;
MDB_cursor *m3; MDB_cursor *m3, *m0 = mc;
MDB_xcursor *mx; MDB_xcursor *mx;
MDB_page *dp, *mp; MDB_page *dp, *mp;
MDB_node *leaf; MDB_node *leaf;
@ -2066,7 +2066,7 @@ mdb_pages_xkeep(MDB_cursor *mc, unsigned pflags, int all)
pgno_t pgno = txn->mt_dbs[i].md_root; pgno_t pgno = txn->mt_dbs[i].md_root;
if (pgno == P_INVALID) if (pgno == P_INVALID)
continue; continue;
if ((rc = mdb_page_get(txn, pgno, &dp, &level)) != MDB_SUCCESS) if ((rc = mdb_page_get(m0, pgno, &dp, &level)) != MDB_SUCCESS)
break; break;
if ((dp->mp_flags & Mask) == pflags && level <= 1) if ((dp->mp_flags & Mask) == pflags && level <= 1)
dp->mp_flags ^= P_KEEP; dp->mp_flags ^= P_KEEP;
@ -2370,7 +2370,7 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
} }
np = m2.mc_pg[m2.mc_top]; np = m2.mc_pg[m2.mc_top];
leaf = NODEPTR(np, m2.mc_ki[m2.mc_top]); leaf = NODEPTR(np, m2.mc_ki[m2.mc_top]);
if ((rc = mdb_node_read(txn, leaf, &data)) != MDB_SUCCESS) if ((rc = mdb_node_read(&m2, leaf, &data)) != MDB_SUCCESS)
return rc; return rc;
idl = (MDB_ID *) data.mv_data; idl = (MDB_ID *) data.mv_data;
@ -5899,15 +5899,16 @@ ok:
#endif #endif
/** Find the address of the page corresponding to a given page number. /** Find the address of the page corresponding to a given page number.
* @param[in] txn the transaction for this access. * @param[in] mc the cursor accessing the page.
* @param[in] pgno the page number for the page to retrieve. * @param[in] pgno the page number for the page to retrieve.
* @param[out] ret address of a pointer where the page's address will be stored. * @param[out] ret address of a pointer where the page's address will be stored.
* @param[out] lvl dirty_list inheritance level of found page. 1=current txn, 0=mapped page. * @param[out] lvl dirty_list inheritance level of found page. 1=current txn, 0=mapped page.
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
static int static int
mdb_page_get(MDB_txn *txn, pgno_t pgno, MDB_page **ret, int *lvl) mdb_page_get(MDB_cursor *mc, pgno_t pgno, MDB_page **ret, int *lvl)
{ {
MDB_txn *txn = mc->mc_txn;
#ifndef MDB_VL32 #ifndef MDB_VL32
MDB_env *env = txn->mt_env; MDB_env *env = txn->mt_env;
#endif #endif
@ -6018,7 +6019,7 @@ mdb_page_search_root(MDB_cursor *mc, MDB_val *key, int flags)
mdb_cassert(mc, i < NUMKEYS(mp)); mdb_cassert(mc, i < NUMKEYS(mp));
node = NODEPTR(mp, i); node = NODEPTR(mp, i);
if ((rc = mdb_page_get(mc->mc_txn, NODEPGNO(node), &mp, NULL)) != 0) if ((rc = mdb_page_get(mc, NODEPGNO(node), &mp, NULL)) != 0)
return rc; return rc;
mc->mc_ki[mc->mc_top] = i; mc->mc_ki[mc->mc_top] = i;
@ -6060,7 +6061,7 @@ mdb_page_search_lowest(MDB_cursor *mc)
MDB_node *node = NODEPTR(mp, 0); MDB_node *node = NODEPTR(mp, 0);
int rc; int rc;
if ((rc = mdb_page_get(mc->mc_txn, NODEPGNO(node), &mp, NULL)) != 0) if ((rc = mdb_page_get(mc, NODEPGNO(node), &mp, NULL)) != 0)
return rc; return rc;
mc->mc_ki[mc->mc_top] = 0; mc->mc_ki[mc->mc_top] = 0;
@ -6112,7 +6113,7 @@ mdb_page_search(MDB_cursor *mc, MDB_val *key, int flags)
return MDB_NOTFOUND; return MDB_NOTFOUND;
if ((leaf->mn_flags & (F_DUPDATA|F_SUBDATA)) != F_SUBDATA) if ((leaf->mn_flags & (F_DUPDATA|F_SUBDATA)) != F_SUBDATA)
return MDB_INCOMPATIBLE; /* not a named DB */ return MDB_INCOMPATIBLE; /* not a named DB */
rc = mdb_node_read(mc->mc_txn, leaf, &data); rc = mdb_node_read(&mc2, leaf, &data);
if (rc) if (rc)
return rc; return rc;
memcpy(&flags, ((char *) data.mv_data + offsetof(MDB_db, md_flags)), memcpy(&flags, ((char *) data.mv_data + offsetof(MDB_db, md_flags)),
@ -6140,7 +6141,7 @@ mdb_page_search(MDB_cursor *mc, MDB_val *key, int flags)
if (mc->mc_pg[0]) if (mc->mc_pg[0])
MDB_PAGE_UNREF(mc->mc_txn, mc->mc_pg[0]); MDB_PAGE_UNREF(mc->mc_txn, mc->mc_pg[0]);
#endif #endif
if ((rc = mdb_page_get(mc->mc_txn, root, &mc->mc_pg[0], NULL)) != 0) if ((rc = mdb_page_get(mc, root, &mc->mc_pg[0], NULL)) != 0)
return rc; return rc;
} }
@ -6245,13 +6246,13 @@ release:
} }
/** Return the data associated with a given node. /** Return the data associated with a given node.
* @param[in] txn The transaction for this operation. * @param[in] mc The cursor for this operation.
* @param[in] leaf The node being read. * @param[in] leaf The node being read.
* @param[out] data Updated to point to the node's data. * @param[out] data Updated to point to the node's data.
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
static int static int
mdb_node_read(MDB_txn *txn, MDB_node *leaf, MDB_val *data) mdb_node_read(MDB_cursor *mc, MDB_node *leaf, MDB_val *data)
{ {
MDB_page *omp; /* overflow page */ MDB_page *omp; /* overflow page */
pgno_t pgno; pgno_t pgno;
@ -6267,7 +6268,7 @@ mdb_node_read(MDB_txn *txn, MDB_node *leaf, MDB_val *data)
*/ */
data->mv_size = NODEDSZ(leaf); data->mv_size = NODEDSZ(leaf);
memcpy(&pgno, NODEDATA(leaf), sizeof(pgno)); memcpy(&pgno, NODEDATA(leaf), sizeof(pgno));
if ((rc = mdb_page_get(txn, pgno, &omp, NULL)) != 0) { if ((rc = mdb_page_get(mc, pgno, &omp, NULL)) != 0) {
DPRINTF(("read overflow page %"Y"u failed", pgno)); DPRINTF(("read overflow page %"Y"u failed", pgno));
return rc; return rc;
} }
@ -6358,7 +6359,7 @@ mdb_cursor_sibling(MDB_cursor *mc, int move_right)
MDB_PAGE_UNREF(mc->mc_txn, op); MDB_PAGE_UNREF(mc->mc_txn, op);
indx = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]); indx = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
if ((rc = mdb_page_get(mc->mc_txn, NODEPGNO(indx), &mp, NULL)) != 0) { if ((rc = mdb_page_get(mc, NODEPGNO(indx), &mp, NULL)) != 0) {
/* mc will be inconsistent if caller does mc_snum++ as above */ /* mc will be inconsistent if caller does mc_snum++ as above */
mc->mc_flags &= ~(C_INITIALIZED|C_EOF); mc->mc_flags &= ~(C_INITIALIZED|C_EOF);
return rc; return rc;
@ -6445,7 +6446,7 @@ skip:
mdb_xcursor_init1(mc, leaf); mdb_xcursor_init1(mc, leaf);
} }
if (data) { if (data) {
if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc; return rc;
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
@ -6530,7 +6531,7 @@ mdb_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
mdb_xcursor_init1(mc, leaf); mdb_xcursor_init1(mc, leaf);
} }
if (data) { if (data) {
if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc; return rc;
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
@ -6717,7 +6718,7 @@ set1:
} else if (op == MDB_GET_BOTH || op == MDB_GET_BOTH_RANGE) { } else if (op == MDB_GET_BOTH || op == MDB_GET_BOTH_RANGE) {
MDB_val olddata; MDB_val olddata;
MDB_cmp_func *dcmp; MDB_cmp_func *dcmp;
if ((rc = mdb_node_read(mc->mc_txn, leaf, &olddata)) != MDB_SUCCESS) if ((rc = mdb_node_read(mc, leaf, &olddata)) != MDB_SUCCESS)
return rc; return rc;
dcmp = mc->mc_dbx->md_dcmp; dcmp = mc->mc_dbx->md_dcmp;
#if UINT_MAX < SIZE_MAX || defined(MDB_VL32) #if UINT_MAX < SIZE_MAX || defined(MDB_VL32)
@ -6735,7 +6736,7 @@ set1:
} else { } else {
if (mc->mc_xcursor) if (mc->mc_xcursor)
mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF); mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc; return rc;
} }
} }
@ -6790,7 +6791,7 @@ mdb_cursor_first(MDB_cursor *mc, MDB_val *key, MDB_val *data)
if (rc) if (rc)
return rc; return rc;
} else { } else {
if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc; return rc;
} }
} }
@ -6841,7 +6842,7 @@ mdb_cursor_last(MDB_cursor *mc, MDB_val *key, MDB_val *data)
if (rc) if (rc)
return rc; return rc;
} else { } else {
if ((rc = mdb_node_read(mc->mc_txn, leaf, data)) != MDB_SUCCESS) if ((rc = mdb_node_read(mc, leaf, data)) != MDB_SUCCESS)
return rc; return rc;
} }
} }
@ -6887,7 +6888,7 @@ mdb_cursor_get(MDB_cursor *mc, MDB_val *key, MDB_val *data,
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
rc = mdb_cursor_get(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_GET_CURRENT); rc = mdb_cursor_get(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_GET_CURRENT);
} else { } else {
rc = mdb_node_read(mc->mc_txn, leaf, data); rc = mdb_node_read(mc, leaf, data);
} }
} }
} }
@ -6993,7 +6994,7 @@ fetchm:
MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]); MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) {
MDB_GET_KEY(leaf, key); MDB_GET_KEY(leaf, key);
rc = mdb_node_read(mc->mc_txn, leaf, data); rc = mdb_node_read(mc, leaf, data);
break; break;
} }
} }
@ -7377,7 +7378,7 @@ current:
int level, ovpages, dpages = OVPAGES(data->mv_size, env->me_psize); int level, ovpages, dpages = OVPAGES(data->mv_size, env->me_psize);
memcpy(&pg, olddata.mv_data, sizeof(pg)); memcpy(&pg, olddata.mv_data, sizeof(pg));
if ((rc2 = mdb_page_get(mc->mc_txn, pg, &omp, &level)) != 0) if ((rc2 = mdb_page_get(mc, pg, &omp, &level)) != 0)
return rc2; return rc2;
ovpages = omp->mp_pages; ovpages = omp->mp_pages;
@ -7678,7 +7679,7 @@ mdb_cursor_del(MDB_cursor *mc, unsigned int flags)
pgno_t pg; pgno_t pg;
memcpy(&pg, NODEDATA(leaf), sizeof(pg)); memcpy(&pg, NODEDATA(leaf), sizeof(pg));
if ((rc = mdb_page_get(mc->mc_txn, pg, &omp, NULL)) || if ((rc = mdb_page_get(mc, pg, &omp, NULL)) ||
(rc = mdb_ovpage_free(mc, omp))) (rc = mdb_ovpage_free(mc, omp)))
goto fail; goto fail;
} }
@ -8837,7 +8838,7 @@ mdb_rebalance(MDB_cursor *mc)
if (rc) if (rc)
return rc; return rc;
mc->mc_db->md_root = NODEPGNO(NODEPTR(mp, 0)); mc->mc_db->md_root = NODEPGNO(NODEPTR(mp, 0));
rc = mdb_page_get(mc->mc_txn,mc->mc_db->md_root,&mc->mc_pg[0],NULL); rc = mdb_page_get(mc, mc->mc_db->md_root, &mc->mc_pg[0], NULL);
if (rc) if (rc)
return rc; return rc;
mc->mc_db->md_depth--; mc->mc_db->md_depth--;
@ -8898,7 +8899,7 @@ mdb_rebalance(MDB_cursor *mc)
DPUTS("reading right neighbor"); DPUTS("reading right neighbor");
mn.mc_ki[ptop]++; mn.mc_ki[ptop]++;
node = NODEPTR(mc->mc_pg[ptop], mn.mc_ki[ptop]); node = NODEPTR(mc->mc_pg[ptop], mn.mc_ki[ptop]);
rc = mdb_page_get(mc->mc_txn,NODEPGNO(node),&mn.mc_pg[mn.mc_top],NULL); rc = mdb_page_get(mc, NODEPGNO(node), &mn.mc_pg[mn.mc_top], NULL);
if (rc) if (rc)
return rc; return rc;
mn.mc_ki[mn.mc_top] = 0; mn.mc_ki[mn.mc_top] = 0;
@ -8910,7 +8911,7 @@ mdb_rebalance(MDB_cursor *mc)
DPUTS("reading left neighbor"); DPUTS("reading left neighbor");
mn.mc_ki[ptop]--; mn.mc_ki[ptop]--;
node = NODEPTR(mc->mc_pg[ptop], mn.mc_ki[ptop]); node = NODEPTR(mc->mc_pg[ptop], mn.mc_ki[ptop]);
rc = mdb_page_get(mc->mc_txn,NODEPGNO(node),&mn.mc_pg[mn.mc_top],NULL); rc = mdb_page_get(mc, NODEPGNO(node), &mn.mc_pg[mn.mc_top], NULL);
if (rc) if (rc)
return rc; return rc;
mn.mc_ki[mn.mc_top] = NUMKEYS(mn.mc_pg[mn.mc_top]) - 1; mn.mc_ki[mn.mc_top] = NUMKEYS(mn.mc_pg[mn.mc_top]) - 1;
@ -9652,7 +9653,6 @@ static int ESECT
mdb_env_cwalk(mdb_copy *my, pgno_t *pg, int flags) mdb_env_cwalk(mdb_copy *my, pgno_t *pg, int flags)
{ {
MDB_cursor mc; MDB_cursor mc;
MDB_txn *txn = my->mc_txn;
MDB_node *ni; MDB_node *ni;
MDB_page *mo, *mp, *leaf; MDB_page *mo, *mp, *leaf;
char *buf, *ptr; char *buf, *ptr;
@ -9665,9 +9665,9 @@ mdb_env_cwalk(mdb_copy *my, pgno_t *pg, int flags)
mc.mc_snum = 1; mc.mc_snum = 1;
mc.mc_top = 0; mc.mc_top = 0;
mc.mc_txn = txn; mc.mc_txn = my->mc_txn;
rc = mdb_page_get(my->mc_txn, *pg, &mc.mc_pg[0], NULL); rc = mdb_page_get(&mc, *pg, &mc.mc_pg[0], NULL);
if (rc) if (rc)
return rc; return rc;
rc = mdb_page_search_root(&mc, NULL, MDB_PS_FIRST); rc = mdb_page_search_root(&mc, NULL, MDB_PS_FIRST);
@ -9711,7 +9711,7 @@ mdb_env_cwalk(mdb_copy *my, pgno_t *pg, int flags)
} }
memcpy(&pg, NODEDATA(ni), sizeof(pg)); memcpy(&pg, NODEDATA(ni), sizeof(pg));
rc = mdb_page_get(txn, pg, &omp, NULL); rc = mdb_page_get(&mc, pg, &omp, NULL);
if (rc) if (rc)
goto done; goto done;
if (my->mc_wlen[toggle] >= MDB_WBUF) { if (my->mc_wlen[toggle] >= MDB_WBUF) {
@ -9762,7 +9762,7 @@ mdb_env_cwalk(mdb_copy *my, pgno_t *pg, int flags)
again: again:
ni = NODEPTR(mp, mc.mc_ki[mc.mc_top]); ni = NODEPTR(mp, mc.mc_ki[mc.mc_top]);
pg = NODEPGNO(ni); pg = NODEPGNO(ni);
rc = mdb_page_get(txn, pg, &mp, NULL); rc = mdb_page_get(&mc, pg, &mp, NULL);
if (rc) if (rc)
goto done; goto done;
mc.mc_top++; mc.mc_top++;
@ -10435,7 +10435,7 @@ mdb_drop0(MDB_cursor *mc, int subs)
#ifdef MDB_VL32 #ifdef MDB_VL32
/* bump refcount for mx's pages */ /* bump refcount for mx's pages */
for (i=0; i<mc->mc_snum; i++) for (i=0; i<mc->mc_snum; i++)
mdb_page_get(txn, mc->mc_pg[i]->mp_pgno, &mx.mc_pg[i], NULL); mdb_page_get(&mx, mc->mc_pg[i]->mp_pgno, &mx.mc_pg[i], NULL);
#endif #endif
while (mc->mc_snum > 0) { while (mc->mc_snum > 0) {
MDB_page *mp = mc->mc_pg[mc->mc_top]; MDB_page *mp = mc->mc_pg[mc->mc_top];
@ -10447,7 +10447,7 @@ mdb_drop0(MDB_cursor *mc, int subs)
MDB_page *omp; MDB_page *omp;
pgno_t pg; pgno_t pg;
memcpy(&pg, NODEDATA(ni), sizeof(pg)); memcpy(&pg, NODEDATA(ni), sizeof(pg));
rc = mdb_page_get(txn, pg, &omp, NULL); rc = mdb_page_get(mc, pg, &omp, NULL);
if (rc != 0) if (rc != 0)
goto done; goto done;
mdb_cassert(mc, IS_OVERFLOW(omp)); mdb_cassert(mc, IS_OVERFLOW(omp));

Loading…
Cancel
Save