From e1286892e59a6ca2fc44a58473ca45292e623a10 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 11 Mar 2026 17:26:32 +0100 Subject: debug info page for db kv and cache kv --- database/src/kv/mod.rs | 27 ++++++++++++++++----------- database/src/lib.rs | 4 +++- 2 files changed, 19 insertions(+), 12 deletions(-) (limited to 'database') diff --git a/database/src/kv/mod.rs b/database/src/kv/mod.rs index 784cbef..f391d31 100644 --- a/database/src/kv/mod.rs +++ b/database/src/kv/mod.rs @@ -41,6 +41,22 @@ impl Database for T { fn transaction(&self, f: &mut dyn FnMut(&mut dyn Transaction) -> Result<()>) -> Result<()> { jellykv::Store::transaction(self, &mut |mut txn| f(&mut txn)) } + fn debug_info(&self) -> Result { + let mut o = String::new(); + self.transaction(&mut |txn| { + o = String::new(); + let rc = read_counter(txn, &T_ROW_COUNTER.to_be_bytes(), 0)?; + writeln!(o, "row ounter: {rc}")?; + writeln!(o, "indices:")?; + for (is, ik) in list_indices(txn)? { + writeln!(o, "\tIS={is} IK={ik}")?; + } + Ok(()) + })?; + writeln!(o)?; + write!(o, "{}", jellykv::Store::debug_info(self)?)?; + Ok(o) + } } impl Transaction for &mut dyn jellykv::Transaction { @@ -125,17 +141,6 @@ impl Transaction for &mut dyn jellykv::Transaction { } Ok(total) } - - fn debug_info(&self) -> Result { - let mut o = String::new(); - let rc = read_counter(*self, &T_ROW_COUNTER.to_be_bytes(), 0)?; - writeln!(o, "Row Counter: {rc}")?; - writeln!(o, "Indices:")?; - for (is, ik) in list_indices(*self)? { - writeln!(o, "\tIS={is} IK={ik}")?; - } - Ok(o) - } } fn get_or_create_index(txn: &mut dyn jellykv::Transaction, ik: &IndexKey) -> Result { diff --git a/database/src/lib.rs b/database/src/lib.rs index 465cb87..9bd4c06 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -17,6 +17,9 @@ pub type RowIter = Box)>>>; pub trait Database: Send + Sync { fn transaction(&self, f: &mut dyn FnMut(&mut dyn Transaction) -> Result<()>) -> Result<()>; + fn debug_info(&self) -> Result { + Ok(String::new()) + } } #[allow(clippy::type_complexity)] @@ -31,7 +34,6 @@ pub trait Transaction { ) -> Result)>> + 'a>>; fn query_single(&mut self, query: Query) -> Result>; fn count(&mut self, query: Query) -> Result; - fn debug_info(&self) -> Result; } #[derive(Debug, Default, Clone, PartialEq)] -- cgit v1.3