From 2398d57065e6cf722914eb2fe9c9f4c2e76ff76b Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Fri, 13 Jan 2023 14:34:56 +0800 Subject: [PATCH] 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 --- server/etcdserver/server.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index 306f30cf6c9e..48f656f91771 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -1491,6 +1491,10 @@ func (s *EtcdServer) isLearnerReady(id uint64) error { return errors.ErrNotLeader } + if err := s.waitAppliedIndex(); err != nil { + return err + } + var learnerMatch uint64 isFound := false leaderID := rs.ID @@ -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