unsigned i, j;
int rc = MDB_SUCCESS, level;
- /* Mark pages seen by cursors */
- if (mc->mc_flags & C_UNTRACK)
- mc = NULL; /* will find mc in mt_cursors */
- for (i = txn->mt_numdbs;; mc = txn->mt_cursors[--i]) {
- for (; mc; mc=mc->mc_next) {
- if (!(mc->mc_flags & C_INITIALIZED))
- continue;
+ /* Mark pages seen by cursors: First m0, then tracked cursors */
+ for (i = txn->mt_numdbs;; ) {
+ if (mc->mc_flags & C_INITIALIZED) {
for (m3 = mc;; m3 = &mx->mx_cursor) {
mp = NULL;
for (j=0; j<m3->mc_snum; j++) {
break;
}
}
- if (i == 0)
- break;
+ mc = mc->mc_next;
+ for (; !mc || mc == m0; mc = txn->mt_cursors[--i])
+ if (i == 0)
+ goto mark_done;
}
+mark_done:
if (all) {
/* Mark dirty root pages */
for (i=0; i<txn->mt_numdbs; i++) {
MDB_CURSOR_UNREF(mc, 0);
}
if (mc && !mc->mc_backup) {
- /* remove from txn, if tracked */
+ /* Remove from txn, if tracked.
+ * A read-only txn (!C_UNTRACK) may have been freed already,
+ * so do not peek inside it. Only write txns track cursors.
+ */
if ((mc->mc_flags & C_UNTRACK) && mc->mc_txn->mt_cursors) {
MDB_cursor **prev = &mc->mc_txn->mt_cursors[mc->mc_dbi];
while (*prev && *prev != mc) prev = &(*prev)->mc_next;
* run out of space, triggering a split. We need this
* cursor to be consistent until the end of the rebalance.
*/
- mc.mc_flags |= C_UNTRACK;
mc.mc_next = txn->mt_cursors[dbi];
txn->mt_cursors[dbi] = &mc;
rc = mdb_cursor_del(&mc, flags);