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,17 +176,16 @@ impl<K: TransactionKind> MetricsHandler<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Logs the backtrace of current call if the duration that the transaction has been open is
|
||||
/// more than [LONG_TRANSACTION_DURATION].
|
||||
/// Logs the backtrace of current call if the duration that the read transaction has been open
|
||||
/// is more than [LONG_TRANSACTION_DURATION].
|
||||
/// 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
|
||||
/// not needed.
|
||||
fn log_backtrace_on_long_transaction(&self) {
|
||||
if self.backtrace_recorded.load(Ordering::Relaxed) {
|
||||
return
|
||||
}
|
||||
|
||||
if !self.backtrace_recorded.load(Ordering::Relaxed) &&
|
||||
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);
|
||||
@ -196,11 +195,12 @@ impl<K: TransactionKind> MetricsHandler<K> {
|
||||
target: "storage::db::mdbx",
|
||||
?open_duration,
|
||||
?backtrace,
|
||||
"The database transaction has been open for too long"
|
||||
"The database read transaction has been open for too long"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: TransactionKind> Drop for MetricsHandler<K> {
|
||||
fn drop(&mut self) {
|
||||
|
||||
@ -18,6 +18,11 @@ impl TransactionMode {
|
||||
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)]
|
||||
|
||||
Reference in New Issue
Block a user