Skip to content

Commit

Permalink
WT-2021 Fix a bug moving the oldest ID forward (introduced by WT-1967).
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelcahill committed Aug 6, 2015
1 parent b52d2d3 commit 62d69b2
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/txn/txn.c
Expand Up @@ -208,15 +208,15 @@ __wt_txn_update_oldest(WT_SESSION_IMPL *session, int force)
WT_SESSION_IMPL *oldest_session;
WT_TXN_GLOBAL *txn_global;
WT_TXN_STATE *s;
uint64_t current_id, id, oldest_id, prev_oldest_id, snap_min;
uint64_t current_id, id, last_running, oldest_id, prev_oldest_id;
uint32_t i, session_cnt;
int32_t count;
int last_running_moved;

conn = S2C(session);
txn_global = &conn->txn_global;

current_id = snap_min = txn_global->current;
current_id = last_running = txn_global->current;
oldest_session = NULL;
prev_oldest_id = txn_global->oldest_id;

Expand All @@ -241,7 +241,7 @@ __wt_txn_update_oldest(WT_SESSION_IMPL *session, int force)

/* The oldest ID cannot change until the scan count goes to zero. */
prev_oldest_id = txn_global->oldest_id;
current_id = oldest_id = snap_min = txn_global->current;
current_id = oldest_id = last_running = txn_global->current;

/* Walk the array of concurrent transactions. */
WT_ORDERED_READ(session_cnt, conn->session_cnt);
Expand All @@ -256,8 +256,8 @@ __wt_txn_update_oldest(WT_SESSION_IMPL *session, int force)
*/
if ((id = s->id) != WT_TXN_NONE &&
WT_TXNID_LE(prev_oldest_id, id) &&
WT_TXNID_LT(id, snap_min))
snap_min = id;
WT_TXNID_LT(id, last_running))
last_running = id;

/*
* !!!
Expand All @@ -274,32 +274,32 @@ __wt_txn_update_oldest(WT_SESSION_IMPL *session, int force)
}
}

if (WT_TXNID_LT(snap_min, oldest_id))
oldest_id = snap_min;
if (WT_TXNID_LT(last_running, oldest_id))
oldest_id = last_running;

/* The oldest ID can't move past any named snapshots. */
if ((id = txn_global->nsnap_oldest_id) != WT_TXN_NONE &&
WT_TXNID_LT(id, oldest_id))
oldest_id = id;

/* Update the last running ID. */
last_running_moved = WT_TXNID_LT(txn_global->last_running, snap_min);
last_running_moved = WT_TXNID_LT(txn_global->last_running, last_running);

/* Update the oldest ID. */
if ((WT_TXNID_LT(prev_oldest_id, oldest_id) || last_running_moved) &&
WT_ATOMIC_CAS4(txn_global->scan_count, 1, -1)) {
WT_ORDERED_READ(session_cnt, conn->session_cnt);
for (i = 0, s = txn_global->states; i < session_cnt; i++, s++) {
if ((id = s->id) != WT_TXN_NONE &&
WT_TXNID_LT(id, snap_min))
oldest_id = id;
WT_TXNID_LT(id, last_running))
last_running = id;
if ((id = s->snap_min) != WT_TXN_NONE &&
WT_TXNID_LT(id, oldest_id))
oldest_id = id;
}

if (WT_TXNID_LT(snap_min, oldest_id))
oldest_id = snap_min;
if (WT_TXNID_LT(last_running, oldest_id))
oldest_id = last_running;

#ifdef HAVE_DIAGNOSTIC
/*
Expand All @@ -313,10 +313,11 @@ __wt_txn_update_oldest(WT_SESSION_IMPL *session, int force)
WT_ASSERT(session,
id == WT_TXN_NONE || !WT_TXNID_LT(id, oldest_id));
#endif
if (WT_TXNID_LT(txn_global->last_running, snap_min))
txn_global->last_running = snap_min;
if (WT_TXNID_LT(txn_global->last_running, last_running))
txn_global->last_running = last_running;
if (WT_TXNID_LT(txn_global->oldest_id, oldest_id))
txn_global->oldest_id = oldest_id;
WT_ASSERT(session, txn_global->scan_count == -1);
txn_global->scan_count = 0;
} else {
if (WT_VERBOSE_ISSET(session, WT_VERB_TRANSACTION) &&
Expand Down

0 comments on commit 62d69b2

Please sign in to comment.