Skip to content

Commit 55414b9

Browse files
authored
chore: Feature gate redb based store. (#143)
## Description Feature gate redb based store. It is still enabled by default. Many tests and examples require this to be enabled, but I think that is fine, since we run both with all and with no default features. ## Breaking Changes None ## Notes & open questions None ## Change checklist - [ ] Self-review. - [ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent b1880e1 commit 55414b9

File tree

21 files changed

+252
-232
lines changed

21 files changed

+252
-232
lines changed

Cargo.lock

Lines changed: 13 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ quinn = { package = "iroh-quinn", version = "0.14.0" }
2121
n0-future = "0.2.0"
2222
n0-snafu = "0.2.0"
2323
range-collections = { version = "0.4.6", features = ["serde"] }
24-
redb = { version = "=2.4" }
2524
smallvec = { version = "1", features = ["serde", "const_new"] }
2625
snafu = "0.8.5"
2726
tokio = { version = "1.43.0", features = ["full"] }
@@ -41,9 +40,10 @@ iroh = "0.91.1"
4140
self_cell = "1.1.0"
4241
genawaiter = { version = "0.99.1", features = ["futures03"] }
4342
iroh-base = "0.91.1"
44-
reflink-copy = "0.1.24"
4543
irpc = { version = "0.7.0", features = ["rpc", "quinn_endpoint_setup", "spans", "stream", "derive"], default-features = false }
4644
iroh-metrics = { version = "0.35" }
45+
redb = { version = "=2.4", optional = true }
46+
reflink-copy = { version = "0.1.24", optional = true }
4747

4848
[dev-dependencies]
4949
clap = { version = "4.5.31", features = ["derive"] }
@@ -64,7 +64,8 @@ iroh = { version = "0.91.1", features = ["discovery-local-network"]}
6464
[features]
6565
hide-proto-docs = []
6666
metrics = []
67-
default = ["hide-proto-docs"]
67+
default = ["hide-proto-docs", "fs-store"]
68+
fs-store = ["dep:redb", "dep:reflink-copy"]
6869

6970
[patch.crates-io]
7071
iroh = { git = "https://github.com/n0-computer/iroh", branch = "main" }

src/api/blobs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ impl Blobs {
144144
/// clears the protections before.
145145
///
146146
/// Users should rely only on garbage collection for blob deletion.
147+
#[cfg(feature = "fs-store")]
147148
pub(crate) async fn delete_with_opts(&self, options: DeleteOptions) -> RequestResult<()> {
148149
trace!("{options:?}");
149150
self.client.rpc(options).await??;
150151
Ok(())
151152
}
152153

153154
/// See [`Self::delete_with_opts`].
155+
#[cfg(feature = "fs-store")]
154156
pub(crate) async fn delete(
155157
&self,
156158
hashes: impl IntoIterator<Item = impl Into<Hash>>,
@@ -510,6 +512,7 @@ impl Blobs {
510512
}
511513
}
512514

515+
#[allow(dead_code)]
513516
pub(crate) async fn clear_protected(&self) -> RequestResult<()> {
514517
let msg = ClearProtectedRequest;
515518
self.client.rpc(msg).await??;

src/api/blobs/reader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl tokio::io::AsyncSeek for BlobReader {
214214
}
215215

216216
#[cfg(test)]
217+
#[cfg(feature = "fs-store")]
217218
mod tests {
218219
use bao_tree::ChunkRanges;
219220
use testresult::TestResult;

src/api/downloader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ impl ContentDiscovery for Shuffled {
524524
}
525525

526526
#[cfg(test)]
527+
#[cfg(feature = "fs-store")]
527528
mod tests {
528529
use std::ops::Deref;
529530

src/api/proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub use bitfield::Bitfield;
4040

4141
use crate::{store::util::Tag, util::temp_tag::TempTag, BlobFormat, Hash, HashAndFormat};
4242

43+
#[allow(dead_code)]
4344
pub(crate) trait HashSpecific {
4445
fn hash(&self) -> Hash;
4546

src/api/proto/bitfield.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl<'de> Deserialize<'de> for Bitfield {
7070
}
7171

7272
impl Bitfield {
73+
#[cfg(feature = "fs-store")]
7374
pub(crate) fn new_unchecked(ranges: ChunkRanges, size: u64) -> Self {
7475
Self { ranges, size }
7576
}

src/api/remote.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ where
10611061
}
10621062

10631063
#[cfg(test)]
1064+
#[cfg(feature = "fs-store")]
10641065
mod tests {
10651066
use bao_tree::{ChunkNum, ChunkRanges};
10661067
use testresult::TestResult;

src/hash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl From<Hash> for HashAndFormat {
283283
}
284284
}
285285

286-
// #[cfg(feature = "redb")]
286+
#[cfg(feature = "fs-store")]
287287
mod redb_support {
288288
use postcard::experimental::max_size::MaxSize;
289289
use redb::{Key as RedbKey, Value as RedbValue};
@@ -493,7 +493,7 @@ mod tests {
493493
assert_eq_hex!(serialized, expected);
494494
}
495495

496-
// #[cfg(feature = "redb")]
496+
#[cfg(feature = "fs-store")]
497497
#[test]
498498
fn hash_redb() {
499499
use redb::Value as RedbValue;
@@ -518,7 +518,7 @@ mod tests {
518518
assert_eq_hex!(serialized, expected);
519519
}
520520

521-
// #[cfg(feature = "redb")]
521+
#[cfg(feature = "fs-store")]
522522
#[test]
523523
fn hash_and_format_redb() {
524524
use redb::Value as RedbValue;

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
//! The [downloader](api::downloader) module provides a component to download blobs from
2525
//! multiple sources and store them in a store.
2626
//!
27+
//! # Features:
28+
//!
29+
//! - `fs-store`: Enables the filesystem based store implementation. This comes with a few additional dependencies such as `redb` and `reflink-copy`.
30+
//! - `metrics`: Enables prometheus metrics for stores and the protocol.
31+
//!
2732
//! [BLAKE3]: https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf
2833
//! [iroh]: https://docs.rs/iroh
2934
mod hash;
@@ -46,6 +51,7 @@ pub mod test;
4651
pub mod util;
4752

4853
#[cfg(test)]
54+
#[cfg(feature = "fs-store")]
4955
mod tests;
5056

5157
pub use protocol::ALPN;

0 commit comments

Comments
 (0)