Skip to content

Commit ddec75c

Browse files
authored
Merge e81b1f3 into def9abc
2 parents def9abc + e81b1f3 commit ddec75c

File tree

2 files changed

+60
-117
lines changed

2 files changed

+60
-117
lines changed

src/store/fs.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,16 @@ impl entity_manager::Params for EmParams {
218218
type EntityState = Slot;
219219

220220
async fn on_shutdown(
221-
_state: entity_manager::ActiveEntityState<Self>,
222-
_cause: entity_manager::ShutdownCause,
221+
state: entity_manager::ActiveEntityState<Self>,
222+
cause: entity_manager::ShutdownCause,
223223
) {
224+
// this isn't strictly necessary. Drop will run anyway as soon as the
225+
// state is reset to it's default value. Doing it here means that we
226+
// have exact control over where it happens.
227+
if let Some(mut handle) = state.state.0.lock().await.take() {
228+
trace!("shutting down hash: {}, cause: {cause:?}", state.id);
229+
handle.persist(&state);
230+
}
224231
}
225232
}
226233

@@ -312,10 +319,7 @@ impl HashContext {
312319
let res = self.db().get(hash).await.map_err(io::Error::other)?;
313320
let res = match res {
314321
Some(state) => open_bao_file(&hash, state, &self.global).await,
315-
None => Ok(BaoFileHandle::new_partial_mem(
316-
hash,
317-
self.global.options.clone(),
318-
)),
322+
None => Ok(BaoFileHandle::new_partial_mem()),
319323
};
320324
Ok((res?, ()))
321325
})
@@ -362,7 +366,7 @@ async fn open_bao_file(
362366
MemOrFile::File(file)
363367
}
364368
};
365-
BaoFileHandle::new_complete(*hash, data, outboard, options.clone())
369+
BaoFileHandle::new_complete(data, outboard)
366370
}
367371
EntryState::Partial { .. } => BaoFileHandle::new_partial_file(*hash, ctx).await?,
368372
})
@@ -618,12 +622,7 @@ impl Actor {
618622
options: options.clone(),
619623
db: meta::Db::new(db_send),
620624
internal_cmd_tx: fs_commands_tx,
621-
empty: BaoFileHandle::new_complete(
622-
Hash::EMPTY,
623-
MemOrFile::empty(),
624-
MemOrFile::empty(),
625-
options,
626-
),
625+
empty: BaoFileHandle::new_complete(MemOrFile::empty(), MemOrFile::empty()),
627626
protect,
628627
});
629628
rt.spawn(db_actor.run());
@@ -925,18 +924,14 @@ async fn import_bao_impl(
925924
handle: BaoFileHandle,
926925
ctx: HashContext,
927926
) -> api::Result<()> {
928-
trace!(
929-
"importing bao: {} {} bytes",
930-
handle.hash().fmt_short(),
931-
size
932-
);
927+
trace!("importing bao: {} {} bytes", ctx.id.fmt_short(), size);
933928
let mut batch = Vec::<BaoContentItem>::new();
934929
let mut ranges = ChunkRanges::empty();
935930
while let Some(item) = rx.recv().await? {
936931
// if the batch is not empty, the last item is a leaf and the current item is a parent, write the batch
937932
if !batch.is_empty() && batch[batch.len() - 1].is_leaf() && item.is_parent() {
938933
let bitfield = Bitfield::new_unchecked(ranges, size.into());
939-
handle.write_batch(&batch, &bitfield, &ctx.global).await?;
934+
handle.write_batch(&batch, &bitfield, &ctx).await?;
940935
batch.clear();
941936
ranges = ChunkRanges::empty();
942937
}
@@ -952,7 +947,7 @@ async fn import_bao_impl(
952947
}
953948
if !batch.is_empty() {
954949
let bitfield = Bitfield::new_unchecked(ranges, size.into());
955-
handle.write_batch(&batch, &bitfield, &ctx.global).await?;
950+
handle.write_batch(&batch, &bitfield, &ctx).await?;
956951
}
957952
Ok(())
958953
}
@@ -992,7 +987,6 @@ async fn export_ranges_impl(
992987
"exporting ranges: {hash} {ranges:?} size={}",
993988
handle.current_size()?
994989
);
995-
debug_assert!(handle.hash() == hash, "hash mismatch");
996990
let bitfield = handle.bitfield()?;
997991
let data = handle.data_reader();
998992
let size = bitfield.size();
@@ -1053,8 +1047,7 @@ async fn export_bao_impl(
10531047
handle: BaoFileHandle,
10541048
) -> anyhow::Result<()> {
10551049
let ExportBaoRequest { ranges, hash, .. } = cmd;
1056-
debug_assert!(handle.hash() == hash, "hash mismatch");
1057-
let outboard = handle.outboard()?;
1050+
let outboard = handle.outboard(&hash)?;
10581051
let size = outboard.tree.size();
10591052
if size == 0 && hash != Hash::EMPTY {
10601053
// we have no data whatsoever, so we stop here

0 commit comments

Comments
 (0)