diff --git a/etcdserver/server.go b/etcdserver/server.go index 808f8c9df4d0..aedd522cf702 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -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 @@ -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