Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Revert "Send watch bookmarks every minute"
Browse files Browse the repository at this point in the history
Kubernetes-commit: 1cb98ed2376b1f7777ca3d7bfac98cbb5f8b9ce3
  • Loading branch information
wojtek-t authored and k8s-publishing-bot committed Apr 27, 2020
1 parent eb05225 commit 7686f35
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions pkg/storage/cacher/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ func newTimeBucketWatchers(clock clock.Clock) *watcherBookmarkTimeBuckets {
// adds a watcher to the bucket, if the deadline is before the start, it will be
// added to the first one.
func (t *watcherBookmarkTimeBuckets) addWatcher(w *cacheWatcher) bool {
nextTime := w.nextBookmarkTime(t.clock.Now())
nextTime, ok := w.nextBookmarkTime(t.clock.Now())
if !ok {
return false
}
bucketID := nextTime.Unix()
t.lock.Lock()
defer t.lock.Unlock()
Expand Down Expand Up @@ -1216,26 +1219,13 @@ func (c *cacheWatcher) add(event *watchCacheEvent, timer *time.Timer) bool {
}
}

// bookmarkHeartbeatFrequency defines how frequently bookmarks should be
// under regular conditions.
const bookmarkHeartbeatFrequency = time.Minute

func (c *cacheWatcher) nextBookmarkTime(now time.Time) time.Time {
// We try to send bookmarks:
// (a) roughly every minute
// (b) right before the watcher timeout - for now we simply set it 2s before
// the deadline
// The former gives us periodicity if the watch breaks due to unexpected
// conditions, the later ensures that on timeout the watcher is as close to
// now as possible - this covers 99% of cases.
heartbeatTime := now.Add(bookmarkHeartbeatFrequency)
func (c *cacheWatcher) nextBookmarkTime(now time.Time) (time.Time, bool) {
// For now we return 2s before deadline (and maybe +infinity is now already passed this time)
// but it gives us extensibility for the future(false when deadline is not set).
if c.deadline.IsZero() {
return heartbeatTime
}
if pretimeoutTime := c.deadline.Add(-2 * time.Second); pretimeoutTime.Before(heartbeatTime) {
return pretimeoutTime
return c.deadline, false
}
return heartbeatTime
return c.deadline.Add(-2 * time.Second), true
}

func getEventObject(object runtime.Object) runtime.Object {
Expand Down

0 comments on commit 7686f35

Please sign in to comment.