@@ -52,32 +52,32 @@ impl KVStore for FilesystemStore {
52
52
type Reader = FilesystemReader ;
53
53
54
54
fn read ( & self , namespace : & str , key : & str ) -> std:: io:: Result < Self :: Reader > {
55
- let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
56
- let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
57
- let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key) . or_default ( ) ) ;
58
-
59
55
if key. is_empty ( ) {
60
56
let msg = format ! ( "Failed to read {}/{}: key may not be empty." , namespace, key) ;
61
57
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
62
58
}
63
59
60
+ let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
61
+ let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
62
+ let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key) . or_default ( ) ) ;
63
+
64
64
let mut dest_file_path = self . data_dir . clone ( ) ;
65
65
dest_file_path. push ( namespace) ;
66
66
dest_file_path. push ( key) ;
67
67
FilesystemReader :: new ( dest_file_path, inner_lock_ref)
68
68
}
69
69
70
70
fn write ( & self , namespace : & str , key : & str , buf : & [ u8 ] ) -> std:: io:: Result < ( ) > {
71
- let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
72
- let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
73
- let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key) . or_default ( ) ) ;
74
- let _guard = inner_lock_ref. write ( ) . unwrap ( ) ;
75
-
76
71
if key. is_empty ( ) {
77
72
let msg = format ! ( "Failed to write {}/{}: key may not be empty." , namespace, key) ;
78
73
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
79
74
}
80
75
76
+ let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
77
+ let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
78
+ let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key) . or_default ( ) ) ;
79
+ let _guard = inner_lock_ref. write ( ) . unwrap ( ) ;
80
+
81
81
let mut dest_file_path = self . data_dir . clone ( ) ;
82
82
dest_file_path. push ( namespace) ;
83
83
dest_file_path. push ( key) ;
@@ -143,17 +143,17 @@ impl KVStore for FilesystemStore {
143
143
}
144
144
145
145
fn remove ( & self , namespace : & str , key : & str ) -> std:: io:: Result < ( ) > {
146
+ if key. is_empty ( ) {
147
+ let msg = format ! ( "Failed to remove {}/{}: key may not be empty." , namespace, key) ;
148
+ return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
149
+ }
150
+
146
151
let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
147
152
let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
148
153
let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key. clone ( ) ) . or_default ( ) ) ;
149
154
150
155
let _guard = inner_lock_ref. write ( ) . unwrap ( ) ;
151
156
152
- if key. is_empty ( ) {
153
- let msg = format ! ( "Failed to remove {}/{}: key may not be empty." , namespace, key) ;
154
- return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
155
- }
156
-
157
157
let mut dest_file_path = self . data_dir . clone ( ) ;
158
158
dest_file_path. push ( namespace) ;
159
159
dest_file_path. push ( key) ;
0 commit comments