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
04e50ae1
Commit
04e50ae1
authored
Oct 26, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce lock contention in watchCache
parent
f046acdf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
8 deletions
+5
-8
watch_cache.go
pkg/storage/watch_cache.go
+5
-8
No files found.
pkg/storage/watch_cache.go
View file @
04e50ae1
...
...
@@ -105,6 +105,7 @@ type watchCache struct {
// store will effectively support LIST operation from the "end of cache
// history" i.e. from the moment just after the newest cached watched event.
// It is necessary to effectively allow clients to start watching at now.
// NOTE: We assume that <store> is thread-safe.
store
cache
.
Store
// ResourceVersion up to which the watchCache is propagated.
...
...
@@ -202,6 +203,10 @@ func (w *watchCache) processEvent(event watch.Event, resourceVersion uint64, upd
}
elem
:=
&
storeElement
{
Key
:
key
,
Object
:
event
.
Object
}
// TODO: We should consider moving this lock below after the watchCacheEvent
// is created. In such situation, the only problematic scenario is Replace(
// happening after getting object from store and before acquiring a lock.
// Maybe introduce another lock for this purpose.
w
.
Lock
()
defer
w
.
Unlock
()
previous
,
exists
,
err
:=
w
.
store
.
Get
(
elem
)
...
...
@@ -240,8 +245,6 @@ func (w *watchCache) updateCache(resourceVersion uint64, event *watchCacheEvent)
// List returns list of pointers to <storeElement> objects.
func
(
w
*
watchCache
)
List
()
[]
interface
{}
{
w
.
RLock
()
defer
w
.
RUnlock
()
return
w
.
store
.
List
()
}
...
...
@@ -300,8 +303,6 @@ func (w *watchCache) WaitUntilFreshAndGet(resourceVersion uint64, key string, tr
}
func
(
w
*
watchCache
)
ListKeys
()
[]
string
{
w
.
RLock
()
defer
w
.
RUnlock
()
return
w
.
store
.
ListKeys
()
}
...
...
@@ -317,15 +318,11 @@ func (w *watchCache) Get(obj interface{}) (interface{}, bool, error) {
return
nil
,
false
,
fmt
.
Errorf
(
"couldn't compute key: %v"
,
err
)
}
w
.
RLock
()
defer
w
.
RUnlock
()
return
w
.
store
.
Get
(
&
storeElement
{
Key
:
key
,
Object
:
object
})
}
// GetByKey returns pointer to <storeElement>.
func
(
w
*
watchCache
)
GetByKey
(
key
string
)
(
interface
{},
bool
,
error
)
{
w
.
RLock
()
defer
w
.
RUnlock
()
return
w
.
store
.
GetByKey
(
key
)
}
...
...
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