mdbx: поправлен сбор информации о задержках, чтобы включенный аудит не искажал затраты на GC.

This commit is contained in:
Leonid Yuriev 2022-10-07 00:42:01 +03:00 committed by Леонид Юрьев (Leonid Yuriev)
parent bee7431f76
commit 0f7e5073db

View File

@ -10388,8 +10388,7 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) {
STATIC_ASSERT(MDBX_TXN_FINISHED == STATIC_ASSERT(MDBX_TXN_FINISHED ==
MDBX_TXN_BLOCKED - MDBX_TXN_HAS_CHILD - MDBX_TXN_ERROR); MDBX_TXN_BLOCKED - MDBX_TXN_HAS_CHILD - MDBX_TXN_ERROR);
const uint64_t ts_0 = latency ? osal_monotime() : 0; const uint64_t ts_0 = latency ? osal_monotime() : 0;
uint64_t ts_1 = 0, ts_2 = 0, ts_3 = 0, ts_4 = 0; uint64_t ts_1 = 0, ts_2 = 0, ts_3 = 0, ts_4 = 0, ts_5 = 0;
uint32_t audit_duration = 0;
int rc = check_txn(txn, MDBX_TXN_FINISHED); int rc = check_txn(txn, MDBX_TXN_FINISHED);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
@ -10534,7 +10533,7 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) {
ts_1 = latency ? osal_monotime() : 0; ts_1 = latency ? osal_monotime() : 0;
txn_merge(parent, txn, parent_retired_len); txn_merge(parent, txn, parent_retired_len);
ts_2 = latency ? osal_monotime() : 0; ts_2 = ts_3 = latency ? osal_monotime() : 0;
env->me_txn = parent; env->me_txn = parent;
parent->mt_child = NULL; parent->mt_child = NULL;
tASSERT(parent, dirtylist_check(parent)); tASSERT(parent, dirtylist_check(parent));
@ -10553,7 +10552,7 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) {
} }
#endif /* MDBX_ENABLE_REFUND */ #endif /* MDBX_ENABLE_REFUND */
ts_4 = ts_3 = latency ? osal_monotime() : 0; ts_4 = ts_5 = latency ? osal_monotime() : 0;
txn->mt_signature = 0; txn->mt_signature = 0;
osal_free(txn); osal_free(txn);
tASSERT(parent, audit_ex(parent, 0, false) == 0); tASSERT(parent, audit_ex(parent, 0, false) == 0);
@ -10632,12 +10631,10 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) {
? txn->mt_txnid ? txn->mt_txnid
: txn->mt_dbs[MAIN_DBI].md_mod_txnid; : txn->mt_dbs[MAIN_DBI].md_mod_txnid;
ts_2 = latency ? osal_monotime() : 0; ts_2 = ts_3 = latency ? osal_monotime() : 0;
if (AUDIT_ENABLED()) { if (AUDIT_ENABLED()) {
rc = audit_ex(txn, MDBX_PNL_GETSIZE(txn->tw.retired_pages), true); rc = audit_ex(txn, MDBX_PNL_GETSIZE(txn->tw.retired_pages), true);
const uint64_t audit_end = osal_monotime(); ts_3 = osal_monotime();
audit_duration = osal_monotime_to_16dot16(audit_end - ts_2);
ts_2 = audit_end;
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
goto fail; goto fail;
} }
@ -10668,7 +10665,7 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) {
} }
/* TODO: use ctx.flush_begin & ctx.flush_end for range-sync */ /* TODO: use ctx.flush_begin & ctx.flush_end for range-sync */
ts_3 = latency ? osal_monotime() : 0; ts_4 = latency ? osal_monotime() : 0;
MDBX_meta meta; MDBX_meta meta;
memcpy(meta.mm_magic_and_version, head.ptr_c->mm_magic_and_version, 8); memcpy(meta.mm_magic_and_version, head.ptr_c->mm_magic_and_version, 8);
@ -10696,7 +10693,7 @@ int mdbx_txn_commit_ex(MDBX_txn *txn, MDBX_commit_latency *latency) {
rc = sync_locked(env, env->me_flags | txn->mt_flags | MDBX_SHRINK_ALLOWED, rc = sync_locked(env, env->me_flags | txn->mt_flags | MDBX_SHRINK_ALLOWED,
&meta, &txn->tw.troika); &meta, &txn->tw.troika);
ts_4 = latency ? osal_monotime() : 0; ts_5 = latency ? osal_monotime() : 0;
if (unlikely(rc != MDBX_SUCCESS)) { if (unlikely(rc != MDBX_SUCCESS)) {
env->me_flags |= MDBX_FATAL_ERROR; env->me_flags |= MDBX_FATAL_ERROR;
ERROR("txn-%s: error %d", "sync", rc); ERROR("txn-%s: error %d", "sync", rc);
@ -10710,14 +10707,15 @@ done:
provide_latency: provide_latency:
if (latency) { if (latency) {
latency->audit = audit_duration;
latency->preparation = ts_1 ? osal_monotime_to_16dot16(ts_1 - ts_0) : 0; latency->preparation = ts_1 ? osal_monotime_to_16dot16(ts_1 - ts_0) : 0;
latency->gc = (ts_1 && ts_2) ? osal_monotime_to_16dot16(ts_2 - ts_1) : 0; latency->gc = (ts_1 && ts_2) ? osal_monotime_to_16dot16(ts_2 - ts_1) : 0;
latency->write = (ts_2 && ts_3) ? osal_monotime_to_16dot16(ts_3 - ts_2) : 0; latency->audit =
latency->sync = (ts_3 && ts_4) ? osal_monotime_to_16dot16(ts_4 - ts_3) : 0; (ts_2 && AUDIT_ENABLED()) ? osal_monotime_to_16dot16(ts_3 - ts_2) : 0;
const uint64_t ts_5 = osal_monotime(); latency->write = (ts_3 && ts_4) ? osal_monotime_to_16dot16(ts_4 - ts_3) : 0;
latency->ending = ts_4 ? osal_monotime_to_16dot16(ts_5 - ts_4) : 0; latency->sync = (ts_4 && ts_5) ? osal_monotime_to_16dot16(ts_5 - ts_4) : 0;
latency->whole = osal_monotime_to_16dot16(ts_5 - ts_0); const uint64_t ts_6 = osal_monotime();
latency->ending = ts_5 ? osal_monotime_to_16dot16(ts_6 - ts_5) : 0;
latency->whole = osal_monotime_to_16dot16(ts_6 - ts_0);
} }
return rc; return rc;