Provide a listener API for tracking cluster member state
See original GitHub issueUse case and problem
We make a system that uses SOFAJRaft for leader election and we also want to use it for cluster member management. The basic idea that we want to consider our cluster member “live” for our systems as long as it’s “live” for current leader of SOFAJRaft cluster.
As for now SOFAJRaft provides a Node#listAlivePeers()
API method that almost sufficient for our task. The missing piece is there is no simple way to track state change for a member. We want to know when a Peer changes state from “live” to “dead” and vice versa.
So as for now we have to periodically poll Node#listAlivePeers()
. That works but such polling seems redundant because NodeImpl#stepDownTimer
already does all necessary work (in Node#checkDeadNodes0(...)
).
Feature suggestion
Please add an API method to register a listener that will be executed when Peer state changes.
We understand that right now “live/dead” is a computed property so such API method will require to store “last reported state value” for listeners. However overhead of this seems to be quite low.
Sample draft of how the listener interface might look like
/**
* Invoked when current node considers that state of a follower have changed.
*
* Invoked only when current node is the leader.
*
* @param peerId peer whose status have changed
* @param alive true means that specified peer now considered alive
*/
void onPeerStateChange(final PeerId peerId, final boolean alive);
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
I think this is an useful feature, we put it into next milestone.
@alexei-osipov Thanks for your reply. I got it. We can extend the
ReplicatorStateListener
to support this feature in next release.