diff --git a/iroh-bytes/src/get/db.rs b/iroh-bytes/src/get/db.rs index a7710a91f9..9915ffd7ff 100644 --- a/iroh-bytes/src/get/db.rs +++ b/iroh-bytes/src/get/db.rs @@ -22,7 +22,7 @@ use crate::{ Stats, }, protocol::{GetRequest, RangeSpecSeq}, - store::{MapEntry, PartialMap, PartialMapEntry, Store as BaoStore}, + store::{MapEntry, MapEntryMut, MapMut, Store as BaoStore}, util::progress::{IdGenerator, ProgressSender}, BlobFormat, HashAndFormat, }; @@ -143,7 +143,7 @@ async fn get_blob< } /// Given a partial entry, get the valid ranges. -pub async fn valid_ranges(entry: &D::PartialEntry) -> anyhow::Result { +pub async fn valid_ranges(entry: &D::EntryMut) -> anyhow::Result { use tracing::trace as log; // compute the valid range from just looking at the data file let mut data_reader = entry.data_reader().await?; @@ -217,7 +217,7 @@ async fn get_blob_inner( async fn get_blob_inner_partial( db: &D, at_header: AtBlobHeader, - entry: D::PartialEntry, + entry: D::EntryMut, sender: impl ProgressSender + IdGenerator, ) -> Result { // read the size. The size we get here is not verified, but since we use @@ -469,7 +469,7 @@ pub enum BlobInfo { /// we have the blob partially Partial { /// The partial entry. - entry: D::PartialEntry, + entry: D::EntryMut, /// The ranges that are available locally. valid_ranges: ChunkRanges, }, diff --git a/iroh-bytes/src/store/flat.rs b/iroh-bytes/src/store/flat.rs index 00d068f3d4..9a4bec4505 100644 --- a/iroh-bytes/src/store/flat.rs +++ b/iroh-bytes/src/store/flat.rs @@ -132,7 +132,7 @@ use std::time::SystemTime; use super::{ BaoBatchWriter, CombinedBatchWriter, EntryStatus, ExportMode, ImportMode, ImportProgress, Map, - MapEntry, PartialMap, PartialMapEntry, PossiblyPartialEntry, ReadableStore, ValidateProgress, + MapEntry, MapEntryMut, MapMut, PossiblyPartialEntry, ReadableStore, ValidateProgress, }; use crate::util::progress::{IdGenerator, IgnoreProgressSender, ProgressSender}; use crate::util::{LivenessTracker, Tag}; @@ -240,7 +240,7 @@ impl PartialEntryData { } } -impl MapEntry for PartialEntry { +impl MapEntry for EntryMut { fn hash(&self) -> Hash { self.hash } @@ -272,7 +272,7 @@ impl MapEntry for PartialEntry { } } -impl PartialEntry { +impl EntryMut { async fn outboard_mut(&self) -> io::Result> { let hash = self.hash; let size = self.size; @@ -305,7 +305,7 @@ impl PartialEntry { } } -impl PartialMapEntry for PartialEntry { +impl MapEntryMut for EntryMut { async fn batch_writer(&self) -> io::Result { let data = self.data_writer().await?; let outboard = self.outboard_mut().await?; @@ -313,8 +313,8 @@ impl PartialMapEntry for PartialEntry { } } -impl PartialMap for Store { - type PartialEntry = PartialEntry; +impl MapMut for Store { + type EntryMut = EntryMut; fn entry_status(&self, hash: &Hash) -> io::Result { let state = self.0.state.read().unwrap(); @@ -330,7 +330,7 @@ impl PartialMap for Store { fn get_possibly_partial(&self, hash: &Hash) -> io::Result> { let state = self.0.state.read().unwrap(); Ok(if let Some(entry) = state.partial.get(hash) { - PossiblyPartialEntry::Partial(PartialEntry { + PossiblyPartialEntry::Partial(EntryMut { hash: *hash, size: entry.size, data_path: self.0.options.partial_data_path(*hash, &entry.uuid), @@ -346,7 +346,7 @@ impl PartialMap for Store { }) } - fn get_or_create_partial(&self, hash: Hash, size: u64) -> io::Result { + fn get_or_create_partial(&self, hash: Hash, size: u64) -> io::Result { let mut state = self.0.state.write().unwrap(); // this protects the entry from being deleted until the next mark phase // @@ -367,7 +367,7 @@ impl PartialMap for Store { .or_insert_with(|| PartialEntryData::new(size, new_uuid())); let data_path = self.0.options.partial_data_path(hash, &entry.uuid); let outboard_path = self.0.options.partial_outboard_path(hash, &entry.uuid); - Ok(PartialEntry { + Ok(EntryMut { hash, size: entry.size, data_path, @@ -375,7 +375,7 @@ impl PartialMap for Store { }) } - async fn insert_complete(&self, entry: Self::PartialEntry) -> io::Result<()> { + async fn insert_complete(&self, entry: Self::EntryMut) -> io::Result<()> { let this = self.clone(); tokio::task::spawn_blocking(move || this.insert_complete_sync(entry)) .map(flatten_to_io) @@ -560,9 +560,9 @@ fn needs_outboard(size: u64) -> bool { size > (IROH_BLOCK_SIZE.bytes() as u64) } -/// The [PartialMapEntry] implementation for [Store]. +/// The [MapEntryMut] implementation for [Store]. #[derive(Debug, Clone)] -pub struct PartialEntry { +pub struct EntryMut { hash: Hash, size: u64, data_path: PathBuf, @@ -1065,7 +1065,7 @@ impl Store { Ok(()) } - fn insert_complete_sync(&self, entry: PartialEntry) -> io::Result<()> { + fn insert_complete_sync(&self, entry: EntryMut) -> io::Result<()> { let hash = entry.hash; let data_path = self.0.options.owned_data_path(&hash); let size = entry.size; diff --git a/iroh-bytes/src/store/mem.rs b/iroh-bytes/src/store/mem.rs index 288f66a86f..d63d361e98 100644 --- a/iroh-bytes/src/store/mem.rs +++ b/iroh-bytes/src/store/mem.rs @@ -21,8 +21,8 @@ use super::PossiblyPartialEntry; use super::TempCounterMap; use crate::{ store::{ - EntryStatus, ExportMode, ImportMode, ImportProgress, Map, MapEntry, PartialMap, - PartialMapEntry, ReadableStore, ValidateProgress, + EntryStatus, ExportMode, ImportMode, ImportProgress, Map, MapEntry, MapEntryMut, + MapMut, ReadableStore, ValidateProgress, }, util::{ progress::{IdGenerator, IgnoreProgressSender, ProgressSender}, @@ -231,13 +231,13 @@ impl MapEntry for Entry { /// The [MapEntry] implementation for [Store]. #[derive(Debug, Clone)] -pub struct PartialEntry { +pub struct EntryMut { hash: Hash, outboard: PreOrderOutboard, data: MutableMemFile, } -impl MapEntry for PartialEntry { +impl MapEntry for EntryMut { fn hash(&self) -> Hash { self.hash } @@ -359,8 +359,8 @@ impl ReadableStore for Store { } } -impl PartialMap for Store { - type PartialEntry = PartialEntry; +impl MapMut for Store { + type EntryMut = EntryMut; fn entry_status(&self, hash: &Hash) -> io::Result { let state = self.0.state.read().unwrap(); @@ -376,7 +376,7 @@ impl PartialMap for Store { fn get_possibly_partial(&self, hash: &Hash) -> io::Result> { let state = self.0.state.read().unwrap(); Ok(match state.partial.get(hash) { - Some((data, outboard)) => PossiblyPartialEntry::Partial(PartialEntry { + Some((data, outboard)) => PossiblyPartialEntry::Partial(EntryMut { hash: *hash, outboard: outboard.clone(), data: data.clone(), @@ -385,7 +385,7 @@ impl PartialMap for Store { }) } - fn get_or_create_partial(&self, hash: Hash, size: u64) -> io::Result { + fn get_or_create_partial(&self, hash: Hash, size: u64) -> io::Result { let tree = BaoTree::new(ByteNum(size), IROH_BLOCK_SIZE); let outboard_size = usize::try_from(outboard_size(size, IROH_BLOCK_SIZE)).map_err(data_too_large)?; @@ -404,7 +404,7 @@ impl PartialMap for Store { .unwrap() .partial .insert(hash, (data.clone(), ob2)); - Ok(PartialEntry { + Ok(EntryMut { hash, outboard: PreOrderOutboard { root: hash.into(), @@ -415,7 +415,7 @@ impl PartialMap for Store { }) } - async fn insert_complete(&self, entry: PartialEntry) -> io::Result<()> { + async fn insert_complete(&self, entry: EntryMut) -> io::Result<()> { tracing::debug!("insert_complete_entry {:#}", entry.hash()); let hash = entry.hash; let data = entry.data.freeze(); @@ -636,7 +636,7 @@ impl Store { } } -impl PartialEntry { +impl EntryMut { fn outboard_mut(&self) -> PreOrderOutboard { self.outboard.clone() } @@ -646,7 +646,7 @@ impl PartialEntry { } } -impl PartialMapEntry for PartialEntry { +impl MapEntryMut for EntryMut { async fn batch_writer(&self) -> io::Result { let data = self.data_writer(); let outboard = self.outboard_mut(); diff --git a/iroh-bytes/src/store/readonly_mem.rs b/iroh-bytes/src/store/readonly_mem.rs index 99987e7b6a..21560b699c 100644 --- a/iroh-bytes/src/store/readonly_mem.rs +++ b/iroh-bytes/src/store/readonly_mem.rs @@ -10,8 +10,8 @@ use std::{ use crate::{ store::{ - EntryStatus, ExportMode, ImportMode, ImportProgress, Map, MapEntry, PartialMap, - PartialMapEntry, ReadableStore, ValidateProgress, + EntryStatus, ExportMode, ImportMode, ImportProgress, Map, MapEntry, MapEntryMut, + MapMut, ReadableStore, ValidateProgress, }, util::{ progress::{IdGenerator, ProgressSender}, @@ -160,11 +160,11 @@ pub struct Entry { data: Bytes, } -/// The [PartialMapEntry] implementation for [Store]. +/// The [MapEntryMut] implementation for [Store]. /// /// This is an unoccupied type, since [Store] is does not allow creating partial entries. #[derive(Debug, Clone)] -pub enum PartialEntry {} +pub enum EntryMut {} impl MapEntry for Entry { fn hash(&self) -> Hash { @@ -203,10 +203,10 @@ impl Map for Store { } } -impl PartialMap for Store { - type PartialEntry = PartialEntry; +impl MapMut for Store { + type EntryMut = EntryMut; - fn get_or_create_partial(&self, _hash: Hash, _size: u64) -> io::Result { + fn get_or_create_partial(&self, _hash: Hash, _size: u64) -> io::Result { Err(io::Error::new( io::ErrorKind::Other, "cannot create temp entry in readonly database", @@ -232,7 +232,7 @@ impl PartialMap for Store { }) } - async fn insert_complete(&self, _entry: PartialEntry) -> io::Result<()> { + async fn insert_complete(&self, _entry: EntryMut) -> io::Result<()> { // this is unreachable, since we cannot create partial entries unreachable!() } @@ -277,41 +277,41 @@ impl ReadableStore for Store { } } -impl MapEntry for PartialEntry { +impl MapEntry for EntryMut { fn hash(&self) -> Hash { - // this is unreachable, since PartialEntry can not be created + // this is unreachable, since EntryMut can not be created unreachable!() } async fn available_ranges(&self) -> io::Result { - // this is unreachable, since PartialEntry can not be created + // this is unreachable, since EntryMut can not be created unreachable!() } fn size(&self) -> u64 { - // this is unreachable, since PartialEntry can not be created + // this is unreachable, since EntryMut can not be created unreachable!() } #[allow(refining_impl_trait)] async fn outboard(&self) -> io::Result { - // this is unreachable, since PartialEntry can not be created + // this is unreachable, since EntryMut can not be created unreachable!() } #[allow(refining_impl_trait)] async fn data_reader(&self) -> io::Result { - // this is unreachable, since PartialEntry can not be created + // this is unreachable, since EntryMut can not be created unreachable!() } fn is_complete(&self) -> bool { - // this is unreachable, since PartialEntry can not be created + // this is unreachable, since EntryMut can not be created unreachable!() } } -impl PartialMapEntry for PartialEntry { +impl MapEntryMut for EntryMut { async fn batch_writer(&self) -> io::Result { enum Bar {} impl BaoBatchWriter for Bar { diff --git a/iroh-bytes/src/store/traits.rs b/iroh-bytes/src/store/traits.rs index da0b9dc707..10b2c7978a 100644 --- a/iroh-bytes/src/store/traits.rs +++ b/iroh-bytes/src/store/traits.rs @@ -43,11 +43,11 @@ pub enum EntryStatus { /// /// This correspnds to [`EntryStatus`], but also includes the entry itself. #[derive(Debug)] -pub enum PossiblyPartialEntry { +pub enum PossiblyPartialEntry { /// A complete entry. Complete(D::Entry), /// A partial entry. - Partial(D::PartialEntry), + Partial(D::EntryMut), /// We got nothing. NotFound, } @@ -100,7 +100,7 @@ pub trait Map: Clone + Send + Sync + 'static { } /// A partial entry -pub trait PartialMapEntry: MapEntry { +pub trait MapEntryMut: MapEntry { /// Get a batch writer fn batch_writer(&self) -> impl Future> + Send; } @@ -242,17 +242,15 @@ where } /// A mutable bao map -pub trait PartialMap: Map { - /// A partial entry. This is an entry that is writeable and possibly incomplete. - /// - /// It must also be readable. - type PartialEntry: PartialMapEntry; +pub trait MapMut: Map { + /// An entry that is possibly writable + type EntryMut: MapEntryMut; /// Get an existing partial entry, or create a new one. /// /// We need to know the size of the partial entry. This might produce an /// error e.g. if there is not enough space on disk. - fn get_or_create_partial(&self, hash: Hash, size: u64) -> io::Result; + fn get_or_create_partial(&self, hash: Hash, size: u64) -> io::Result; /// Find out if the data behind a `hash` is complete, partial, or not present. /// @@ -269,7 +267,7 @@ pub trait PartialMap: Map { fn get_possibly_partial(&self, hash: &Hash) -> io::Result>; /// Upgrade a partial entry to a complete entry. - fn insert_complete(&self, entry: Self::PartialEntry) -> impl Future>; + fn insert_complete(&self, entry: Self::EntryMut) -> impl Future>; } /// Extension of BaoMap to add misc methods used by the rpc calls. @@ -308,7 +306,7 @@ pub trait ReadableStore: Map { } /// The mutable part of a BaoDb -pub trait Store: ReadableStore + PartialMap { +pub trait Store: ReadableStore + MapMut { /// This trait method imports a file from a local path. /// /// `data` is the path to the file. diff --git a/iroh/tests/gc.rs b/iroh/tests/gc.rs index 43d8fcad75..22431818a6 100644 --- a/iroh/tests/gc.rs +++ b/iroh/tests/gc.rs @@ -8,7 +8,7 @@ use rand::RngCore; use iroh_bytes::{ hashseq::HashSeq, - store::{EntryStatus, PartialMap, Store}, + store::{EntryStatus, MapMut, Store}, util::Tag, BlobFormat, HashAndFormat, }; @@ -195,7 +195,7 @@ mod flat { use iroh_bytes::{ hashseq::HashSeq, - store::{BaoBatchWriter, PartialMap, PartialMapEntry, Store}, + store::{BaoBatchWriter, MapEntryMut, MapMut, Store}, BlobFormat, HashAndFormat, Tag, TempTag, IROH_BLOCK_SIZE, }; @@ -366,7 +366,7 @@ mod flat { async fn simulate_download_partial( bao_store: &S, data: Bytes, - ) -> io::Result<(S::PartialEntry, TempTag)> { + ) -> io::Result<(S::EntryMut, TempTag)> { // simulate the remote side. let (hash, response) = simulate_remote(data.as_ref()); // simulate the local side. diff --git a/iroh/tests/provide.rs b/iroh/tests/provide.rs index fc957ac8e3..a1d79c3a8e 100644 --- a/iroh/tests/provide.rs +++ b/iroh/tests/provide.rs @@ -27,7 +27,7 @@ use iroh_bytes::{ }, protocol::{GetRequest, RangeSpecSeq}, provider, - store::{PartialMap, Store}, + store::{MapMut, Store}, BlobFormat, Hash, }; use iroh_sync::store;