etcdserver: return membership.ErrIDNotFound when the memberID not found
When promoting a learner, we need to wait until the leader's applied ID catches up to the commitId. Afterwards, check whether the learner ID exist or not, and return `membership.ErrIDNotFound` directly in the API if the member ID not found, to avoid the request being unnecessarily delivered to raft. Signed-off-by: Benjamin Wang <wachao@vmware.com>dependabot/go_modules/go.uber.org/atomic-1.10.0
parent
677e5281e0
commit
8ed20e85d2
|
@ -1484,6 +1484,10 @@ func (s *EtcdServer) mayPromoteMember(id types.ID) error {
|
||||||
// Note: it will return nil if member is not found in cluster or if member is not learner.
|
// Note: it will return nil if member is not found in cluster or if member is not learner.
|
||||||
// These two conditions will be checked before toApply phase later.
|
// These two conditions will be checked before toApply phase later.
|
||||||
func (s *EtcdServer) isLearnerReady(id uint64) error {
|
func (s *EtcdServer) isLearnerReady(id uint64) error {
|
||||||
|
if err := s.waitAppliedIndex(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
rs := s.raftStatus()
|
rs := s.raftStatus()
|
||||||
|
|
||||||
// leader's raftStatus.Progress is not nil
|
// leader's raftStatus.Progress is not nil
|
||||||
|
@ -1503,12 +1507,16 @@ func (s *EtcdServer) isLearnerReady(id uint64) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isFound {
|
// We should return an error in API directly, to avoid the request
|
||||||
leaderMatch := rs.Progress[leaderID].Match
|
// being unnecessarily delivered to raft.
|
||||||
// the learner's Match not caught up with leader yet
|
if !isFound {
|
||||||
if float64(learnerMatch) < float64(leaderMatch)*readyPercent {
|
return membership.ErrIDNotFound
|
||||||
return errors.ErrLearnerNotReady
|
}
|
||||||
}
|
|
||||||
|
leaderMatch := rs.Progress[leaderID].Match
|
||||||
|
// the learner's Match not caught up with leader yet
|
||||||
|
if float64(learnerMatch) < float64(leaderMatch)*readyPercent {
|
||||||
|
return errors.ErrLearnerNotReady
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue