Skip to content

lease: modify log info #7701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it print a lot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible. But similar to the 'clock offset' warning log in tso, it is indeed a worthwhile log to output

}
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