Skip to content

Commit 3d603b0

Browse files
committed
remove options from BaoFileHandleInner
it is present in global, so now we don't need to impl drop, we have it in on_shutdown
1 parent def9abc commit 3d603b0

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

src/store/fs.rs

Lines changed: 12 additions & 13 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.global.options);
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(hash)),
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(*hash, 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(Hash::EMPTY, MemOrFile::empty(), MemOrFile::empty()),
627626
protect,
628627
});
629628
rt.spawn(db_actor.run());

src/store/fs/bao_file.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ impl BaoFileStorage {
507507
pub struct BaoFileHandleInner {
508508
pub(crate) storage: watch::Sender<BaoFileStorage>,
509509
hash: Hash,
510-
options: Arc<Options>,
511510
}
512511

513512
impl fmt::Debug for BaoFileHandleInner {
@@ -526,15 +525,14 @@ impl fmt::Debug for BaoFileHandleInner {
526525
pub struct BaoFileHandle(Arc<BaoFileHandleInner>);
527526

528527
impl BaoFileHandle {
529-
pub fn persist(&mut self) {
528+
pub fn persist(&mut self, options: &Options) {
530529
self.0.storage.send_if_modified(|guard| {
531530
if Arc::strong_count(&self.0) > 1 {
532531
return false;
533532
}
534533
let BaoFileStorage::Partial(fs) = guard.take() else {
535534
return false;
536535
};
537-
let options = &self.options;
538536
let path = options.path.bitfield_path(&self.hash);
539537
trace!(
540538
"writing bitfield for hash {} to {}",
@@ -554,12 +552,6 @@ impl BaoFileHandle {
554552
}
555553
}
556554

557-
impl Drop for BaoFileHandle {
558-
fn drop(&mut self) {
559-
self.persist();
560-
}
561-
}
562-
563555
/// A reader for a bao file, reading just the data.
564556
#[derive(Debug)]
565557
pub struct DataReader(BaoFileHandle);
@@ -601,12 +593,11 @@ impl BaoFileHandle {
601593
/// Create a new bao file handle.
602594
///
603595
/// This will create a new file handle with an empty memory storage.
604-
pub fn new_partial_mem(hash: Hash, options: Arc<Options>) -> Self {
596+
pub fn new_partial_mem(hash: Hash) -> Self {
605597
let storage = BaoFileStorage::partial_mem();
606598
Self(Arc::new(BaoFileHandleInner {
607599
storage: watch::Sender::new(storage),
608600
hash,
609-
options: options.clone(),
610601
}))
611602
}
612603

@@ -626,7 +617,6 @@ impl BaoFileHandle {
626617
Ok(Self(Arc::new(BaoFileHandleInner {
627618
storage: watch::Sender::new(storage),
628619
hash,
629-
options,
630620
})))
631621
}
632622

@@ -635,13 +625,11 @@ impl BaoFileHandle {
635625
hash: Hash,
636626
data: MemOrFile<Bytes, FixedSize<File>>,
637627
outboard: MemOrFile<Bytes, File>,
638-
options: Arc<Options>,
639628
) -> Self {
640629
let storage = CompleteStorage { data, outboard }.into();
641630
Self(Arc::new(BaoFileHandleInner {
642631
storage: watch::Sender::new(storage),
643632
hash,
644-
options,
645633
}))
646634
}
647635

0 commit comments

Comments
 (0)