Merge pull request #15095 from ahrtr/promote_non_exist_id_20230113

etcdserver: return `membership.ErrIDNotFound` when the memberID not found
This commit is contained in:
Benjamin Wang 2023-01-17 07:12:29 +08:00 committed by GitHub
commit 81b359262e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.
// These two conditions will be checked before toApply phase later.
func (s *EtcdServer) isLearnerReady(id uint64) error {
if err := s.waitAppliedIndex(); err != nil {
return err
}
rs := s.raftStatus()
// leader's raftStatus.Progress is not nil
@ -1503,12 +1507,16 @@ func (s *EtcdServer) isLearnerReady(id uint64) error {
}
}
if isFound {
leaderMatch := rs.Progress[leaderID].Match
// the learner's Match not caught up with leader yet
if float64(learnerMatch) < float64(leaderMatch)*readyPercent {
return errors.ErrLearnerNotReady
}
// We should return an error in API directly, to avoid the request
// being unnecessarily delivered to raft.
if !isFound {
return membership.ErrIDNotFound
}
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