Skip to content

Commit

Permalink
Added a error log when learner is not sync with etcd leader.
Browse files Browse the repository at this point in the history
Signed-off-by: ishan16696 <[email protected]>
  • Loading branch information
ishan16696 committed Jan 28, 2024
1 parent 15f95ec commit b1213dd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ func (s *EtcdServer) promoteMember(ctx context.Context, id uint64) ([]*membershi

func (s *EtcdServer) mayPromoteMember(id types.ID) error {
lg := s.Logger()
err := s.isLearnerReady(uint64(id))
err := s.isLearnerReady(lg, uint64(id))
if err != nil {
return err
}
Expand All @@ -1515,7 +1515,7 @@ func (s *EtcdServer) mayPromoteMember(id types.ID) error {
// check whether the learner catches up with leader or not.
// 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 {
func (s *EtcdServer) isLearnerReady(lg *zap.Logger, id uint64) error {
if err := s.waitAppliedIndex(); err != nil {
return err
}
Expand Down Expand Up @@ -1546,8 +1546,14 @@ func (s *EtcdServer) isLearnerReady(id uint64) error {
}

leaderMatch := rs.Progress[leaderID].Match
learnerReadyPercent := float64(learnerMatch) / float64(leaderMatch)

// the learner's Match not caught up with leader yet
if float64(learnerMatch) < float64(leaderMatch)*readyPercent {
if learnerReadyPercent < readyPercent {
lg.Error(
"rejecting promote learner: learner is not ready",
zap.Float64("learner-ready-percent", learnerReadyPercent),
)
return errors.ErrLearnerNotReady
}

Expand Down

0 comments on commit b1213dd

Please sign in to comment.