From b802bcf7040110e1f0768d9d9ffa88dabd4bd5e7 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 5 Jul 2012 16:40:46 -0700 Subject: [PATCH] Partial revert of 13c663f666ac28d7a72cbe644d393fc8d2dd9881 Don't re-use free pages so soon; that leaves us vulnerable to DB corruption if data syncs successfully but meta doesn't. --- libraries/libmdb/mdb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 3b0b66fa19..fe89a7a45a 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -1220,7 +1220,11 @@ mdb_page_alloc(MDB_cursor *mc, int num) pgno_t pgno = P_INVALID; MDB_ID2 mid; - if (txn->mt_txnid > 2) { + /* The free list won't have any content at all until txn 2 has + * committed. The pages from txn 1 will be free after txn 3 has + * committed. It will be safe to re-use them during txn 4. + */ + if (txn->mt_txnid > 3) { if (!txn->mt_env->me_pghead && txn->mt_dbs[FREE_DBI].md_root != P_INVALID) { @@ -1253,7 +1257,7 @@ again: { unsigned int i; - oldest = txn->mt_txnid - 1; + oldest = txn->mt_txnid - 2; for (i=0; imt_env->me_txns->mti_numreaders; i++) { txnid_t mr = txn->mt_env->me_txns->mti_readers[i].mr_txnid; if (mr && mr < oldest) -- 2.39.5