Maintain MDB_cursor.mc_top

vmware
Hallvard Furuseth 11 years ago
parent 99ea7669a3
commit 0f9b79e12c
  1. 21
      libraries/liblmdb/mdb.c

@ -5553,14 +5553,14 @@ fetchm:
return rc; return rc;
} }
/** Touch all the pages in the cursor stack. /** Touch all the pages in the cursor stack. Set mc_top.
* Makes sure all the pages are writable, before attempting a write operation. * Makes sure all the pages are writable, before attempting a write operation.
* @param[in] mc The cursor to operate on. * @param[in] mc The cursor to operate on.
*/ */
static int static int
mdb_cursor_touch(MDB_cursor *mc) mdb_cursor_touch(MDB_cursor *mc)
{ {
int rc; int rc = MDB_SUCCESS;
if (mc->mc_dbi > MAIN_DBI && !(*mc->mc_dbflag & DB_DIRTY)) { if (mc->mc_dbi > MAIN_DBI && !(*mc->mc_dbflag & DB_DIRTY)) {
MDB_cursor mc2; MDB_cursor mc2;
@ -5571,13 +5571,14 @@ mdb_cursor_touch(MDB_cursor *mc)
return rc; return rc;
*mc->mc_dbflag |= DB_DIRTY; *mc->mc_dbflag |= DB_DIRTY;
} }
for (mc->mc_top = 0; mc->mc_top < mc->mc_snum; mc->mc_top++) { mc->mc_top = 0;
rc = mdb_page_touch(mc); if (mc->mc_snum) {
if (rc) do {
return rc; rc = mdb_page_touch(mc);
} while (!rc && ++(mc->mc_top) < mc->mc_snum);
mc->mc_top = mc->mc_snum-1;
} }
mc->mc_top = mc->mc_snum-1; return rc;
return MDB_SUCCESS;
} }
/** Do not spill pages to disk if txn is getting full, may fail instead */ /** Do not spill pages to disk if txn is getting full, may fail instead */
@ -5640,6 +5641,7 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
} else if (mc->mc_db->md_root == P_INVALID) { } else if (mc->mc_db->md_root == P_INVALID) {
/* new database, cursor has nothing to point to */ /* new database, cursor has nothing to point to */
mc->mc_snum = 0; mc->mc_snum = 0;
mc->mc_top = 0;
mc->mc_flags &= ~C_INITIALIZED; mc->mc_flags &= ~C_INITIALIZED;
rc = MDB_NO_ROOT; rc = MDB_NO_ROOT;
} else { } else {
@ -6499,6 +6501,7 @@ mdb_xcursor_init1(MDB_cursor *mc, MDB_node *node)
memcpy(&mx->mx_db, NODEDATA(node), sizeof(MDB_db)); memcpy(&mx->mx_db, NODEDATA(node), sizeof(MDB_db));
mx->mx_cursor.mc_pg[0] = 0; mx->mx_cursor.mc_pg[0] = 0;
mx->mx_cursor.mc_snum = 0; mx->mx_cursor.mc_snum = 0;
mx->mx_cursor.mc_top = 0;
mx->mx_cursor.mc_flags = C_SUB; mx->mx_cursor.mc_flags = C_SUB;
} else { } else {
MDB_page *fp = NODEDATA(node); MDB_page *fp = NODEDATA(node);
@ -6511,8 +6514,8 @@ mdb_xcursor_init1(MDB_cursor *mc, MDB_node *node)
mx->mx_db.md_entries = NUMKEYS(fp); mx->mx_db.md_entries = NUMKEYS(fp);
COPY_PGNO(mx->mx_db.md_root, fp->mp_pgno); COPY_PGNO(mx->mx_db.md_root, fp->mp_pgno);
mx->mx_cursor.mc_snum = 1; mx->mx_cursor.mc_snum = 1;
mx->mx_cursor.mc_flags = C_INITIALIZED|C_SUB;
mx->mx_cursor.mc_top = 0; mx->mx_cursor.mc_top = 0;
mx->mx_cursor.mc_flags = C_INITIALIZED|C_SUB;
mx->mx_cursor.mc_pg[0] = fp; mx->mx_cursor.mc_pg[0] = fp;
mx->mx_cursor.mc_ki[0] = 0; mx->mx_cursor.mc_ki[0] = 0;
if (mc->mc_db->md_flags & MDB_DUPFIXED) { if (mc->mc_db->md_flags & MDB_DUPFIXED) {

Loading…
Cancel
Save