etcdserver: export method EtcdServer.leaderChangedNotify (#12378)

This commit is contained in:
Yanhao Mo
2020-10-21 16:21:08 +08:00
parent e897daaebc
commit 6d82778a4e
5 changed files with 25 additions and 13 deletions

View File

@@ -185,6 +185,15 @@ type Server interface {
ClusterVersion() *semver.Version
Cluster() api.Cluster
Alarms() []*pb.AlarmMember
// LeaderChangedNotify returns a channel for application level code to be notified
// when etcd leader changes, this function is intend to be used only in application
// which embed etcd.
// Caution:
// 1. the returned channel is being closed when the leadership changes.
// 2. so the new channel needs to be obtained for each raft term.
// 3. user can loose some consecutive channel changes using this API.
LeaderChangedNotify() <-chan struct{}
}
// EtcdServer is the production implementation of the Server interface
@@ -1743,7 +1752,7 @@ func (s *EtcdServer) getLead() uint64 {
return atomic.LoadUint64(&s.lead)
}
func (s *EtcdServer) leaderChangedNotify() <-chan struct{} {
func (s *EtcdServer) LeaderChangedNotify() <-chan struct{} {
s.leaderChangedMu.RLock()
defer s.leaderChangedMu.RUnlock()
return s.leaderChanged