core: Wrap Connection::metrics with RwLock

This commit is contained in:
Pekka Enberg
2025-09-24 09:14:25 +03:00
parent fa1e986dca
commit fb39661809
2 changed files with 6 additions and 6 deletions

View File

@@ -330,14 +330,14 @@ impl Limbo {
// Display all metrics
let output = {
let metrics = self.conn.metrics.borrow();
let metrics = self.conn.metrics.read();
format!("{metrics}")
};
self.writeln(output)?;
if args.reset {
self.conn.metrics.borrow_mut().reset();
self.conn.metrics.write().reset();
self.writeln("Statistics reset.")?;
}
@@ -482,7 +482,7 @@ impl Limbo {
// Display stats if enabled
if self.opts.stats {
let stats_output = {
let metrics = self.conn.metrics.borrow();
let metrics = self.conn.metrics.read();
metrics
.last_statement
.as_ref()

View File

@@ -516,7 +516,7 @@ impl Database {
query_only: AtomicBool::new(false),
mv_tx: RwLock::new(None),
view_transaction_states: AllViewsTxState::new(),
metrics: RefCell::new(ConnectionMetrics::new()),
metrics: RwLock::new(ConnectionMetrics::new()),
is_nested_stmt: AtomicBool::new(false),
encryption_key: RefCell::new(None),
encryption_cipher_mode: Cell::new(None),
@@ -1010,7 +1010,7 @@ pub struct Connection {
/// one entry per view that was touched in the transaction.
view_transaction_states: AllViewsTxState,
/// Connection-level metrics aggregation
pub metrics: RefCell<ConnectionMetrics>,
pub metrics: RwLock<ConnectionMetrics>,
/// Whether the connection is executing a statement initiated by another statement.
/// Generally this is only true for ParseSchema.
is_nested_stmt: AtomicBool,
@@ -2395,7 +2395,7 @@ impl Statement {
// Aggregate metrics when statement completes
if matches!(res, Ok(StepResult::Done)) {
let mut conn_metrics = self.program.connection.metrics.borrow_mut();
let mut conn_metrics = self.program.connection.metrics.write();
conn_metrics.record_statement(self.state.metrics.clone());
self.busy = false;
} else {