@@ -35,7 +35,7 @@ fn path_to_windows_str<T: AsRef<OsStr>>(path: T) -> Vec<u16> {
35
35
pub struct FilesystemStore {
36
36
data_dir : PathBuf ,
37
37
tmp_file_counter : AtomicUsize ,
38
- locks : Mutex < HashMap < ( String , String ) , Arc < RwLock < ( ) > > > > ,
38
+ locks : Mutex < HashMap < PathBuf , Arc < RwLock < ( ) > > > > ,
39
39
}
40
40
41
41
impl FilesystemStore {
@@ -71,13 +71,13 @@ impl KVStore for FilesystemStore {
71
71
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
72
72
}
73
73
74
- let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
75
- let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
76
- let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key) . or_default ( ) ) ;
77
-
78
74
let mut dest_file_path = self . data_dir . clone ( ) ;
79
75
dest_file_path. push ( namespace) ;
80
76
dest_file_path. push ( key) ;
77
+
78
+ let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
79
+ let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( dest_file_path. clone ( ) ) . or_default ( ) ) ;
80
+
81
81
FilesystemReader :: new ( dest_file_path, inner_lock_ref)
82
82
}
83
83
@@ -97,15 +97,14 @@ impl KVStore for FilesystemStore {
97
97
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
98
98
}
99
99
100
- let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
101
- let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
102
- let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key) . or_default ( ) ) ;
103
- let _guard = inner_lock_ref. write ( ) . unwrap ( ) ;
104
-
105
100
let mut dest_file_path = self . data_dir . clone ( ) ;
106
101
dest_file_path. push ( namespace) ;
107
102
dest_file_path. push ( key) ;
108
103
104
+ let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
105
+ let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( dest_file_path. clone ( ) ) . or_default ( ) ) ;
106
+ let _guard = inner_lock_ref. write ( ) . unwrap ( ) ;
107
+
109
108
let parent_directory = dest_file_path
110
109
. parent ( )
111
110
. ok_or_else ( || {
@@ -183,16 +182,15 @@ impl KVStore for FilesystemStore {
183
182
return Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , msg) ) ;
184
183
}
185
184
186
- let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
187
- let lock_key = ( namespace. to_string ( ) , key. to_string ( ) ) ;
188
- let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( lock_key. clone ( ) ) . or_default ( ) ) ;
189
-
190
- let _guard = inner_lock_ref. write ( ) . unwrap ( ) ;
191
-
192
185
let mut dest_file_path = self . data_dir . clone ( ) ;
193
186
dest_file_path. push ( namespace) ;
194
187
dest_file_path. push ( key) ;
195
188
189
+ let mut outer_lock = self . locks . lock ( ) . unwrap ( ) ;
190
+ let inner_lock_ref = Arc :: clone ( & outer_lock. entry ( dest_file_path. clone ( ) ) . or_default ( ) ) ;
191
+
192
+ let _guard = inner_lock_ref. write ( ) . unwrap ( ) ;
193
+
196
194
if !dest_file_path. is_file ( ) {
197
195
return Ok ( ( ) ) ;
198
196
}
@@ -230,7 +228,7 @@ impl KVStore for FilesystemStore {
230
228
// Note that this by itself is still leaky as lock entries will remain when more Readers/Writers are
231
229
// around, but is preferable to doing nothing *or* something overly complex such as
232
230
// implementing yet another RAII structure just for this pupose.
233
- outer_lock. remove ( & lock_key ) ;
231
+ outer_lock. remove ( & dest_file_path ) ;
234
232
}
235
233
236
234
// Garbage collect all lock entries that are not referenced anymore.
0 commit comments