From 75ab3716fb7cc9ffec0dd4336666bc0d2b25c60c Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 9 Dec 2015 20:07:51 +0300 Subject: [PATCH] mdbx: avoid tsan-trap in mdbx_txn_straggler(). Change-Id: Ib62cdd5592e6001a1734c321f3801722e4dcf7e4 --- mdb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mdb.c b/mdb.c index c54f380c..d59c959e 100644 --- a/mdb.c +++ b/mdb.c @@ -3063,8 +3063,8 @@ mdb_dbis_update(MDB_txn *txn, int keep) env->me_numdbs = n; } -int -mdbx_txn_straggler(MDB_txn *txn, int *percent) +ATTRIBUTE_NO_SANITIZE_THREAD /* LY: avoid tsan-trap by me_txn, mm_last_pg and mt_next_pgno */ +int mdbx_txn_straggler(MDB_txn *txn, int *percent) { MDB_env *env; MDB_meta *meta; @@ -3082,9 +3082,11 @@ mdbx_txn_straggler(MDB_txn *txn, int *percent) env = txn->mt_env; meta = mdb_meta_head_r(env); if (percent) { - long cent = env->me_maxpg / 100; - long last = env->me_txn ? env->me_txn0->mt_next_pgno : meta->mm_last_pg; - *percent = (last + cent / 2) / (cent ? cent : 1); + size_t maxpg = env->me_maxpg; + size_t last = meta->mm_last_pg + 1; + if (env->me_txn) + last = env->me_txn0->mt_next_pgno; + *percent = (last + maxpg / 2) * 100u / maxpg; } lag = meta->mm_txnid - txn->mt_u.reader->mr_txnid; return (0 > (long) lag) ? ~0u >> 1: lag;