Skip to content

Commit

Permalink
etcdserver: return membership.ErrIDNotFound when the memberID not found
Browse files Browse the repository at this point in the history
Backport #15095 to 3.4.

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 <[email protected]>
  • Loading branch information
ahrtr committed Jan 13, 2023
1 parent a577940 commit 82f315c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,10 @@ func (s *EtcdServer) isLearnerReady(id uint64) error {
return ErrNotLeader
}

if err := s.waitAppliedIndex(); err != nil {
return err
}

var learnerMatch uint64
isFound := false
leaderID := rs.ID
Expand All @@ -1817,12 +1821,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 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 ErrLearnerNotReady
}

return nil
Expand Down

0 comments on commit 82f315c

Please sign in to comment.