From 78da9e52c40efe4bfd90b76f90c885b1512ee882 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 16 Sep 2019 20:55:07 +0300 Subject: [PATCH] mdbx: return consistency info from mdbx_env_stat(). Change-Id: Ia53259a8590118adf01b03a6eb7835c62376ad1f --- src/elements/core.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/elements/core.c b/src/elements/core.c index 173f12c5..43009ae6 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -12493,9 +12493,20 @@ int __cold mdbx_env_stat2(const MDBX_env *env, const MDBX_txn *txn, if (unlikely(bytes != sizeof(MDBX_stat))) return MDBX_EINVAL; - const MDBX_db *db = - txn ? &txn->mt_dbs[MAIN_DBI] : &mdbx_meta_head(env)->mm_dbs[MAIN_DBI]; - return mdbx_stat0(txn ? txn->mt_env : env, db, arg); + if (txn) + return mdbx_stat0(txn->mt_env, &txn->mt_dbs[MAIN_DBI], arg); + + while (1) { + const MDBX_meta *const recent_meta = mdbx_meta_head(env); + const txnid_t txnid = mdbx_meta_txnid_fluid(env, recent_meta); + const int err = mdbx_stat0(env, &recent_meta->mm_dbs[MAIN_DBI], arg); + if (unlikely(err != MDBX_SUCCESS)) + return err; + mdbx_compiler_barrier(); + if (likely(txnid == mdbx_meta_txnid_fluid(env, recent_meta) && + recent_meta == mdbx_meta_head(env))) + return MDBX_SUCCESS; + } } int __cold mdbx_env_info(MDBX_env *env, MDBX_envinfo *arg, size_t bytes) {