databendlabs / openraft

rust raft with improvements
Apache License 2.0
1.41k stars 159 forks source link

Refactor: Replace async Mutex for `RaftInner.core_state` with standard Mutex and a watch channel #1211

Closed drmingdrmer closed 4 months ago

drmingdrmer commented 4 months ago

Changelog

Refactor: Replace async Mutex for RaftInner.core_state with standard Mutex and a watch channel

In this commit, when joining the RaftCore task, the core_state is first switched from Running to Joining. The thread then blocks while awaiting the completion of the RaftCore task. Any other threads observing the Joining state will wait for the first thread to finish by monitoring a watch channel created by the initial thread.

Refactor: RaftInner::tx_shutdown changed to use std Mutex

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.


This change is Reviewable