Skip to content

Commit

Permalink
Refactor: RaftInner::tx_shutdown changed to use std Mutex
Browse files Browse the repository at this point in the history
`RaftInner::tx_shutdown` has been changed to use a standard
(synchronous) Mutex instead of an asynchronous one. This change is made
because `tx_shutdown` does not span across `.await` points, making the
asynchronous capabilities unnecessary.
  • Loading branch information
drmingdrmer committed Jul 30, 2024
1 parent 28c934c commit 69ab424
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions openraft/src/raft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ where C: RaftTypeConfig
rx_metrics,
rx_data_metrics,
rx_server_metrics,
tx_shutdown: Mutex::new(Some(tx_shutdown)),
tx_shutdown: std::sync::Mutex::new(Some(tx_shutdown)),
core_state: Mutex::new(CoreState::Running(core_handle)),

snapshot: Mutex::new(None),
Expand Down Expand Up @@ -919,7 +919,7 @@ where C: RaftTypeConfig
///
/// It sends a shutdown signal and waits until `RaftCore` returns.
pub async fn shutdown(&self) -> Result<(), JoinErrorOf<C>> {
if let Some(tx) = self.inner.tx_shutdown.lock().await.take() {
if let Some(tx) = self.inner.tx_shutdown.lock().unwrap().take() {
// A failure to send means the RaftCore is already shutdown. Continue to check the task
// return value.
let send_res = tx.send(());
Expand Down
4 changes: 1 addition & 3 deletions openraft/src/raft/raft_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ where C: RaftTypeConfig
pub(in crate::raft) rx_data_metrics: WatchReceiverOf<C, RaftDataMetrics<C>>,
pub(in crate::raft) rx_server_metrics: WatchReceiverOf<C, RaftServerMetrics<C>>,

// TODO(xp): it does not need to be a async mutex.
#[allow(clippy::type_complexity)]
pub(in crate::raft) tx_shutdown: Mutex<Option<OneshotSenderOf<C, ()>>>,
pub(in crate::raft) tx_shutdown: std::sync::Mutex<Option<OneshotSenderOf<C, ()>>>,
pub(in crate::raft) core_state: Mutex<CoreState<C>>,

/// The ongoing snapshot transmission.
Expand Down

0 comments on commit 69ab424

Please sign in to comment.