CURSOR_TMP_[UN]TRACK() -> WITH_CURSOR_TRACKING()

vl32b
Hallvard Furuseth 9 years ago
parent 85d2f9804a
commit fae01c8df5
  1. 46
      libraries/liblmdb/mdb.c

@ -7645,21 +7645,21 @@ mdb_update_key(MDB_cursor *mc, MDB_val *key)
static void static void
mdb_cursor_copy(const MDB_cursor *csrc, MDB_cursor *cdst); mdb_cursor_copy(const MDB_cursor *csrc, MDB_cursor *cdst);
/** Track a temporary cursor */ /** Perform \b act while tracking temporary cursor \b mn */
#define CURSOR_TMP_TRACK(mc, mn, dummy, tracked) \ #define WITH_CURSOR_TRACKING(mn, act) do { \
if (mc->mc_flags & C_SUB) { \ MDB_cursor dummy, *tracked, **tp = &(mn).mc_txn->mt_cursors[mn.mc_dbi]; \
if ((mn).mc_flags & C_SUB) { \
dummy.mc_flags = C_INITIALIZED; \ dummy.mc_flags = C_INITIALIZED; \
dummy.mc_xcursor = (MDB_xcursor *)&mn; \ dummy.mc_xcursor = (MDB_xcursor *)&(mn); \
tracked = &dummy; \ tracked = &dummy; \
} else { \ } else { \
tracked = &mn; \ tracked = &(mn); \
} \ } \
tracked->mc_next = mc->mc_txn->mt_cursors[mc->mc_dbi]; \ tracked->mc_next = *tp; \
mc->mc_txn->mt_cursors[mc->mc_dbi] = tracked *tp = tracked; \
{ act; } \
/** Stop tracking a temporary cursor */ *tp = tracked->mc_next; \
#define CURSOR_TMP_UNTRACK(mc, tracked) \ } while (0)
mc->mc_txn->mt_cursors[mc->mc_dbi] = tracked->mc_next
/** Move a node from csrc to cdst. /** Move a node from csrc to cdst.
*/ */
@ -7816,7 +7816,6 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
*/ */
if (csrc->mc_ki[csrc->mc_top] == 0) { if (csrc->mc_ki[csrc->mc_top] == 0) {
if (csrc->mc_ki[csrc->mc_top-1] != 0) { if (csrc->mc_ki[csrc->mc_top-1] != 0) {
MDB_cursor dummy, *tracked;
if (IS_LEAF2(csrc->mc_pg[csrc->mc_top])) { if (IS_LEAF2(csrc->mc_pg[csrc->mc_top])) {
key.mv_data = LEAF2KEY(csrc->mc_pg[csrc->mc_top], 0, key.mv_size); key.mv_data = LEAF2KEY(csrc->mc_pg[csrc->mc_top], 0, key.mv_size);
} else { } else {
@ -7830,9 +7829,8 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
mn.mc_snum--; mn.mc_snum--;
mn.mc_top--; mn.mc_top--;
/* We want mdb_rebalance to find mn when doing fixups */ /* We want mdb_rebalance to find mn when doing fixups */
CURSOR_TMP_TRACK(csrc, mn, dummy, tracked); WITH_CURSOR_TRACKING(mn,
rc = mdb_update_key(&mn, &key); rc = mdb_update_key(&mn, &key));
CURSOR_TMP_UNTRACK(csrc, tracked);
if (rc) if (rc)
return rc; return rc;
} }
@ -7849,7 +7847,6 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
if (cdst->mc_ki[cdst->mc_top] == 0) { if (cdst->mc_ki[cdst->mc_top] == 0) {
if (cdst->mc_ki[cdst->mc_top-1] != 0) { if (cdst->mc_ki[cdst->mc_top-1] != 0) {
MDB_cursor dummy, *tracked;
if (IS_LEAF2(csrc->mc_pg[csrc->mc_top])) { if (IS_LEAF2(csrc->mc_pg[csrc->mc_top])) {
key.mv_data = LEAF2KEY(cdst->mc_pg[cdst->mc_top], 0, key.mv_size); key.mv_data = LEAF2KEY(cdst->mc_pg[cdst->mc_top], 0, key.mv_size);
} else { } else {
@ -7863,9 +7860,8 @@ mdb_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft)
mn.mc_snum--; mn.mc_snum--;
mn.mc_top--; mn.mc_top--;
/* We want mdb_rebalance to find mn when doing fixups */ /* We want mdb_rebalance to find mn when doing fixups */
CURSOR_TMP_TRACK(cdst, mn, dummy, tracked); WITH_CURSOR_TRACKING(mn,
rc = mdb_update_key(&mn, &key); rc = mdb_update_key(&mn, &key));
CURSOR_TMP_UNTRACK(cdst, tracked);
if (rc) if (rc)
return rc; return rc;
} }
@ -8224,13 +8220,11 @@ mdb_rebalance(MDB_cursor *mc)
if (!fromleft) { if (!fromleft) {
rc = mdb_page_merge(&mn, mc); rc = mdb_page_merge(&mn, mc);
} else { } else {
MDB_cursor dummy, *tracked;
oldki += NUMKEYS(mn.mc_pg[mn.mc_top]); oldki += NUMKEYS(mn.mc_pg[mn.mc_top]);
mn.mc_ki[mn.mc_top] += mc->mc_ki[mn.mc_top] + 1; mn.mc_ki[mn.mc_top] += mc->mc_ki[mn.mc_top] + 1;
/* We want mdb_rebalance to find mn when doing fixups */ /* We want mdb_rebalance to find mn when doing fixups */
CURSOR_TMP_TRACK(mc, mn, dummy, tracked); WITH_CURSOR_TRACKING(mn,
rc = mdb_page_merge(mc, &mn); rc = mdb_page_merge(mc, &mn));
CURSOR_TMP_UNTRACK(mc, tracked);
mdb_cursor_copy(&mn, mc); mdb_cursor_copy(&mn, mc);
} }
mc->mc_flags &= ~C_EOF; mc->mc_flags &= ~C_EOF;
@ -8594,14 +8588,12 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
*/ */
if (SIZELEFT(mn.mc_pg[ptop]) < mdb_branch_size(env, &sepkey)) { if (SIZELEFT(mn.mc_pg[ptop]) < mdb_branch_size(env, &sepkey)) {
int snum = mc->mc_snum; int snum = mc->mc_snum;
MDB_cursor dummy, *tracked;
mn.mc_snum--; mn.mc_snum--;
mn.mc_top--; mn.mc_top--;
did_split = 1; did_split = 1;
/* We want other splits to find mn when doing fixups */ /* We want other splits to find mn when doing fixups */
CURSOR_TMP_TRACK(mc, mn, dummy, tracked); WITH_CURSOR_TRACKING(mn,
rc = mdb_page_split(&mn, &sepkey, NULL, rp->mp_pgno, 0); rc = mdb_page_split(&mn, &sepkey, NULL, rp->mp_pgno, 0));
CURSOR_TMP_UNTRACK(mc, tracked);
if (rc) if (rc)
goto done; goto done;

Loading…
Cancel
Save