@@ -43,6 +43,7 @@ use spacetimedb_lib::ConnectionId;
4343use spacetimedb_lib:: Identity ;
4444use spacetimedb_paths:: server:: { ReplicaDir , SnapshotsPath } ;
4545use spacetimedb_primitives:: * ;
46+ use spacetimedb_runtime:: Handle ;
4647use spacetimedb_sats:: memory_usage:: MemoryUsage ;
4748use spacetimedb_sats:: raw_identifier:: RawIdentifier ;
4849use spacetimedb_sats:: { AlgebraicType , AlgebraicValue , ProductType , ProductValue } ;
@@ -100,7 +101,7 @@ pub struct RelationalDB {
100101
101102 inner : Locking ,
102103 durability : Option < Arc < Durability > > ,
103- durability_runtime : Option < tokio :: runtime :: Handle > ,
104+ durability_runtime : Option < Handle > ,
104105 snapshot_worker : Option < SnapshotWorker > ,
105106
106107 row_count_fn : RowCountFn ,
@@ -1688,9 +1689,10 @@ pub type LocalDurability = Arc<durability::Local<ProductValue>>;
16881689/// of the commitlog.
16891690pub async fn local_durability (
16901691 replica_dir : ReplicaDir ,
1692+ runtime : Handle ,
16911693 snapshot_worker : Option < & SnapshotWorker > ,
16921694) -> Result < ( LocalDurability , DiskSizeFn ) , DBError > {
1693- local_durability_with_options ( replica_dir, snapshot_worker, <_ >:: default ( ) ) . await
1695+ local_durability_with_options ( replica_dir, runtime , snapshot_worker, <_ >:: default ( ) ) . await
16941696}
16951697
16961698/// Initialize local durability with explicit parameters.
@@ -1701,10 +1703,10 @@ pub async fn local_durability(
17011703/// of the commitlog.
17021704pub async fn local_durability_with_options (
17031705 replica_dir : ReplicaDir ,
1706+ runtime : Handle ,
17041707 snapshot_worker : Option < & SnapshotWorker > ,
17051708 opts : durability:: local:: Options ,
17061709) -> Result < ( LocalDurability , DiskSizeFn ) , DBError > {
1707- let rt = tokio:: runtime:: Handle :: current ( ) ;
17081710 let on_new_segment = snapshot_worker. map ( |snapshot_worker| {
17091711 let snapshot_worker = snapshot_worker. clone ( ) ;
17101712 Arc :: new ( move || {
@@ -1716,7 +1718,7 @@ pub async fn local_durability_with_options(
17161718 let local = asyncify ( move || {
17171719 durability:: Local :: open (
17181720 replica_dir. clone ( ) ,
1719- rt ,
1721+ runtime ,
17201722 opts,
17211723 // Give the durability a handle to request a new snapshot run,
17221724 // which it will send down whenever we rotate commitlog segments.
@@ -1982,19 +1984,22 @@ pub mod tests_utils {
19821984 ) -> Result < ( RelationalDB , Arc < durability:: Local < ProductValue > > ) , DBError > {
19831985 let snapshots = want_snapshot_repo
19841986 . then ( || {
1985- open_snapshot_repo ( root. snapshots ( ) , db_identity, replica_id)
1986- . map ( |repo| SnapshotWorker :: new ( repo, snapshot:: Compression :: Disabled ) )
1987+ open_snapshot_repo ( root. snapshots ( ) , db_identity, replica_id) . map ( |repo| {
1988+ SnapshotWorker :: new ( repo, snapshot:: Compression :: Disabled , Handle :: tokio ( rt. clone ( ) ) )
1989+ } )
19871990 } )
19881991 . transpose ( ) ?;
19891992
1990- let ( local, disk_size_fn) = rt. block_on ( local_durability ( root. clone ( ) , snapshots. as_ref ( ) ) ) ?;
1993+ let runtime = Handle :: tokio ( rt. clone ( ) ) ;
1994+ let ( local, disk_size_fn) =
1995+ rt. block_on ( local_durability ( root. clone ( ) , runtime. clone ( ) , snapshots. as_ref ( ) ) ) ?;
19911996 let history = local. as_history ( ) ;
19921997
19931998 let persistence = Persistence {
19941999 durability : local. clone ( ) ,
19952000 disk_size : disk_size_fn,
19962001 snapshots,
1997- runtime : rt ,
2002+ runtime,
19982003 } ;
19992004
20002005 let ( db, _) = RelationalDB :: open (
@@ -2107,17 +2112,20 @@ pub mod tests_utils {
21072112 ) -> Result < ( RelationalDB , Arc < durability:: Local < ProductValue > > ) , DBError > {
21082113 let snapshots = want_snapshot_repo
21092114 . then ( || {
2110- open_snapshot_repo ( root. snapshots ( ) , Identity :: ZERO , 0 )
2111- . map ( |repo| SnapshotWorker :: new ( repo, snapshot:: Compression :: Disabled ) )
2115+ open_snapshot_repo ( root. snapshots ( ) , Identity :: ZERO , 0 ) . map ( |repo| {
2116+ SnapshotWorker :: new ( repo, snapshot:: Compression :: Disabled , Handle :: tokio ( rt. clone ( ) ) )
2117+ } )
21122118 } )
21132119 . transpose ( ) ?;
2114- let ( local, disk_size_fn) = rt. block_on ( local_durability ( root. clone ( ) , snapshots. as_ref ( ) ) ) ?;
2120+ let runtime = Handle :: tokio ( rt. clone ( ) ) ;
2121+ let ( local, disk_size_fn) =
2122+ rt. block_on ( local_durability ( root. clone ( ) , runtime. clone ( ) , snapshots. as_ref ( ) ) ) ?;
21152123 let history = local. as_history ( ) ;
21162124 let persistence = Persistence {
21172125 durability : local. clone ( ) ,
21182126 disk_size : disk_size_fn,
21192127 snapshots,
2120- runtime : rt ,
2128+ runtime,
21212129 } ;
21222130 let db = Self :: open_db ( history, Some ( persistence) , None , 0 ) ?;
21232131
0 commit comments