Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b6a775ca
Commit
b6a775ca
authored
Nov 06, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Terminate watcher if it is full
parent
1e438be0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
8 deletions
+45
-8
cacher.go
pkg/storage/cacher.go
+19
-8
cacher_test.go
pkg/storage/cacher_test.go
+26
-0
No files found.
pkg/storage/cacher.go
View file @
b6a775ca
...
...
@@ -22,6 +22,7 @@ import (
"strconv"
"strings"
"sync"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/cache"
...
...
@@ -352,10 +353,12 @@ func (c *Cacher) terminateAllWatchers() {
}
}
func
forgetWatcher
(
c
*
Cacher
,
index
int
)
func
()
{
return
func
()
{
c
.
Lock
()
defer
c
.
Unlock
()
func
forgetWatcher
(
c
*
Cacher
,
index
int
)
func
(
bool
)
{
return
func
(
lock
bool
)
{
if
lock
{
c
.
Lock
()
defer
c
.
Unlock
()
}
// It's possible that the watcher is already not in the map (e.g. in case of
// simulaneous Stop() and terminateAllWatchers(), but it doesn't break anything.
delete
(
c
.
watchers
,
index
)
...
...
@@ -428,10 +431,10 @@ type cacheWatcher struct {
result
chan
watch
.
Event
filter
FilterFunc
stopped
bool
forget
func
()
forget
func
(
bool
)
}
func
newCacheWatcher
(
initEvents
[]
watchCacheEvent
,
filter
FilterFunc
,
forget
func
())
*
cacheWatcher
{
func
newCacheWatcher
(
initEvents
[]
watchCacheEvent
,
filter
FilterFunc
,
forget
func
(
bool
))
*
cacheWatcher
{
watcher
:=
&
cacheWatcher
{
input
:
make
(
chan
watchCacheEvent
,
10
),
result
:
make
(
chan
watch
.
Event
,
10
),
...
...
@@ -450,7 +453,7 @@ func (c *cacheWatcher) ResultChan() <-chan watch.Event {
// Implements watch.Interface.
func
(
c
*
cacheWatcher
)
Stop
()
{
c
.
forget
()
c
.
forget
(
true
)
c
.
stop
()
}
...
...
@@ -464,7 +467,15 @@ func (c *cacheWatcher) stop() {
}
func
(
c
*
cacheWatcher
)
add
(
event
watchCacheEvent
)
{
c
.
input
<-
event
select
{
case
c
.
input
<-
event
:
case
<-
time
.
After
(
time
.
Second
)
:
// This means that we couldn't send event to that watcher.
// Since we don't want to blockin on it infinitely,
// we simply terminate it.
c
.
forget
(
false
)
c
.
stop
()
}
}
func
(
c
*
cacheWatcher
)
sendWatchCacheEvent
(
event
watchCacheEvent
)
{
...
...
pkg/storage/cacher_test.go
View file @
b6a775ca
...
...
@@ -223,6 +223,32 @@ func TestWatch(t *testing.T) {
verifyWatchEvent
(
t
,
nowWatcher
,
watch
.
Modified
,
podFooBis
)
}
func
TestWatcherTimeout
(
t
*
testing
.
T
)
{
server
,
etcdStorage
:=
newEtcdTestStorage
(
t
,
testapi
.
Default
.
Codec
(),
etcdtest
.
PathPrefix
())
defer
server
.
Terminate
(
t
)
cacher
:=
newTestCacher
(
etcdStorage
)
// Create a watcher that will not be reading any result.
watcher
,
err
:=
cacher
.
WatchList
(
context
.
TODO
(),
"pods/ns"
,
1
,
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
defer
watcher
.
Stop
()
// Create a second watcher that will be reading result.
readingWatcher
,
err
:=
cacher
.
WatchList
(
context
.
TODO
(),
"pods/ns"
,
1
,
storage
.
Everything
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
defer
readingWatcher
.
Stop
()
for
i
:=
1
;
i
<=
22
;
i
++
{
pod
:=
makeTestPod
(
strconv
.
Itoa
(
i
))
_
=
updatePod
(
t
,
etcdStorage
,
pod
,
nil
)
verifyWatchEvent
(
t
,
readingWatcher
,
watch
.
Added
,
pod
)
}
}
func
TestFiltering
(
t
*
testing
.
T
)
{
server
,
etcdStorage
:=
newEtcdTestStorage
(
t
,
testapi
.
Default
.
Codec
(),
etcdtest
.
PathPrefix
())
defer
server
.
Terminate
(
t
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment