1010
1111use hashbrown:: { HashMap , hash_map} ;
1212use slotmap:: SlotMap ;
13+ use tokio:: task:: JoinHandle ;
1314use tracing:: { debug, trace} ;
1415
1516use restate_storage_api:: StorageError ;
1617use restate_storage_api:: vqueue_table:: metadata:: { self , VQueueMeta } ;
1718use restate_storage_api:: vqueue_table:: { ReadVQueueTable , ScanVQueueTable } ;
1819use restate_types:: vqueue:: VQueueId ;
1920
20- use crate :: vqueue_config:: ConfigPool ;
21-
2221type Result < T > = std:: result:: Result < T , StorageError > ;
2322
2423slotmap:: new_key_type! { pub struct VQueueCacheKey ; }
@@ -35,10 +34,6 @@ impl<'a> VQueuesMeta<'a> {
3534 Self { inner : cache }
3635 }
3736
38- pub ( crate ) fn config_pool ( & ' a self ) -> & ' a ConfigPool {
39- & self . inner . config
40- }
41-
4237 pub fn get ( & self , key : VQueueCacheKey ) -> Option < & Slot > {
4338 self . inner . slab . get ( key)
4439 }
@@ -102,7 +97,6 @@ impl Slot {
10297// Needs rewriting after the workload pattern becomes more clear.
10398#[ derive( Clone ) ]
10499pub struct VQueuesMetaCache {
105- config : ConfigPool ,
106100 queues : HashMap < VQueueId , VQueueCacheKey > ,
107101 slab : SlotMap < VQueueCacheKey , Slot > ,
108102}
@@ -121,31 +115,36 @@ impl VQueuesMetaCache {
121115 Self {
122116 slab : Default :: default ( ) ,
123117 queues : Default :: default ( ) ,
124- config : ConfigPool :: default ( ) ,
125118 }
126119 }
127120
128121 /// Initializes the vqueue cache by loading all active vqueues into the cache.
129122 ///
130123 /// From this point on, the cache remains in-sync with the storage state by
131124 /// using the "apply_updates" method.
132- pub async fn create < S : ScanVQueueTable > ( storage : & S ) -> Result < Self > {
133- let mut cache = Self {
134- slab : Default :: default ( ) ,
135- queues : Default :: default ( ) ,
136- config : ConfigPool :: default ( ) ,
137- } ;
138- // find and load all active vqueues.
139- storage. scan_active_vqueues ( |qid, meta| {
140- let key = cache. slab . insert ( Slot {
141- qid : qid. clone ( ) ,
142- meta,
143- } ) ;
144- // SAFETY: at batch load time we are guaranteed to observe every vqueue id only once.
145- unsafe { cache. queues . insert_unique_unchecked ( qid, key) } ;
146- } ) ?;
147-
148- Ok ( cache)
125+ pub async fn create < S : ScanVQueueTable + Send + Sync + ' static > ( storage : S ) -> Result < Self > {
126+ let handle: JoinHandle < Result < _ > > = tokio:: task:: spawn_blocking ( {
127+ move || {
128+ let mut slab = SlotMap :: default ( ) ;
129+ let mut queues = HashMap :: default ( ) ;
130+ // find and load all active vqueues.
131+ storage. scan_active_vqueues ( |qid, meta| {
132+ let key = slab. insert ( Slot {
133+ qid : qid. clone ( ) ,
134+ meta,
135+ } ) ;
136+ // SAFETY: at batch load time we are guaranteed to observe every vqueue id only once.
137+ unsafe { queues. insert_unique_unchecked ( qid, key) } ;
138+ } ) ?;
139+ Ok ( ( slab, queues) )
140+ }
141+ } ) ;
142+
143+ let ( slab, queues) = handle
144+ . await
145+ . map_err ( |e| StorageError :: Generic ( e. into ( ) ) ) ??;
146+
147+ Ok ( Self { slab, queues } )
149148 }
150149
151150 pub async fn load < S : ReadVQueueTable > (
0 commit comments