From 9e07b71c2716a175169c60612c0209c1228a6cb5 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Thu, 27 Apr 2017 01:26:33 +0300 Subject: [PATCH] mdbx: fix snap-state bug. Change-Id: I8700209ab012bfef21c88fe06c39b80a640291c6 --- src/mdbx.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index f36bbc37..0046d5e2 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -2185,22 +2185,21 @@ static int mdbx_txn_renew0(MDB_txn *txn, unsigned flags) { mdbx_thread_rthc_set(env->me_txkey, r); } - while ((env->me_flags & MDB_FATAL_ERROR) == 0) { + while (1) { MDB_meta *const meta = mdbx_meta_head(txn->mt_env); - txnid_t lead = meta->mm_txnid; - r->mr_txnid = lead; + const txnid_t snap = meta->mm_txnid; + r->mr_txnid = snap; mdbx_coherent_barrier(); - txnid_t snap = mdbx_meta_head(txn->mt_env)->mm_txnid; + /* Snap the state from current meta-head */ + txn->mt_txnid = snap; + txn->mt_next_pgno = meta->mm_last_pg + 1; + memcpy(txn->mt_dbs, meta->mm_dbs, CORE_DBS * sizeof(MDB_db)); + txn->mt_canary = meta->mm_canary; + /* LY: Retry on a race, ITS#7970. */ - if (likely(lead == snap)) { - txn->mt_txnid = lead; - txn->mt_next_pgno = meta->mm_last_pg + 1; - /* Copy the DB info and flags */ - memcpy(txn->mt_dbs, meta->mm_dbs, CORE_DBS * sizeof(MDB_db)); - txn->mt_canary = meta->mm_canary; + if (likely(meta == mdbx_meta_head(txn->mt_env) && snap == meta->mm_txnid)) break; - } } txn->mt_u.reader = r;