Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Jun 4, 2024
1 parent 04137da commit d9fe06e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
45 changes: 22 additions & 23 deletions iroh-docs/src/store/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) mod tables;

use self::{
bounds::{ByKeyBounds, RecordsBounds},
ranges::{RangeExt, RecordsRange},
ranges::RangeExt,
tables::{RecordsTable, TransactionAndTables},
};
use self::{
Expand All @@ -48,6 +48,8 @@ use self::{
},
};

pub use self::ranges::RecordsRange;

/// Manages the replicas and authors for an instance.
#[derive(Debug)]
pub struct Store {
Expand Down Expand Up @@ -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<ReadOnlyTables> {
// 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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -414,11 +422,7 @@ impl Store {
namespace: NamespaceId,
query: impl Into<Query>,
) -> Result<QueryIterator> {
// 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())
}

Expand All @@ -441,13 +445,8 @@ impl Store {

/// Get all content hashes of all replicas in the store.
pub fn content_hashes(&mut self) -> Result<ContentHashesIterator> {
// 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.
Expand Down
2 changes: 0 additions & 2 deletions iroh/src/node/rpc/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ impl DocsEngine {
}

pub async fn doc_open(&self, req: DocOpenRequest) -> RpcResult<DocOpenResponse> {
tracing::debug!("doc_open IN");
self.sync.open(req.doc_id, Default::default()).await?;
tracing::debug!("doc_open OUT");
Ok(DocOpenResponse {})
}

Expand Down

0 comments on commit d9fe06e

Please sign in to comment.