From 86496e4480f9ccd6a68e8981344ea3afb464d7bc Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 28 Sep 2019 11:23:20 +0300 Subject: [PATCH] mdbx: refine retired-next-reader insode mdbx_txn_info(). Change-Id: Iba57365cc4b7f4f09a0698502bc7aafcb6e67478 --- mdbx.h | 14 +++++++------- src/elements/core.c | 10 ++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mdbx.h b/mdbx.h index c754751c..275a3058 100644 --- a/mdbx.h +++ b/mdbx.h @@ -2132,13 +2132,13 @@ typedef struct MDBX_txn_info { For WRITE transaction: the space inside transaction that left to MDBX_TXN_FULL error. */ - uint64_t - txn_space_dirty; /* For READ-ONLY transaction (provided if scan_rlt=true): - The retired distance for next more recent reader, i.e. - the space that actually become available for reuse - when only this transaction will be finished. For WRITE - transaction: The summarized size of the dirty database - pages that generated during this transaction. */ + uint64_t txn_space_dirty; /* For READ-ONLY transaction (provided if + scan_rlt=true): The space that actually become + available for reuse when only this transaction + will be finished. + For WRITE transaction: The summarized size of the + dirty database pages that generated during this + transaction. */ } MDBX_txn_info; /* Return information about the MDBX transaction. diff --git a/src/elements/core.c b/src/elements/core.c index a5e575f1..d603ce73 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -4104,6 +4104,7 @@ int mdbx_txn_info(MDBX_txn *txn, MDBX_txn_info *info, int scan_rlt) { env, (pgno_t)(head_retired - txn->mt_ro_reader->mr_snapshot_pages_retired)); + size_t retired_next_reader = 0; MDBX_lockinfo *const lck = env->me_lck; if (scan_rlt && info->txn_reader_lag > 1 && lck) { /* find next more recent reader */ @@ -4122,15 +4123,20 @@ int mdbx_txn_info(MDBX_txn *txn, MDBX_txn_info *info, int scan_rlt) { lck->mti_readers[i].mr_snapshot_pages_retired) || snap_txnid != safe64_read(&lck->mti_readers[i].mr_txnid)) goto retry; - if (snap_txnid > txn->mt_txnid && snap_txnid < next_reader) { + if (snap_txnid <= txn->mt_txnid) { + retired_next_reader = 0; + break; + } + if (snap_txnid < next_reader) { next_reader = snap_txnid; - info->txn_space_dirty = pgno2bytes( + retired_next_reader = pgno2bytes( env, (pgno_t)(snap_retired - txn->mt_ro_reader->mr_snapshot_pages_retired)); } } } } + info->txn_space_dirty = retired_next_reader; } } else { info->txn_space_limit_soft = pgno2bytes(env, txn->mt_geo.now);