From 2fe1729c24652a1281f7fa1be5b244c65ccfe8b8 Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Tue, 30 Jul 2019 23:04:54 -0700 Subject: [PATCH] Refine watcher count calculation Kubernetes-commit: 4ce92b05acf7fec89c8723ba1779bf9e2baf55f4 --- pkg/storage/cacher/cacher.go | 1 - pkg/storage/cacher/cacher_whitebox_test.go | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/storage/cacher/cacher.go b/pkg/storage/cacher/cacher.go index e366906af..925ef0d2c 100644 --- a/pkg/storage/cacher/cacher.go +++ b/pkg/storage/cacher/cacher.go @@ -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 // 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. -// This is NOT thread-safe. type watcherBookmarkTimeBuckets struct { lock sync.Mutex watchersBuckets map[int64][]*cacheWatcher diff --git a/pkg/storage/cacher/cacher_whitebox_test.go b/pkg/storage/cacher/cacher_whitebox_test.go index ff8075840..fa2c92192 100644 --- a/pkg/storage/cacher/cacher_whitebox_test.go +++ b/pkg/storage/cacher/cacher_whitebox_test.go @@ -647,7 +647,12 @@ func TestCacherNoLeakWithMultipleWatchers(t *testing.T) { cacher.bookmarkWatchers.lock.Lock() defer cacher.bookmarkWatchers.lock.Unlock() 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) } }