From d9fe06e3ab71c4dd7afd94b479fe73c41fa7421a Mon Sep 17 00:00:00 2001 From: "Franz Heinzmann (Frando)" Date: Wed, 5 Jun 2024 00:15:53 +0200 Subject: [PATCH] cleanup --- iroh-docs/src/store/fs.rs | 45 +++++++++++++++++++-------------------- iroh/src/node/rpc/docs.rs | 2 -- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/iroh-docs/src/store/fs.rs b/iroh-docs/src/store/fs.rs index 6e2cc2ddcc4..a7c8835e31a 100644 --- a/iroh-docs/src/store/fs.rs +++ b/iroh-docs/src/store/fs.rs @@ -38,7 +38,7 @@ pub(crate) mod tables; use self::{ bounds::{ByKeyBounds, RecordsBounds}, - ranges::{RangeExt, RecordsRange}, + ranges::RangeExt, tables::{RecordsTable, TransactionAndTables}, }; use self::{ @@ -48,6 +48,8 @@ use self::{ }, }; +pub use self::ranges::RecordsRange; + /// Manages the replicas and authors for an instance. #[derive(Debug)] pub struct Store { @@ -152,6 +154,22 @@ impl Store { } } + /// Get an owned read-only snapshot of the database. + /// + /// This will open a new read transaction. The read transaction won't be reused for other + /// reads. + /// + /// This has the side effect of committing any open write transaction, + /// so it can be used as a way to ensure that the data is persisted. + pub fn snapshot_owned(&mut self) -> Result { + // make sure the current transaction is committed + self.flush()?; + assert!(matches!(self.transaction, CurrentTransaction::None)); + let tx = self.db.begin_read()?; + let tables = ReadOnlyTables::new(tx)?; + Ok(tables) + } + /// Get access to the tables to read from them. /// /// The underlying transaction is a write transaction, but with a non-mut @@ -303,16 +321,6 @@ impl Store { Ok((capability.id(), capability.kind())) }); Ok(iter) - // let tables = self.tables()?; - // let namespaces: Vec<_> = tables - // .namespaces - // .iter()? - // .map(|res| { - // let capability = parse_capability(res?.1.value())?; - // Ok((capability.id(), capability.kind())) - // }) - // .collect(); - // Ok(namespaces.into_iter()) } /// Get an author key from the store. @@ -414,11 +422,7 @@ impl Store { namespace: NamespaceId, query: impl Into, ) -> Result { - // make sure the current transaction is committed - self.flush()?; - assert!(matches!(self.transaction, CurrentTransaction::None)); - let tx = self.db.begin_read()?; - let tables = ReadOnlyTables::new(tx)?; + let tables = self.snapshot_owned()?; QueryIterator::new(tables, namespace, query.into()) } @@ -441,13 +445,8 @@ impl Store { /// Get all content hashes of all replicas in the store. pub fn content_hashes(&mut self) -> Result { - // make sure the current transaction is committed - self.flush()?; - assert!(matches!(self.transaction, CurrentTransaction::None)); - let tx = self.db.begin_read()?; - let tables = ReadOnlyTables::new(tx)?; - let records = tables.records; - ContentHashesIterator::all(&records) + let tables = self.snapshot_owned()?; + ContentHashesIterator::all(&tables.records) } /// Get the latest entry for each author in a namespace. diff --git a/iroh/src/node/rpc/docs.rs b/iroh/src/node/rpc/docs.rs index 2b64bf0b3cb..a0433a803eb 100644 --- a/iroh/src/node/rpc/docs.rs +++ b/iroh/src/node/rpc/docs.rs @@ -126,9 +126,7 @@ impl DocsEngine { } pub async fn doc_open(&self, req: DocOpenRequest) -> RpcResult { - tracing::debug!("doc_open IN"); self.sync.open(req.doc_id, Default::default()).await?; - tracing::debug!("doc_open OUT"); Ok(DocOpenResponse {}) }