mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-19 22:18:21 +08:00
mdbx: рефакторинг mdbx_txn_straggler()
с добавлением проверки env
.
This commit is contained in:
parent
585ccdf716
commit
a89d418c91
@ -10,10 +10,11 @@ __attribute__((__no_sanitize_thread__, __noinline__))
|
|||||||
int mdbx_txn_straggler(const MDBX_txn *txn, int *percent)
|
int mdbx_txn_straggler(const MDBX_txn *txn, int *percent)
|
||||||
{
|
{
|
||||||
int rc = check_txn(txn, MDBX_TXN_BLOCKED);
|
int rc = check_txn(txn, MDBX_TXN_BLOCKED);
|
||||||
|
if (likely(rc == MDBX_SUCCESS))
|
||||||
|
rc = check_env(txn->env, true);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return LOG_IFERR((rc > 0) ? -rc : rc);
|
return LOG_IFERR((rc > 0) ? -rc : rc);
|
||||||
|
|
||||||
MDBX_env *env = txn->env;
|
|
||||||
if (unlikely((txn->flags & MDBX_TXN_RDONLY) == 0)) {
|
if (unlikely((txn->flags & MDBX_TXN_RDONLY) == 0)) {
|
||||||
if (percent)
|
if (percent)
|
||||||
*percent = (int)((txn->geo.first_unallocated * UINT64_C(100) + txn->geo.end_pgno / 2) / txn->geo.end_pgno);
|
*percent = (int)((txn->geo.first_unallocated * UINT64_C(100) + txn->geo.end_pgno / 2) / txn->geo.end_pgno);
|
||||||
@ -21,15 +22,15 @@ int mdbx_txn_straggler(const MDBX_txn *txn, int *percent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
txnid_t lag;
|
txnid_t lag;
|
||||||
troika_t troika = meta_tap(env);
|
troika_t troika = meta_tap(txn->env);
|
||||||
do {
|
do {
|
||||||
const meta_ptr_t head = meta_recent(env, &troika);
|
const meta_ptr_t head = meta_recent(txn->env, &troika);
|
||||||
if (percent) {
|
if (percent) {
|
||||||
const pgno_t maxpg = head.ptr_v->geometry.now;
|
const pgno_t maxpg = head.ptr_v->geometry.now;
|
||||||
*percent = (int)((head.ptr_v->geometry.first_unallocated * UINT64_C(100) + maxpg / 2) / maxpg);
|
*percent = (int)((head.ptr_v->geometry.first_unallocated * UINT64_C(100) + maxpg / 2) / maxpg);
|
||||||
}
|
}
|
||||||
lag = (head.txnid - txn->txnid) / xMDBX_TXNID_STEP;
|
lag = (head.txnid - txn->txnid) / xMDBX_TXNID_STEP;
|
||||||
} while (unlikely(meta_should_retry(env, &troika)));
|
} while (unlikely(meta_should_retry(txn->env, &troika)));
|
||||||
|
|
||||||
return (lag > INT_MAX) ? INT_MAX : (int)lag;
|
return (lag > INT_MAX) ? INT_MAX : (int)lag;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user