Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
fix: status may change when releasing lock
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlou1554 committed Apr 29, 2024
1 parent 87c0d6a commit 7e174ec
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions storage-node/src/cache/data_store_cache/memdisk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,28 @@ impl<R: DataStoreReplacer<MemDiskStoreReplacerKey, MemDiskStoreReplacerValue>> D
// If in_progress of remote_location thread fails, it will clean the data from this hash map.
let mut existed = false;
loop {
let (status, size, notify);
if let Some(((status_ref, size_ref), notify_ref)) =
self.status_of_keys.read().await.get(&remote_location)
{
let status_of_keys = self.status_of_keys.read().await;
if let Some(((status, size), notify_ref)) = status_of_keys.get(&remote_location) {
let notify;
existed = true;
status = status_ref.clone();
size = *size_ref;
notify = notify_ref.clone();
match status {
Status::Incompleted => {
notify = notify_ref.clone();
*notify_ref.1.lock().await += 1;
// The Notified future is guaranteed to receive wakeups from notify_waiters()
// as soon as it has been created, even if it has not yet been polled.
let notified = notify.0.notified();
drop(status_of_keys);
notified.await;
}
Status::Completed => {
return Ok(*size);
}
}
} else {
// FIXME: status_of_keys lock should be released after break
break;
}
match status {
Status::Incompleted => {
// TODO(lanlou): Make these 2 code atomic!!
*notify.1.lock().await += 1;
notify.0.notified().await;
}
Status::Completed => {
return Ok(size);
}
}
}
if existed {
// Another in progress of remote_location thread fails
Expand Down

0 comments on commit 7e174ec

Please sign in to comment.