Skip to content

Commit

Permalink
Merge branch 'main' into better-shutdown
Browse files Browse the repository at this point in the history
# Conflicts:
#	iroh-bytes/src/store/bao_file.rs
  • Loading branch information
rklaehn committed Mar 20, 2024
2 parents 957dbd0 + 953a768 commit 5f10ba3
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 368 deletions.
31 changes: 16 additions & 15 deletions iroh-bytes/src/get/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::io;

use crate::hashseq::parse_hash_seq;
use crate::store::BaoBatchWriter;
use crate::store::PossiblyPartialEntry;

use crate::{
export::ExportProgress,
Expand Down Expand Up @@ -72,8 +71,8 @@ async fn get_blob<
hash: &Hash,
progress: impl ProgressSender<Msg = DownloadProgress> + IdGenerator,
) -> Result<Stats, GetError> {
let end = match db.get_possibly_partial(hash).await? {
PossiblyPartialEntry::Complete(entry) => {
let end = match db.get_mut(hash).await? {
Some(entry) if entry.is_complete() => {
tracing::info!("already got entire blob");
progress
.send(DownloadProgress::FoundLocal {
Expand All @@ -85,7 +84,7 @@ async fn get_blob<
.await?;
return Ok(Stats::default());
}
PossiblyPartialEntry::Partial(entry) => {
Some(entry) => {
trace!("got partial data for {}", hash);
let valid_ranges = valid_ranges::<D>(&entry)
.await
Expand Down Expand Up @@ -117,7 +116,7 @@ async fn get_blob<

get_blob_inner_partial(db, header, entry, progress).await?
}
PossiblyPartialEntry::NotFound => {
None => {
// full request
let conn = get_conn().await.map_err(GetError::Io)?;
let request = get::fsm::start(conn, GetRequest::single(*hash));
Expand Down Expand Up @@ -270,8 +269,11 @@ async fn get_blob_inner_partial<D: BaoStore>(
///
/// This will compute the valid ranges for partial blobs, so it is somewhat expensive for those.
pub async fn blob_info<D: BaoStore>(db: &D, hash: &Hash) -> io::Result<BlobInfo<D>> {
io::Result::Ok(match db.get_possibly_partial(hash).await? {
PossiblyPartialEntry::Partial(entry) => {
io::Result::Ok(match db.get_mut(hash).await? {
Some(entry) if entry.is_complete() => BlobInfo::Complete {
size: entry.size().value(),
},
Some(entry) => {
let valid_ranges = valid_ranges::<D>(&entry)
.await
.ok()
Expand All @@ -281,10 +283,7 @@ pub async fn blob_info<D: BaoStore>(db: &D, hash: &Hash) -> io::Result<BlobInfo<
valid_ranges,
}
}
PossiblyPartialEntry::Complete(entry) => BlobInfo::Complete {
size: entry.size().value(),
},
PossiblyPartialEntry::NotFound => BlobInfo::Missing,
None => BlobInfo::Missing,
})
}

Expand All @@ -308,8 +307,8 @@ async fn get_hash_seq<
sender: impl ProgressSender<Msg = DownloadProgress> + IdGenerator,
) -> Result<Stats, GetError> {
use tracing::info as log;
let finishing =
if let PossiblyPartialEntry::Complete(entry) = db.get_possibly_partial(root_hash).await? {
let finishing = match db.get_mut(root_hash).await? {
Some(entry) if entry.is_complete() => {
log!("already got collection - doing partial download");
// send info that we have the hashseq itself entirely
sender
Expand Down Expand Up @@ -404,7 +403,8 @@ async fn get_hash_seq<
};
next = end_blob.next();
}
} else {
}
_ => {
tracing::info!("don't have collection - doing full download");
// don't have the collection, so probably got nothing
let conn = get_conn().await.map_err(GetError::Io)?;
Expand Down Expand Up @@ -456,7 +456,8 @@ async fn get_hash_seq<
let end_blob = get_blob_inner(db, header, sender.clone()).await?;
next = end_blob.next();
}
};
}
};
// this closes the bidi stream. Do something with the stats?
let stats = finishing.next().await?;
Ok(stats)
Expand Down
5 changes: 4 additions & 1 deletion iroh-bytes/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Implementations of blob stores
use crate::{BlobFormat, Hash, HashAndFormat};
pub mod bao_file;

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

#[cfg(feature = "file-db")]
Expand Down
Loading

0 comments on commit 5f10ba3

Please sign in to comment.