* Re-use old malloc'd pages first for singletons, otherwise just malloc.
*/
static MDB_page *
-mdb_page_malloc(MDB_cursor *mc, unsigned num)
+mdb_page_malloc(MDB_txn *txn, unsigned num)
{
- MDB_env *env = mc->mc_txn->mt_env;
+ MDB_env *env = txn->mt_env;
MDB_page *ret = env->me_dpages;
size_t sz = env->me_psize;
if (num == 1) {
}
np = (MDB_page *)(env->me_map + env->me_psize * pgno);
} else {
- if (!(np = mdb_page_malloc(mc, num)))
+ if (!(np = mdb_page_malloc(txn, num)))
return ENOMEM;
if (pgno == P_INVALID) {
pgno = txn->mt_next_pgno;
mdb_page_touch(MDB_cursor *mc)
{
MDB_page *mp = mc->mc_pg[mc->mc_top], *np;
+ MDB_txn *txn = mc->mc_txn;
MDB_cursor *m2, *m3;
MDB_dbi dbi;
pgno_t pgno;
pgno = np->mp_pgno;
DPRINTF("touched db %u page %zu -> %zu", mc->mc_dbi,mp->mp_pgno,pgno);
assert(mp->mp_pgno != pgno);
- mdb_midl_append(&mc->mc_txn->mt_free_pgs, mp->mp_pgno);
+ mdb_midl_append(&txn->mt_free_pgs, mp->mp_pgno);
/* Update the parent page, if any, to point to the new page */
if (mc->mc_top) {
MDB_page *parent = mc->mc_pg[mc->mc_top-1];
} else {
mc->mc_db->md_root = pgno;
}
- } else if (mc->mc_txn->mt_parent && !(mp->mp_flags & P_SUBP)) {
- MDB_ID2 mid, *dl = mc->mc_txn->mt_u.dirty_list;
+ } else if (txn->mt_parent && !IS_SUBP(mp)) {
+ MDB_ID2 mid, *dl = txn->mt_u.dirty_list;
pgno = mp->mp_pgno;
/* If txn has a parent, make sure the page is in our
* dirty list.
}
assert(dl[0].mid < MDB_IDL_UM_MAX);
/* No - copy it */
- np = mdb_page_malloc(mc, 1);
+ np = mdb_page_malloc(txn, 1);
if (!np)
return ENOMEM;
mid.mid = pgno;
return 0;
}
- mdb_page_copy(np, mp, mc->mc_txn->mt_env->me_psize);
+ mdb_page_copy(np, mp, txn->mt_env->me_psize);
np->mp_pgno = pgno;
np->mp_flags |= P_DIRTY;
dbi = mc->mc_dbi;
if (mc->mc_flags & C_SUB) {
dbi--;
- for (m2 = mc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
+ for (m2 = txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
m3 = &m2->mc_xcursor->mx_cursor;
if (m3->mc_snum < mc->mc_snum) continue;
if (m3->mc_pg[mc->mc_top] == mp)
m3->mc_pg[mc->mc_top] = np;
}
} else {
- for (m2 = mc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
+ for (m2 = txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
if (m2->mc_snum < mc->mc_snum) continue;
if (m2->mc_pg[mc->mc_top] == mp) {
m2->mc_pg[mc->mc_top] = np;
mdb_midl_free(txn->mt_free_pgs);
free(txn->mt_u.dirty_list);
return;
- } else {
- if (mdb_midl_shrink(&txn->mt_free_pgs))
- env->me_free_pgs = txn->mt_free_pgs;
}
- txn->mt_env->me_pghead = NULL;
- txn->mt_env->me_pglast = 0;
+ if (mdb_midl_shrink(&txn->mt_free_pgs))
+ env->me_free_pgs = txn->mt_free_pgs;
+ env->me_pghead = NULL;
+ env->me_pglast = 0;
env->me_txn = NULL;
/* The writer mutex was locked in mdb_txn_begin. */
* readers will get consistent data regardless of how fresh or
* how stale their view of these values is.
*/
- txn->mt_env->me_txns->mti_txnid = txn->mt_txnid;
+ env->me_txns->mti_txnid = txn->mt_txnid;
return MDB_SUCCESS;
}
if (level > 1) {
/* It is writable only in a parent txn */
size_t sz = (size_t) psize * ovpages, off;
- MDB_page *np = mdb_page_malloc(mc, ovpages);
+ MDB_page *np = mdb_page_malloc(mc->mc_txn, ovpages);
MDB_ID2 id2;
if (!np)
return ENOMEM;
/* Move half of the keys to the right sibling. */
/* grab a page to hold a temporary copy */
- copy = mdb_page_malloc(mc, 1);
+ copy = mdb_page_malloc(mc->mc_txn, 1);
if (copy == NULL)
return ENOMEM;
rc = mdb_page_search(mc, NULL, 0);
if (rc == MDB_SUCCESS) {
+ MDB_txn *txn = mc->mc_txn;
MDB_node *ni;
MDB_cursor mx;
unsigned int i;
mdb_cursor_copy(mc, &mx);
while (mc->mc_snum > 0) {
- if (IS_LEAF(mc->mc_pg[mc->mc_top])) {
- for (i=0; i<NUMKEYS(mc->mc_pg[mc->mc_top]); i++) {
- ni = NODEPTR(mc->mc_pg[mc->mc_top], i);
+ MDB_page *mp = mc->mc_pg[mc->mc_top];
+ unsigned n = NUMKEYS(mp);
+ if (IS_LEAF(mp)) {
+ for (i=0; i<n; i++) {
+ ni = NODEPTR(mp, i);
if (ni->mn_flags & F_BIGDATA) {
int j, ovpages;
MDB_page *omp;
pgno_t pg;
memcpy(&pg, NODEDATA(ni), sizeof(pg));
- rc = mdb_page_get(mc->mc_txn, pg, &omp, NULL);
+ rc = mdb_page_get(txn, pg, &omp, NULL);
if (rc != 0)
return rc;
assert(IS_OVERFLOW(omp));
ovpages = omp->mp_pages;
for (j=0; j<ovpages; j++) {
- mdb_midl_append(&mc->mc_txn->mt_free_pgs, pg);
+ mdb_midl_append(&txn->mt_free_pgs, pg);
pg++;
}
} else if (subs && (ni->mn_flags & F_SUBDATA)) {
}
}
} else {
- for (i=0; i<NUMKEYS(mc->mc_pg[mc->mc_top]); i++) {
+ for (i=0; i<n; i++) {
pgno_t pg;
- ni = NODEPTR(mc->mc_pg[mc->mc_top], i);
+ ni = NODEPTR(mp, i);
pg = NODEPGNO(ni);
/* free it */
- mdb_midl_append(&mc->mc_txn->mt_free_pgs, pg);
+ mdb_midl_append(&txn->mt_free_pgs, pg);
}
}
if (!mc->mc_top)
}
}
/* free it */
- mdb_midl_append(&mc->mc_txn->mt_free_pgs,
- mc->mc_db->md_root);
+ mdb_midl_append(&txn->mt_free_pgs, mc->mc_db->md_root);
}
return 0;
}