6464//! safely shut down as well. Any store refs you are holding will be inoperable
6565//! after this.
6666use std:: {
67- collections:: { HashMap , HashSet } ,
6867 fmt, fs,
6968 future:: Future ,
7069 io:: Write ,
@@ -93,7 +92,7 @@ use meta::{list_blobs, Snapshot};
9392use n0_future:: { future:: yield_now, io} ;
9493use nested_enum_utils:: enum_conversions;
9594use range_collections:: range_set:: RangeSetRange ;
96- use tokio:: task:: { Id , JoinError , JoinSet } ;
95+ use tokio:: task:: { JoinError , JoinSet } ;
9796use tracing:: { error, instrument, trace} ;
9897
9998use crate :: {
@@ -117,7 +116,7 @@ use crate::{
117116 } ,
118117} ;
119118mod bao_file;
120- use bao_file:: { BaoFileHandle , BaoFileHandleWeak } ;
119+ use bao_file:: BaoFileHandle ;
121120mod delete_set;
122121mod entry_state;
123122mod import;
@@ -259,7 +258,7 @@ impl HashContext {
259258 & self . ctx . options
260259 }
261260
262- pub async fn lock ( & self ) -> tokio:: sync:: MutexGuard < ' _ , Option < BaoFileHandleWeak > > {
261+ pub async fn lock ( & self ) -> tokio:: sync:: MutexGuard < ' _ , Option < BaoFileHandle > > {
263262 self . slot . 0 . lock ( ) . await
264263 }
265264
@@ -377,14 +376,9 @@ async fn open_bao_file(
377376/// An entry for each hash, containing a weak reference to a BaoFileHandle
378377/// wrapped in a tokio mutex so handle creation is sequential.
379378#[ derive( Debug , Clone , Default ) ]
380- pub ( crate ) struct Slot ( Arc < tokio:: sync:: Mutex < Option < BaoFileHandleWeak > > > ) ;
379+ pub ( crate ) struct Slot ( Arc < tokio:: sync:: Mutex < Option < BaoFileHandle > > > ) ;
381380
382381impl Slot {
383- pub async fn is_live ( & self ) -> bool {
384- let slot = self . 0 . lock ( ) . await ;
385- slot. as_ref ( ) . map ( |weak| !weak. is_dead ( ) ) . unwrap_or ( false )
386- }
387-
388382 /// Get the handle if it exists and is still alive, otherwise load it from the database.
389383 /// If there is nothing in the database, create a new in-memory handle.
390384 ///
@@ -396,14 +390,12 @@ impl Slot {
396390 T : Default ,
397391 {
398392 let mut slot = self . 0 . lock ( ) . await ;
399- if let Some ( weak) = & * slot {
400- if let Some ( handle) = weak. upgrade ( ) {
401- return Ok ( ( handle, Default :: default ( ) ) ) ;
402- }
393+ if let Some ( handle) = & * slot {
394+ return Ok ( ( handle. clone ( ) , Default :: default ( ) ) ) ;
403395 }
404396 let handle = make ( ) . await ;
405397 if let Ok ( ( handle, _) ) = & handle {
406- * slot = Some ( handle. downgrade ( ) ) ;
398+ * slot = Some ( handle. clone ( ) ) ;
407399 }
408400 handle
409401 }
@@ -845,7 +837,7 @@ async fn finish_import_impl(import_data: ImportEntry, ctx: HashContext) -> io::R
845837 }
846838 }
847839 let guard = ctx. lock ( ) . await ;
848- let handle = guard. as_ref ( ) . and_then ( |x| x. upgrade ( ) ) ;
840+ let handle = guard. as_ref ( ) . map ( |x| x. clone ( ) ) ;
849841 // if I do have an existing handle, I have to possibly deal with observers.
850842 // if I don't have an existing handle, there are 2 cases:
851843 // the entry exists in the db, but we don't have a handle
0 commit comments