Skip to content

Commit 1a3631c

Browse files
committed
f: simplify cleanup
1 parent 217a027 commit 1a3631c

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

fuzz/src/fs_store.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ async fn do_test_internal<Out: test_logger::Output>(data: &[u8], _out: Out) {
5454
let secondary_namespace = "secondary";
5555
let key = "key";
5656

57-
// Remove the key in case something was left over from a previous run.
58-
_ = KVStoreSync::remove(fs_store, primary_namespace, secondary_namespace, key, false);
59-
6057
let mut next_data_value = 0u64;
6158
let mut get_next_data_value = || {
6259
let data_value = next_data_value.to_be_bytes().to_vec();

lightning-persister/src/fs_store.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -242,35 +242,27 @@ impl FilesystemStoreInner {
242242
})
243243
};
244244

245-
self.clean_locks(&inner_lock_ref, dest_file_path, &async_state);
245+
self.clean_locks(&inner_lock_ref, dest_file_path);
246246

247247
res
248248
}
249249

250250
fn execute_locked_read<F: FnOnce() -> Result<(), lightning::io::Error>>(
251251
&self, inner_lock_ref: Arc<RwLock<AsyncState>>, dest_file_path: PathBuf, callback: F,
252252
) -> Result<(), lightning::io::Error> {
253-
let async_state = inner_lock_ref.read().unwrap();
254-
255-
// If the version is not stale, we execute the callback. Otherwise we can and must skip writing.
253+
let _async_state = inner_lock_ref.read().unwrap();
256254
let res = callback();
257-
258-
self.clean_locks(&inner_lock_ref, dest_file_path, &async_state);
259-
255+
self.clean_locks(&inner_lock_ref, dest_file_path);
260256
res
261257
}
262258

263-
fn clean_locks(
264-
&self, inner_lock_ref: &Arc<RwLock<AsyncState>>, dest_file_path: PathBuf,
265-
async_state: &AsyncState,
266-
) {
267-
let more_writes_pending = async_state.latest_written_version < async_state.latest_version;
268-
269-
// If there are no more writes pending and no arcs in use elsewhere, we can remove the map entry to prevent
270-
// leaking memory. The two arcs are the one in the map and the one held here in inner_lock_ref. The outer lock
271-
// is obtained first, to avoid a new arc being cloned after we've already counted.
259+
fn clean_locks(&self, inner_lock_ref: &Arc<RwLock<AsyncState>>, dest_file_path: PathBuf) {
260+
// If there no arcs in use elsewhere, this means that there are no in-flight writes. We can remove the map entry
261+
// to prevent leaking memory. The two arcs that are expected are the one in the map and the one held here in
262+
// inner_lock_ref. The outer lock is obtained first, to avoid a new arc being cloned after we've already
263+
// counted.
272264
let mut outer_lock = self.locks.lock().unwrap();
273-
if !more_writes_pending && Arc::strong_count(&inner_lock_ref) == 2 {
265+
if Arc::strong_count(&inner_lock_ref) == 2 {
274266
outer_lock.remove(&dest_file_path);
275267
}
276268
}

0 commit comments

Comments
 (0)