Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(db): capture tx opening backtrace in debug mode #11477

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion crates/storage/db/src/implementation/mdbx/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ struct MetricsHandler<K: TransactionKind> {
/// If `true`, the backtrace of transaction has already been recorded and logged.
/// See [`MetricsHandler::log_backtrace_on_long_read_transaction`].
backtrace_recorded: AtomicBool,
/// Shared database environment metrics.
env_metrics: Arc<DatabaseEnvMetrics>,
/// Backtrace of the location where the transaction has been opened. Reported only with debug
/// assertions, because capturing the backtrace on every transaction opening is expensive.
#[cfg(debug_assertions)]
open_backtrace: Backtrace,
_marker: PhantomData<K>,
}

Expand All @@ -193,6 +198,8 @@ impl<K: TransactionKind> MetricsHandler<K> {
close_recorded: false,
record_backtrace: true,
backtrace_recorded: AtomicBool::new(false),
#[cfg(debug_assertions)]
open_backtrace: Backtrace::force_capture(),
env_metrics,
_marker: PhantomData,
}
Expand Down Expand Up @@ -232,11 +239,23 @@ impl<K: TransactionKind> MetricsHandler<K> {
let open_duration = self.start.elapsed();
if open_duration >= self.long_transaction_duration {
self.backtrace_recorded.store(true, Ordering::Relaxed);
let message = if cfg!(debug_assertions) {
shekhirin marked this conversation as resolved.
Show resolved Hide resolved
format!(
"The database read transaction has been open for too long. Open backtrace:\n{}\n\nCurrent backtrace:\n{}",
self.open_backtrace,
Backtrace::force_capture()
)
} else {
format!(
"The database read transaction has been open for too long. Backtrace:\n{}",
Backtrace::force_capture()
)
};
warn!(
target: "storage::db::mdbx",
?open_duration,
%self.txn_id,
"The database read transaction has been open for too long. Backtrace:\n{}", Backtrace::force_capture()
"{message}"
);
}
}
Expand Down
Loading