Skip to content

Commit

Permalink
fix: lock mgr may failed to release lock in time (#16611)
Browse files Browse the repository at this point in the history
* fix: lock mgr may failed to release lock in time

relaces `tokio::sync::Notify` with `WatchNotify` which is safe to `nofity_one` before
`Notified` future has been being polled.

* fix: typo, revert default log level
  • Loading branch information
dantengsky authored Oct 16, 2024
1 parent 00a5d8b commit b46195b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/common/base/src/base/watch_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ impl WatchNotify {
pub fn notify_waiters(&self) {
let _ = self.tx.send_replace(true);
}

pub fn notify_one(&self) {
self.notify_waiters()
}
}

#[cfg(test)]
Expand All @@ -68,4 +72,15 @@ mod tests {
let notified = notify.notified();
notified.await;
}

#[tokio::test]
async fn test_notify_one() {
let notify = WatchNotify::new();
// notify_waiters ahead of notified being instantiated and awaited
notify.notify_one();

// this should not await indefinitely
let notified = notify.notified();
notified.await;
}
}
4 changes: 2 additions & 2 deletions src/query/service/src/locks/lock_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::time::Duration;
use std::time::Instant;

use backoff::backoff::Backoff;
use databend_common_base::base::tokio::sync::Notify;
use databend_common_base::base::tokio::time::sleep;
use databend_common_base::base::WatchNotify;
use databend_common_base::runtime::GlobalIORuntime;
use databend_common_base::runtime::TrySpawn;
use databend_common_catalog::catalog::Catalog;
Expand All @@ -41,7 +41,7 @@ use crate::sessions::SessionManager;
#[derive(Default)]
pub struct LockHolder {
shutdown_flag: AtomicBool,
shutdown_notify: Notify,
shutdown_notify: WatchNotify,
}

impl LockHolder {
Expand Down

0 comments on commit b46195b

Please sign in to comment.