Skip to content

Commit

Permalink
lease: modify log info (#7701)
Browse files Browse the repository at this point in the history
ref #7700

Signed-off-by: Cabinfever_B <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
CabinfeverB and ti-chi-bot[bot] authored Jan 24, 2024
1 parent 9c1035d commit 1a38582
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/election/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (l *lease) KeepAlive(ctx context.Context) {
// https://pkg.go.dev/time@master#Timer.Reset
timer.Reset(l.leaseTimeout)
case <-timer.C:
log.Info("lease timeout", zap.Time("expire", l.expireTime.Load().(time.Time)), zap.String("purpose", l.Purpose))
log.Info("keep alive lease too slow", zap.Duration("timeout-duration", l.leaseTimeout), zap.Time("actual-expire", l.expireTime.Load().(time.Time)), zap.String("purpose", l.Purpose))
return
case <-ctx.Done():
return
Expand All @@ -154,11 +154,14 @@ func (l *lease) keepAliveWorker(ctx context.Context, interval time.Duration) <-c

log.Info("start lease keep alive worker", zap.Duration("interval", interval), zap.String("purpose", l.Purpose))
defer log.Info("stop lease keep alive worker", zap.String("purpose", l.Purpose))

lastTime := time.Now()
for {
go func() {
start := time.Now()
if start.Sub(lastTime) > interval*2 {
log.Warn("the interval between keeping alive lease is too long", zap.Time("last-time", lastTime))
}
go func(start time.Time) {
defer logutil.LogPanic()
start := time.Now()
ctx1, cancel := context.WithTimeout(ctx, l.leaseTimeout)
defer cancel()
var leaseID clientv3.LeaseID
Expand All @@ -180,12 +183,13 @@ func (l *lease) keepAliveWorker(ctx context.Context, interval time.Duration) <-c
} else {
log.Error("keep alive response ttl is zero", zap.String("purpose", l.Purpose))
}
}()
}(start)

select {
case <-ctx.Done():
return
case <-ticker.C:
lastTime = start
}
}
}()
Expand Down

0 comments on commit 1a38582

Please sign in to comment.