@@ -51,6 +51,7 @@ pub struct VssStore {
5151 // operations aren't sensitive to the order of execution.
5252 next_version : AtomicU64 ,
5353 runtime : Arc < Runtime > ,
54+ inner_runtime : Arc < tokio:: runtime:: Runtime > ,
5455}
5556
5657impl VssStore {
@@ -60,7 +61,8 @@ impl VssStore {
6061 ) -> Self {
6162 let inner = Arc :: new ( VssStoreInner :: new ( base_url, store_id, vss_seed, header_provider) ) ;
6263 let next_version = AtomicU64 :: new ( 1 ) ;
63- Self { inner, next_version, runtime }
64+ let inner_runtime = Arc :: new ( tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ) ;
65+ Self { inner, next_version, runtime, inner_runtime }
6466 }
6567
6668 // Same logic as for the obfuscated keys below, but just for locking, using the plaintext keys
@@ -103,16 +105,31 @@ impl KVStoreSync for VssStore {
103105 ) -> io:: Result < ( ) > {
104106 let locking_key = self . build_locking_key ( primary_namespace, secondary_namespace, key) ;
105107 let ( inner_lock_ref, version) = self . get_new_version_and_lock_ref ( locking_key. clone ( ) ) ;
106- let fut = self . inner . write_internal (
107- inner_lock_ref,
108- locking_key,
109- version,
110- primary_namespace,
111- secondary_namespace,
112- key,
113- buf,
114- ) ;
115- self . runtime . block_on ( fut)
108+ let write_id: u64 = rand:: random ( ) ;
109+ println ! ( "WRITE {} IS SYNC" , write_id) ;
110+ let primary_namespace = primary_namespace. to_string ( ) ;
111+ let secondary_namespace = secondary_namespace. to_string ( ) ;
112+ let key = key. to_string ( ) ;
113+ let inner = Arc :: clone ( & self . inner ) ;
114+ let fut = async move {
115+ inner
116+ . write_internal (
117+ inner_lock_ref,
118+ locking_key,
119+ version,
120+ & primary_namespace,
121+ & secondary_namespace,
122+ & key,
123+ buf,
124+ write_id,
125+ )
126+ . await
127+ } ;
128+ // let spawned_fut = self.inner_runtime.spawn(fut);
129+ // self
130+ // .runtime
131+ // .block_on( async { spawned_fut.await.unwrap() })
132+ self . runtime . spawn_block_on ( async { fut. await } , write_id)
116133 }
117134
118135 fn remove (
@@ -158,6 +175,8 @@ impl KVStore for VssStore {
158175 let secondary_namespace = secondary_namespace. to_string ( ) ;
159176 let key = key. to_string ( ) ;
160177 let inner = Arc :: clone ( & self . inner ) ;
178+ let write_id: u64 = rand:: random ( ) ;
179+ println ! ( "WRITE {} IS ASYNC" , write_id) ;
161180 Box :: pin ( async move {
162181 inner
163182 . write_internal (
@@ -168,6 +187,7 @@ impl KVStore for VssStore {
168187 & secondary_namespace,
169188 & key,
170189 buf,
190+ write_id,
171191 )
172192 . await
173193 } )
@@ -332,7 +352,7 @@ impl VssStoreInner {
332352
333353 async fn write_internal (
334354 & self , inner_lock_ref : Arc < tokio:: sync:: Mutex < u64 > > , locking_key : String , version : u64 ,
335- primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > ,
355+ primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > , write_id : u64 ,
336356 ) -> io:: Result < ( ) > {
337357 check_namespace_key_validity ( primary_namespace, secondary_namespace, Some ( key) , "write" ) ?;
338358
@@ -345,21 +365,39 @@ impl VssStoreInner {
345365 store_id : self . store_id . clone ( ) ,
346366 global_version : None ,
347367 transaction_items : vec ! [ KeyValue {
348- key: obfuscated_key,
368+ key: obfuscated_key. clone ( ) ,
349369 version: vss_version,
350370 value: storable. encode_to_vec( ) ,
351371 } ] ,
352372 delete_items : vec ! [ ] ,
353373 } ;
354374
355- self . client . put_object ( & request) . await . map_err ( |e| {
375+ println ! (
376+ "WRITE {}: {}/{}/{} ({})" ,
377+ write_id, primary_namespace, secondary_namespace, key, obfuscated_key
378+ ) ;
379+ let fut = self . client . put_object ( & request) ;
380+ // let res =
381+ // tokio::time::timeout(Duration::from_secs(5), fut).await.unwrap().map_err(|e| {
382+ // let msg = format!(
383+ // "Failed to write to key {}/{}/{}: {}",
384+ // primary_namespace, secondary_namespace, key, e
385+ // );
386+ // Error::new(ErrorKind::Other, msg)
387+ // });
388+ let res = fut. await . map_err ( |e| {
356389 let msg = format ! (
357390 "Failed to write to key {}/{}/{}: {}" ,
358391 primary_namespace, secondary_namespace, key, e
359392 ) ;
360393 Error :: new ( ErrorKind :: Other , msg)
361- } ) ?;
394+ } ) ;
395+ println ! (
396+ "WRITE DONE {}: {}/{}/{} ({})" ,
397+ write_id, primary_namespace, secondary_namespace, key, obfuscated_key
398+ ) ;
362399
400+ res?;
363401 Ok ( ( ) )
364402 } )
365403 . await
@@ -417,7 +455,9 @@ impl VssStoreInner {
417455 callback : FN ,
418456 ) -> Result < ( ) , lightning:: io:: Error > {
419457 let res = {
458+ println ! ( "BEFORE TAKING THE LOCK" ) ;
420459 let mut last_written_version = inner_lock_ref. lock ( ) . await ;
460+ println ! ( "AFTER TAKING THE LOCK" ) ;
421461
422462 // Check if we already have a newer version written/removed. This is used in async contexts to realize eventual
423463 // consistency.
0 commit comments