Skip to content

Commit 0b3c07a

Browse files
tedyuyutedz
authored andcommitted
Rename cacheWatcher#stop
1 parent bb496d6 commit 0b3c07a

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ func (c *Cacher) startDispatchingBookmarkEvents() {
856856
// as we don't delete watcher from bookmarkWatchers when it is stopped.
857857
for _, watchers := range c.bookmarkWatchers.popExpiredWatchers() {
858858
for _, watcher := range watchers {
859-
// watcher.stop() is protected by c.Lock()
859+
// c.Lock() is held here.
860+
// watcher.stopThreadUnsafe() is protected by c.Lock()
860861
if watcher.stopped {
861862
continue
862863
}
@@ -926,7 +927,7 @@ func (c *Cacher) finishDispatching() {
926927
defer c.Unlock()
927928
c.dispatching = false
928929
for _, watcher := range c.watchersToStop {
929-
watcher.stop()
930+
watcher.stopThreadUnsafe()
930931
}
931932
c.watchersToStop = c.watchersToStop[:0]
932933
}
@@ -941,7 +942,7 @@ func (c *Cacher) stopWatcherThreadUnsafe(watcher *cacheWatcher) {
941942
if c.dispatching {
942943
c.watchersToStop = append(c.watchersToStop, watcher)
943944
} else {
944-
watcher.stop()
945+
watcher.stopThreadUnsafe()
945946
}
946947
}
947948

@@ -971,7 +972,7 @@ func forgetWatcher(c *Cacher, index int, triggerValue string, triggerSupported b
971972
defer c.Unlock()
972973

973974
// It's possible that the watcher is already not in the structure (e.g. in case of
974-
// simultaneous Stop() and terminateAllWatchers(), but it is safe to call stop()
975+
// simultaneous Stop() and terminateAllWatchers(), but it is safe to call stopThreadUnsafe()
975976
// on a watcher multiple times.
976977
c.watchers.deleteWatcher(index, triggerValue, triggerSupported, c.stopWatcherThreadUnsafe)
977978
}
@@ -1073,8 +1074,8 @@ func (c *errWatcher) Stop() {
10731074
}
10741075

10751076
// cacheWatcher implements watch.Interface
1077+
// this is not thread-safe
10761078
type cacheWatcher struct {
1077-
sync.Mutex
10781079
input chan *watchCacheEvent
10791080
result chan watch.Event
10801081
done chan struct{}
@@ -1115,12 +1116,8 @@ func (c *cacheWatcher) Stop() {
11151116
c.forget()
11161117
}
11171118

1118-
// TODO(#73958)
1119-
// stop() is protected by Cacher.Lock(), rename it to
1120-
// stopThreadUnsafe and remove the sync.Mutex.
1121-
func (c *cacheWatcher) stop() {
1122-
c.Lock()
1123-
defer c.Unlock()
1119+
// we rely on the fact that stopThredUnsafe is actually protected by Cacher.Lock()
1120+
func (c *cacheWatcher) stopThreadUnsafe() {
11241121
if !c.stopped {
11251122
c.stopped = true
11261123
close(c.done)

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestCacheWatcherCleanupNotBlockedByResult(t *testing.T) {
6363
// forget() has to stop the watcher, as only stopping the watcher
6464
// triggers stopping the process() goroutine which we are in the
6565
// end waiting for in this test.
66-
w.stop()
66+
w.stopThreadUnsafe()
6767
}
6868
initEvents := []*watchCacheEvent{
6969
{Object: &v1.Pod{}},
@@ -472,7 +472,7 @@ func TestCacheWatcherStoppedInAnotherGoroutine(t *testing.T) {
472472
done := make(chan struct{})
473473
filter := func(string, labels.Set, fields.Set) bool { return true }
474474
forget := func() {
475-
w.stop()
475+
w.stopThreadUnsafe()
476476
done <- struct{}{}
477477
}
478478

0 commit comments

Comments
 (0)