Refine watcher count calculation

This commit is contained in:
Ted Yu 2019-07-30 23:04:54 -07:00 committed by Ted Yu
parent ad899665ea
commit 4ce92b05ac
2 changed files with 6 additions and 2 deletions

View File

@ -163,7 +163,6 @@ func (i *indexedWatchers) terminateAll(objectType reflect.Type, done func(*cache
// As we don't need a high precision here, we keep all watchers timeout within a // As we don't need a high precision here, we keep all watchers timeout within a
// second in a bucket, and pop up them once at the timeout. To be more specific, // second in a bucket, and pop up them once at the timeout. To be more specific,
// if you set fire time at X, you can get the bookmark within (X-1,X+1) period. // if you set fire time at X, you can get the bookmark within (X-1,X+1) period.
// This is NOT thread-safe.
type watcherBookmarkTimeBuckets struct { type watcherBookmarkTimeBuckets struct {
lock sync.Mutex lock sync.Mutex
watchersBuckets map[int64][]*cacheWatcher watchersBuckets map[int64][]*cacheWatcher

View File

@ -647,7 +647,12 @@ func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {
cacher.bookmarkWatchers.lock.Lock() cacher.bookmarkWatchers.lock.Lock()
defer cacher.bookmarkWatchers.lock.Unlock() defer cacher.bookmarkWatchers.lock.Unlock()
if len(cacher.bookmarkWatchers.watchersBuckets) != 0 { if len(cacher.bookmarkWatchers.watchersBuckets) != 0 {
t.Errorf("unexpected bookmark watchers %v", len(cacher.bookmarkWatchers.watchersBuckets)) numWatchers := 0
for bucketID, v := range cacher.bookmarkWatchers.watchersBuckets {
numWatchers += len(v)
t.Errorf("there are %v watchers at bucket Id %v with start Id %v", len(v), bucketID, cacher.bookmarkWatchers.startBucketID)
}
t.Errorf("unexpected bookmark watchers %v", numWatchers)
} }
} }