mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(storage): report backtrace only on read transactions (#5625)
This commit is contained in:
@ -176,28 +176,28 @@ impl<K: TransactionKind> MetricsHandler<K> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logs the backtrace of current call if the duration that the transaction has been open is
|
/// Logs the backtrace of current call if the duration that the read transaction has been open
|
||||||
/// more than [LONG_TRANSACTION_DURATION].
|
/// is more than [LONG_TRANSACTION_DURATION].
|
||||||
/// The backtrace is recorded and logged just once, guaranteed by `backtrace_recorded` atomic.
|
/// The backtrace is recorded and logged just once, guaranteed by `backtrace_recorded` atomic.
|
||||||
///
|
///
|
||||||
/// NOTE: Backtrace is recorded using [Backtrace::force_capture], so `RUST_BACKTRACE` env var is
|
/// NOTE: Backtrace is recorded using [Backtrace::force_capture], so `RUST_BACKTRACE` env var is
|
||||||
/// not needed.
|
/// not needed.
|
||||||
fn log_backtrace_on_long_transaction(&self) {
|
fn log_backtrace_on_long_transaction(&self) {
|
||||||
if self.backtrace_recorded.load(Ordering::Relaxed) {
|
if !self.backtrace_recorded.load(Ordering::Relaxed) &&
|
||||||
return
|
self.transaction_mode().is_read_only()
|
||||||
}
|
{
|
||||||
|
let open_duration = self.start.elapsed();
|
||||||
|
if open_duration > LONG_TRANSACTION_DURATION {
|
||||||
|
self.backtrace_recorded.store(true, Ordering::Relaxed);
|
||||||
|
|
||||||
let open_duration = self.start.elapsed();
|
let backtrace = Backtrace::force_capture();
|
||||||
if open_duration > LONG_TRANSACTION_DURATION {
|
debug!(
|
||||||
self.backtrace_recorded.store(true, Ordering::Relaxed);
|
target: "storage::db::mdbx",
|
||||||
|
?open_duration,
|
||||||
let backtrace = Backtrace::force_capture();
|
?backtrace,
|
||||||
debug!(
|
"The database read transaction has been open for too long"
|
||||||
target: "storage::db::mdbx",
|
);
|
||||||
?open_duration,
|
}
|
||||||
?backtrace,
|
|
||||||
"The database transaction has been open for too long"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,11 @@ impl TransactionMode {
|
|||||||
TransactionMode::ReadWrite => "read-write",
|
TransactionMode::ReadWrite => "read-write",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the transaction mode is read-only.
|
||||||
|
pub(crate) const fn is_read_only(&self) -> bool {
|
||||||
|
matches!(self, TransactionMode::ReadOnly)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||||
|
|||||||
Reference in New Issue
Block a user