Skip to content

Commit

Permalink
refactor(iroh-bytes): make module name and feature flags consistent w…
Browse files Browse the repository at this point in the history
…ith docs db (#2110)

## Description

refactor(iroh-bytes): make module name and feature flags consistent with
docs db

file::Store becomes fs::Store, and "file-db" feature becomes "fs-store"
feature.

## Notes & open questions

We could make it either way, I care more about consistency than about my
naming choice. But if we do it let's do it fast so I don't have merge
hell...

## Change checklist

- [ ] Self-review.
- [ ] Documentation updates if relevant.
- [ ] Tests if relevant.
  • Loading branch information
rklaehn authored Mar 22, 2024
1 parent 07c29f0 commit 918fca6
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions iroh-bytes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ rustls = { version = "0.21.0", default-features = false, features = ["quic"] }
tempfile = "3.10.0"

[features]
default = ["file-db"]
file-db = ["reflink-copy", "redb"]
default = ["fs-store"]
fs-store = ["reflink-copy", "redb"]
downloader = ["iroh-net", "parking_lot", "tokio-util/time"]
metrics = ["iroh-metrics"]

Expand Down
6 changes: 3 additions & 3 deletions iroh-bytes/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Implementations of blob stores
use crate::{BlobFormat, Hash, HashAndFormat};

#[cfg(feature = "file-db")]
#[cfg(feature = "fs-store")]
mod bao_file;
pub mod mem;
mod mutable_mem_storage;
pub mod readonly_mem;

#[cfg(feature = "file-db")]
pub mod file;
#[cfg(feature = "fs-store")]
pub mod fs;

mod traits;
pub use traits::*;
Expand Down
4 changes: 2 additions & 2 deletions iroh-bytes/src/store/bao_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl BaoFileStorage {
/// Take the storage out, leaving an empty storage in its place.
///
/// Be careful to put somethign back in its place, or you will lose data.
#[cfg(feature = "file-db")]
#[cfg(feature = "fs-store")]
pub fn take(&mut self) -> Self {
std::mem::take(self)
}
Expand Down Expand Up @@ -525,7 +525,7 @@ impl BaoFileHandle {

/// Transform the storage in place. If the transform fails, the storage will
/// be an immutable empty storage.
#[cfg(feature = "file-db")]
#[cfg(feature = "fs-store")]
pub(crate) fn transform(
&self,
f: impl FnOnce(BaoFileStorage) -> io::Result<BaoFileStorage>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod validate;
use crate::{
store::{
bao_file::{BaoFileStorage, CompleteStorage},
file::{
fs::{
tables::BaoFilePart,
util::{overwrite_and_sync, read_and_remove, ProgressReader},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
};

use crate::{
store::file::{tables::Tables, DataLocation, EntryState, OutboardLocation},
store::fs::{tables::Tables, DataLocation, EntryState, OutboardLocation},
util::{raw_outboard_size, Tag},
IROH_BLOCK_SIZE,
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeSet;

use redb::ReadableTable;

use crate::store::{file::tables::BaoFilePart, ValidateLevel, ValidateProgress};
use crate::store::{fs::tables::BaoFilePart, ValidateLevel, ValidateProgress};

use super::{
raw_outboard_size, tables::Tables, ActorResult, ActorState, DataLocation, EntryState, Hash,
Expand Down
2 changes: 1 addition & 1 deletion iroh-cli/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ pub async fn run(command: Commands, config: &NodeConfig) -> anyhow::Result<()> {
}
Commands::TicketInspect { ticket } => inspect_ticket(&ticket),
Commands::ValidateBlobStore { path, repair } => {
let blob_store = iroh::bytes::store::file::Store::load(path).await?;
let blob_store = iroh::bytes::store::fs::Store::load(path).await?;
let (send, mut recv) = sync::mpsc::channel(1);
let task = tokio::spawn(async move {
while let Some(msg) = recv.recv().await {
Expand Down
2 changes: 1 addition & 1 deletion iroh-cli/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where
pub(crate) async fn start_node(
iroh_data_root: &Path,
relay_map: Option<RelayMap>,
) -> Result<Node<iroh::bytes::store::file::Store>> {
) -> Result<Node<iroh::bytes::store::fs::Store>> {
let rpc_status = RpcStatus::load(iroh_data_root).await?;
match rpc_status {
RpcStatus::Running { port, .. } => {
Expand Down
8 changes: 4 additions & 4 deletions iroh-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn cli_provide_tree() -> Result<()> {
test_provide_get_loop(Input::Path(path), Output::Path)
}

#[cfg(feature = "file-db")]
#[cfg(feature = "fs-store")]
#[test]
#[ignore = "flaky"]
fn cli_provide_tree_resume() -> Result<()> {
Expand Down Expand Up @@ -213,7 +213,7 @@ fn cli_provide_tree_resume() -> Result<()> {
Ok(())
}

#[cfg(feature = "file-db")]
#[cfg(feature = "fs-store")]
#[test]
#[ignore = "flaky"]
fn cli_provide_file_resume() -> Result<()> {
Expand Down Expand Up @@ -439,14 +439,14 @@ async fn cli_provide_persistence() -> anyhow::Result<()> {
provide(&foo_path)?;
// should have some data now
let db_path = IrohPaths::BaoStoreDir.with_root(&iroh_data_dir);
let db = iroh::bytes::store::file::Store::load(&db_path).await?;
let db = iroh::bytes::store::fs::Store::load(&db_path).await?;
let blobs: Vec<std::io::Result<Hash>> = db.blobs().await.unwrap().collect::<Vec<_>>();
drop(db);
assert_eq!(blobs.len(), 3);

provide(&bar_path)?;
// should have more data now
let db = iroh::bytes::store::file::Store::load(&db_path).await?;
let db = iroh::bytes::store::fs::Store::load(&db_path).await?;
let blobs = db.blobs().await.unwrap().collect::<Vec<_>>();
drop(db);
assert_eq!(blobs.len(), 6);
Expand Down
2 changes: 1 addition & 1 deletion iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ indicatif = { version = "0.17", features = ["tokio"], optional = true }
[features]
default = ["metrics"]
metrics = ["iroh-metrics", "iroh-bytes/metrics"]
file-db = ["iroh-bytes/file-db"]
fs-store = ["iroh-bytes/fs-store"]
test = []
examples = ["dep:clap", "dep:indicatif"]

Expand Down
6 changes: 3 additions & 3 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub enum Event {
pub type MemNode = Node<iroh_bytes::store::mem::Store>;

/// Persistent node.
pub type FsNode = Node<iroh_bytes::store::file::Store>;
pub type FsNode = Node<iroh_bytes::store::fs::Store>;

impl MemNode {
/// Returns a new builder for the [`Node`], by default configured to run in memory.
Expand All @@ -142,7 +142,7 @@ impl FsNode {
/// Once done with the builder call [`Builder::spawn`] to create the node.
pub async fn persistent(
root: impl AsRef<Path>,
) -> Result<Builder<iroh_bytes::store::file::Store, iroh_sync::store::fs::Store>> {
) -> Result<Builder<iroh_bytes::store::fs::Store, iroh_sync::store::fs::Store>> {
Builder::default().persist(root).await
}
}
Expand Down Expand Up @@ -278,7 +278,7 @@ impl<D> NodeInner<D> {
}
}

#[cfg(all(test, feature = "file-db"))]
#[cfg(all(test, feature = "fs-store"))]
mod tests {
use std::path::Path;
use std::time::Duration;
Expand Down
10 changes: 5 additions & 5 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,25 @@ where
pub async fn persist(
self,
root: impl AsRef<Path>,
) -> Result<Builder<iroh_bytes::store::file::Store, iroh_sync::store::fs::Store, E>> {
) -> Result<Builder<iroh_bytes::store::fs::Store, iroh_sync::store::fs::Store, E>> {
let root = root.as_ref();
let blob_dir = IrohPaths::BaoStoreDir.with_root(root);

tokio::fs::create_dir_all(&blob_dir).await?;
let blobs_store = iroh_bytes::store::file::Store::load(&blob_dir)
let blobs_store = iroh_bytes::store::fs::Store::load(&blob_dir)
.await
.with_context(|| format!("Failed to load iroh database from {}", blob_dir.display()))?;
let docs_store = iroh_sync::store::fs::Store::new(IrohPaths::DocsDatabase.with_root(root))?;

let v0 = blobs_store
.import_flat_store(iroh_bytes::store::file::FlatStorePaths {
.import_flat_store(iroh_bytes::store::fs::FlatStorePaths {
complete: root.join("blobs.v0"),
partial: root.join("blobs-partial.v0"),
meta: root.join("blobs-meta.v0"),
})
.await?;
let v1 = blobs_store
.import_flat_store(iroh_bytes::store::file::FlatStorePaths {
.import_flat_store(iroh_bytes::store::fs::FlatStorePaths {
complete: root.join("blobs.v1").join("complete"),
partial: root.join("blobs.v1").join("partial"),
meta: root.join("blobs.v1").join("meta"),
Expand All @@ -163,7 +163,7 @@ where
if v0 || v1 {
tracing::info!("flat data was imported - reapply inline options");
blobs_store
.update_inline_options(iroh_bytes::store::file::InlineOptions::default(), true)
.update_inline_options(iroh_bytes::store::fs::InlineOptions::default(), true)
.await?;
}

Expand Down
2 changes: 1 addition & 1 deletion iroh/src/util/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum IrohPaths {
/// Path to the node's secret key for the [`iroh_net::key::PublicKey`].
#[strum(serialize = "keypair")]
SecretKey,
/// Path to the node's [file based blob store](iroh_bytes::store::file::Store).
/// Path to the node's [file based blob store](iroh_bytes::store::fs::Store).
#[strum(serialize = "blobs")]
BaoStoreDir,
/// Path to the [iroh-sync document database](iroh_sync::store::fs::Store)
Expand Down
10 changes: 5 additions & 5 deletions iroh/tests/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async fn gc_hashseq_impl() -> Result<()> {
Ok(())
}

#[cfg(feature = "file-db")]
#[cfg(feature = "fs-store")]
mod file {
use super::*;
use std::{io, path::PathBuf, time::Duration};
Expand Down Expand Up @@ -242,7 +242,7 @@ mod file {
async fn redb_doc_import_stress() -> Result<()> {
let _ = tracing_subscriber::fmt::try_init();
let dir = testdir!();
let bao_store = iroh_bytes::store::file::Store::load(dir.join("store")).await?;
let bao_store = iroh_bytes::store::fs::Store::load(dir.join("store")).await?;
let node = wrap_in_node(bao_store.clone(), Duration::from_secs(10)).await;
let client = node.client();
let doc = client.docs.create().await?;
Expand Down Expand Up @@ -285,7 +285,7 @@ mod file {
let path = data_path(dir.clone());
let outboard_path = outboard_path(dir.clone());

let bao_store = iroh_bytes::store::file::Store::load(dir.clone()).await?;
let bao_store = iroh_bytes::store::fs::Store::load(dir.clone()).await?;
let node = wrap_in_node(bao_store.clone(), Duration::from_millis(100)).await;
let evs = attach_db_events(&node).await;
let data1 = create_test_data(10000000);
Expand Down Expand Up @@ -448,7 +448,7 @@ mod file {
let path = data_path(dir.clone());
let outboard_path = outboard_path(dir.clone());

let bao_store = iroh_bytes::store::file::Store::load(dir.clone()).await?;
let bao_store = iroh_bytes::store::fs::Store::load(dir.clone()).await?;
let node = wrap_in_node(bao_store.clone(), Duration::from_millis(10)).await;
let evs = attach_db_events(&node).await;

Expand Down Expand Up @@ -482,7 +482,7 @@ mod file {
let _ = tracing_subscriber::fmt::try_init();
let dir = testdir!();

let bao_store = iroh_bytes::store::file::Store::load(dir.clone()).await?;
let bao_store = iroh_bytes::store::fs::Store::load(dir.clone()).await?;
let node = wrap_in_node(bao_store.clone(), Duration::from_secs(1)).await;
let evs = attach_db_events(&node).await;

Expand Down

0 comments on commit 918fca6

Please sign in to comment.