@@ -301,7 +301,7 @@ fn open_storage_internal(
301301 let reader = StorageReader {
302302 db_reader,
303303 scope : storage_config. scope ,
304- file_readers,
304+ file_readers : Arc :: new ( file_readers ) ,
305305 tables,
306306 open_readers_metric,
307307 } ;
@@ -505,7 +505,7 @@ pub enum StorageScope {
505505#[ derive( Clone ) ]
506506pub struct StorageReader {
507507 db_reader : DbReader ,
508- file_readers : FileHandlers < RO > ,
508+ file_readers : Arc < FileHandlers < RO > > ,
509509 tables : Arc < Tables > ,
510510 scope : StorageScope ,
511511 open_readers_metric : Option < & ' static MetricGauge > ,
@@ -569,8 +569,7 @@ impl StorageReader {
569569 pub fn begin_ro_txn ( & self ) -> StorageResult < StorageTxn < ' _ , RO > > {
570570 Ok ( StorageTxn {
571571 txn : self . db_reader . begin_ro_txn ( ) ?,
572- // TODO(Dean): Wrap FileHandlers with an Arc to avoid cloning.
573- file_handlers : self . file_readers . clone ( ) ,
572+ file_handlers : Arc :: clone ( & self . file_readers ) ,
574573 tables : self . tables . clone ( ) ,
575574 scope : self . scope ,
576575 _metric_updater : MetricsHandler :: new ( self . open_readers_metric ) ,
@@ -636,7 +635,7 @@ type SharedStorageState = Arc<Mutex<SharedState>>;
636635/// There is a single non-clonable writer instance, to make sure there is only one write transaction
637636/// at any given moment.
638637pub struct StorageWriter {
639- file_writers : FileHandlers < RW > ,
638+ file_writers : Arc < FileHandlers < RW > > ,
640639 scope : StorageScope ,
641640 /// Shared state containing db_writer, tables, and batching information.
642641 shared_state : SharedStorageState ,
@@ -649,7 +648,7 @@ impl StorageWriter {
649648 scope : StorageScope ,
650649 shared_state : SharedStorageState ,
651650 ) -> Self {
652- Self { file_writers, scope, shared_state }
651+ Self { file_writers : Arc :: new ( file_writers ) , scope, shared_state }
653652 }
654653
655654 /// Returns a [`StorageTxnRW`] for reading and modifying data in the storage.
@@ -663,7 +662,7 @@ impl StorageWriter {
663662 guard. ensure_active_txn ( ) ?;
664663 Ok ( StorageTxnRW {
665664 guard,
666- file_handlers : self . file_writers . clone ( ) ,
665+ file_handlers : Arc :: clone ( & self . file_writers ) ,
667666 scope : self . scope ,
668667 _metric_updater : MetricsHandler :: new ( None ) ,
669668 } )
@@ -817,7 +816,7 @@ pub(crate) trait StorageTransaction: Sized {
817816/// The actual functionality is implemented on the transaction in multiple traits.
818817pub struct StorageTxn < ' env , Mode : TransactionKind + ' static > {
819818 txn : DbTransaction < ' env , Mode > ,
820- file_handlers : FileHandlers < Mode > ,
819+ file_handlers : Arc < FileHandlers < Mode > > ,
821820 tables : Arc < Tables > ,
822821 scope : StorageScope ,
823822 // Do not remove this. It is used to automatically update metrics on create/drop.
@@ -829,7 +828,7 @@ pub struct StorageTxn<'env, Mode: TransactionKind + 'static> {
829828/// to the transaction.
830829pub struct StorageTxnRW < ' a > {
831830 guard : MutexGuard < ' a , SharedState > ,
832- file_handlers : FileHandlers < RW > ,
831+ file_handlers : Arc < FileHandlers < RW > > ,
833832 scope : StorageScope ,
834833 _metric_updater : MetricsHandler ,
835834}
0 commit comments