@@ -93,9 +93,7 @@ impl KVStoreSync for VssStore {
9393 fn read (
9494 & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
9595 ) -> io:: Result < Vec < u8 > > {
96- let locking_key = self . build_locking_key ( primary_namespace, secondary_namespace, key) ;
97- let fut =
98- self . inner . read_internal ( locking_key, primary_namespace, secondary_namespace, key) ;
96+ let fut = self . inner . read_internal ( primary_namespace, secondary_namespace, key) ;
9997 self . runtime . block_on ( fut)
10098 }
10199
@@ -143,13 +141,12 @@ impl KVStore for VssStore {
143141 fn read (
144142 & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
145143 ) -> Pin < Box < dyn Future < Output = Result < Vec < u8 > , io:: Error > > + Send > > {
146- let locking_key = self . build_locking_key ( primary_namespace, secondary_namespace, key) ;
147144 let primary_namespace = primary_namespace. to_string ( ) ;
148145 let secondary_namespace = secondary_namespace. to_string ( ) ;
149146 let key = key. to_string ( ) ;
150147 let inner = Arc :: clone ( & self . inner ) ;
151148 Box :: pin ( async move {
152- inner. read_internal ( locking_key , & primary_namespace, & secondary_namespace, & key) . await
149+ inner. read_internal ( & primary_namespace, & secondary_namespace, & key) . await
153150 } )
154151 }
155152 fn write (
@@ -304,38 +301,34 @@ impl VssStoreInner {
304301 }
305302
306303 async fn read_internal (
307- & self , locking_key : String , primary_namespace : & str , secondary_namespace : & str , key : & str ,
304+ & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
308305 ) -> io:: Result < Vec < u8 > > {
309306 check_namespace_key_validity ( primary_namespace, secondary_namespace, Some ( key) , "read" ) ?;
310307
311- self . execute_locked_read ( locking_key, async move || {
312- let obfuscated_key =
313- self . build_obfuscated_key ( primary_namespace, secondary_namespace, key) ;
314- let request = GetObjectRequest { store_id : self . store_id . clone ( ) , key : obfuscated_key } ;
315- let resp = self . client . get_object ( & request) . await . map_err ( |e| {
316- let msg = format ! (
317- "Failed to read from key {}/{}/{}: {}" ,
318- primary_namespace, secondary_namespace, key, e
319- ) ;
320- match e {
321- VssError :: NoSuchKeyError ( ..) => Error :: new ( ErrorKind :: NotFound , msg) ,
322- _ => Error :: new ( ErrorKind :: Other , msg) ,
323- }
324- } ) ?;
325-
326- // unwrap safety: resp.value must be always present for a non-erroneous VSS response, otherwise
327- // it is an API-violation which is converted to [`VssError::InternalServerError`] in [`VssClient`]
328- let storable = Storable :: decode ( & resp. value . unwrap ( ) . value [ ..] ) . map_err ( |e| {
329- let msg = format ! (
330- "Failed to decode data read from key {}/{}/{}: {}" ,
331- primary_namespace, secondary_namespace, key, e
332- ) ;
333- Error :: new ( ErrorKind :: Other , msg)
334- } ) ?;
335-
336- Ok ( self . storable_builder . deconstruct ( storable) ?. 0 )
337- } )
338- . await
308+ let obfuscated_key = self . build_obfuscated_key ( primary_namespace, secondary_namespace, key) ;
309+ let request = GetObjectRequest { store_id : self . store_id . clone ( ) , key : obfuscated_key } ;
310+ let resp = self . client . get_object ( & request) . await . map_err ( |e| {
311+ let msg = format ! (
312+ "Failed to read from key {}/{}/{}: {}" ,
313+ primary_namespace, secondary_namespace, key, e
314+ ) ;
315+ match e {
316+ VssError :: NoSuchKeyError ( ..) => Error :: new ( ErrorKind :: NotFound , msg) ,
317+ _ => Error :: new ( ErrorKind :: Other , msg) ,
318+ }
319+ } ) ?;
320+
321+ // unwrap safety: resp.value must be always present for a non-erroneous VSS response, otherwise
322+ // it is an API-violation which is converted to [`VssError::InternalServerError`] in [`VssClient`]
323+ let storable = Storable :: decode ( & resp. value . unwrap ( ) . value [ ..] ) . map_err ( |e| {
324+ let msg = format ! (
325+ "Failed to decode data read from key {}/{}/{}: {}" ,
326+ primary_namespace, secondary_namespace, key, e
327+ ) ;
328+ Error :: new ( ErrorKind :: Other , msg)
329+ } ) ?;
330+
331+ Ok ( self . storable_builder . deconstruct ( storable) ?. 0 )
339332 }
340333
341334 async fn write_internal (
@@ -445,21 +438,6 @@ impl VssStoreInner {
445438 res
446439 }
447440
448- async fn execute_locked_read <
449- F : Future < Output = Result < Vec < u8 > , lightning:: io:: Error > > ,
450- FN : FnOnce ( ) -> F ,
451- > (
452- & self , locking_key : String , callback : FN ,
453- ) -> Result < Vec < u8 > , lightning:: io:: Error > {
454- let inner_lock_ref = self . get_inner_lock_ref ( locking_key. clone ( ) ) ;
455- let res = {
456- let _guard = inner_lock_ref. read ( ) . await ;
457- callback ( ) . await
458- } ;
459- self . clean_locks ( & inner_lock_ref, locking_key) ;
460- res
461- }
462-
463441 fn clean_locks ( & self , inner_lock_ref : & Arc < RwLock < u64 > > , locking_key : String ) {
464442 // If there no arcs in use elsewhere, this means that there are no in-flight writes. We can remove the map entry
465443 // to prevent leaking memory. The two arcs that are expected are the one in the map and the one held here in
0 commit comments