-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Observe state changes in a Raft node #984
Comments
👋 Thanks for opening this issue! Get help or engage by:
|
To monitor the state of a Raft node in OpenRaft, it's recommended to subscribe to updates in the let mut rx = self.raft.metrics();
loop {
if let Some(l) = rx.borrow().current_leader {
return Ok(Some(l));
}
rx.changed().await?;
} This approach allows you to react to changes in the cluster's leadership efficiently. For more detailed information, refer to the specific section of the code in the |
@drmingdrmer I tried this out, looks like the receiver of raft metrics unblocks every few millisecond. Is there any way to subscribe to only leadership change notifications? |
You need to verify whether |
@drmingdrmer Understood! I have an implementation here - tensorlakeai/indexify#221 would appreciate if you can take a look and provide some feedback :) |
Of course. I've added some comments on your pull request. |
HI @drmingdrmer, what's the best way to get notified when the raft node's server state changes? I want the leader node to run some tasks, and stop them when it loses leadership. Is there a good api to get a stream of state changes? I saw that there is a wait method which waits for a specific state, but in that case if I am waiting only for leader I am wondering how I can know that the leadership is lost after a node becomes a leader prior to that.
The text was updated successfully, but these errors were encountered: