Skip to content

Commit

Permalink
Merge pull request #17288 from ishan16696/promoteLeaner/addLogInfo
Browse files Browse the repository at this point in the history
Added a error log when learner is not sync with etcd leader.
  • Loading branch information
ahrtr authored Jan 30, 2024
2 parents 58846bd + 16a5e1d commit ca41186
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ const (

recommendedMaxRequestBytes = 10 * 1024 * 1024

readyPercent = 0.9
// readyPercentThreshold is a threshold used to determine
// whether a learner is ready for a transition into a full voting member or not.
readyPercentThreshold = 0.9

DowngradeEnabledPath = "/downgrade/enabled"
)
Expand Down Expand Up @@ -1491,8 +1493,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))
if err != nil {
if err := s.isLearnerReady(lg, uint64(id)); err != nil {
return err
}

Expand All @@ -1515,7 +1516,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 +1547,16 @@ 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 < readyPercentThreshold {
lg.Error(
"rejecting promote learner: learner is not ready",
zap.Float64("learner-ready-percent", learnerReadyPercent),
zap.Float64("ready-percent-threshold", readyPercentThreshold),
)
return errors.ErrLearnerNotReady
}

Expand Down

0 comments on commit ca41186

Please sign in to comment.