From fb3966180972b107ebe9beaed5e47d9afa4251bd Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 24 Sep 2025 09:14:25 +0300 Subject: [PATCH] core: Wrap Connection::metrics with RwLock --- cli/app.rs | 6 +++--- core/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/app.rs b/cli/app.rs index cdca3e192..18c036c6b 100644 --- a/cli/app.rs +++ b/cli/app.rs @@ -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() diff --git a/core/lib.rs b/core/lib.rs index 3532166da..b4197f6d7 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -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, + pub metrics: RwLock, /// 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 {