diff --git a/libsql-server/src/connection/libsql.rs b/libsql-server/src/connection/libsql.rs index 0b0f086962..8521af87ad 100644 --- a/libsql-server/src/connection/libsql.rs +++ b/libsql-server/src/connection/libsql.rs @@ -661,9 +661,9 @@ impl<W: WalHook> Connection<W> { fn update_stats(&self, sql: String, stmt: &rusqlite::Statement, elapsed: Duration) { histogram!("statement_execution_time", elapsed); let elapsed = elapsed.as_millis() as u64; - let rows_read = stmt.get_status(StatementStatus::RowsRead); - let rows_written = stmt.get_status(StatementStatus::RowsWritten); - let mem_used = stmt.get_status(StatementStatus::MemUsed); + let rows_read = stmt.get_status(StatementStatus::RowsRead) as u64; + let rows_written = stmt.get_status(StatementStatus::RowsWritten) as u64; + let mem_used = stmt.get_status(StatementStatus::MemUsed) as u64; histogram!("statement_mem_used_bytes", mem_used as f64); let rows_read = if rows_read == 0 && rows_written == 0 { 1 @@ -672,7 +672,7 @@ impl<W: WalHook> Connection<W> { }; self.stats.inc_rows_read(rows_read as u64); self.stats.inc_rows_written(rows_written as u64); - let weight = (rows_read + rows_written) as i64; + let weight = (rows_read + rows_written) as u64; if self.stats.qualifies_as_top_query(weight) { self.stats.add_top_query(crate::stats::TopQuery::new( sql.clone(), diff --git a/libsql-server/src/stats.rs b/libsql-server/src/stats.rs index 9133a7a260..2d79719604 100644 --- a/libsql-server/src/stats.rs +++ b/libsql-server/src/stats.rs @@ -1,5 +1,5 @@ use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicI64, AtomicU64, Ordering}; +use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, RwLock, Weak}; use metrics::{counter, gauge, increment_counter}; @@ -15,16 +15,16 @@ use crate::replication::FrameNo; #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub struct TopQuery { #[serde(skip)] - pub weight: i64, - pub rows_written: i32, - pub rows_read: i32, + pub weight: u64, + pub rows_written: u64, + pub rows_read: u64, pub query: String, } impl TopQuery { - pub fn new(query: String, rows_read: i32, rows_written: i32) -> Self { + pub fn new(query: String, rows_read: u64, rows_written: u64) -> Self { Self { - weight: rows_read as i64 + rows_written as i64, + weight: rows_read + rows_written, rows_read, rows_written, query, @@ -36,12 +36,12 @@ impl TopQuery { pub struct SlowestQuery { pub elapsed_ms: u64, pub query: String, - pub rows_written: i32, - pub rows_read: i32, + pub rows_written: u64, + pub rows_read: u64, } impl SlowestQuery { - pub fn new(query: String, elapsed_ms: u64, rows_read: i32, rows_written: i32) -> Self { + pub fn new(query: String, elapsed_ms: u64, rows_read: u64, rows_written: u64) -> Self { Self { elapsed_ms, query, @@ -69,7 +69,7 @@ pub struct Stats { current_frame_no: AtomicU64, // Lowest value in currently stored top queries #[serde(default)] - top_query_threshold: AtomicI64, + top_query_threshold: AtomicU64, #[serde(default)] top_queries: Arc<RwLock<BTreeSet<TopQuery>>>, // Lowest value in currently stored slowest queries @@ -172,7 +172,7 @@ impl Stats { } } - pub(crate) fn qualifies_as_top_query(&self, weight: i64) -> bool { + pub(crate) fn qualifies_as_top_query(&self, weight: u64) -> bool { weight >= self.top_query_threshold.load(Ordering::Relaxed) }