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
8fcbcafc
Commit
8fcbcafc
authored
Sep 02, 2018
by
Michelle Au
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use rwlock for caches
parent
ce2dfac2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
24 deletions
+26
-24
scheduler_assume_cache.go
...troller/volume/persistentvolume/scheduler_assume_cache.go
+14
-13
scheduler_binder_cache.go
...troller/volume/persistentvolume/scheduler_binder_cache.go
+12
-11
No files found.
pkg/controller/volume/persistentvolume/scheduler_assume_cache.go
View file @
8fcbcafc
...
@@ -83,7 +83,8 @@ func (e *errObjectName) Error() string {
...
@@ -83,7 +83,8 @@ func (e *errObjectName) Error() string {
// Restore() sets the latest object pointer back to the informer object.
// Restore() sets the latest object pointer back to the informer object.
// Get/List() always returns the latest object pointer.
// Get/List() always returns the latest object pointer.
type
assumeCache
struct
{
type
assumeCache
struct
{
mutex
sync
.
Mutex
// Synchronizes updates to store
rwMutex
sync
.
RWMutex
// describes the object stored
// describes the object stored
description
string
description
string
...
@@ -155,8 +156,8 @@ func (c *assumeCache) add(obj interface{}) {
...
@@ -155,8 +156,8 @@ func (c *assumeCache) add(obj interface{}) {
return
return
}
}
c
.
m
utex
.
Lock
()
c
.
rwM
utex
.
Lock
()
defer
c
.
m
utex
.
Unlock
()
defer
c
.
rwM
utex
.
Unlock
()
if
objInfo
,
_
:=
c
.
getObjInfo
(
name
);
objInfo
!=
nil
{
if
objInfo
,
_
:=
c
.
getObjInfo
(
name
);
objInfo
!=
nil
{
newVersion
,
err
:=
c
.
getObjVersion
(
name
,
obj
)
newVersion
,
err
:=
c
.
getObjVersion
(
name
,
obj
)
...
@@ -199,8 +200,8 @@ func (c *assumeCache) delete(obj interface{}) {
...
@@ -199,8 +200,8 @@ func (c *assumeCache) delete(obj interface{}) {
return
return
}
}
c
.
m
utex
.
Lock
()
c
.
rwM
utex
.
Lock
()
defer
c
.
m
utex
.
Unlock
()
defer
c
.
rwM
utex
.
Unlock
()
objInfo
:=
&
objInfo
{
name
:
name
}
objInfo
:=
&
objInfo
{
name
:
name
}
err
=
c
.
store
.
Delete
(
objInfo
)
err
=
c
.
store
.
Delete
(
objInfo
)
...
@@ -239,8 +240,8 @@ func (c *assumeCache) getObjInfo(name string) (*objInfo, error) {
...
@@ -239,8 +240,8 @@ func (c *assumeCache) getObjInfo(name string) (*objInfo, error) {
}
}
func
(
c
*
assumeCache
)
Get
(
objName
string
)
(
interface
{},
error
)
{
func
(
c
*
assumeCache
)
Get
(
objName
string
)
(
interface
{},
error
)
{
c
.
mutex
.
Lock
()
c
.
rwMutex
.
R
Lock
()
defer
c
.
mutex
.
Unlock
()
defer
c
.
rwMutex
.
R
Unlock
()
objInfo
,
err
:=
c
.
getObjInfo
(
objName
)
objInfo
,
err
:=
c
.
getObjInfo
(
objName
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -250,8 +251,8 @@ func (c *assumeCache) Get(objName string) (interface{}, error) {
...
@@ -250,8 +251,8 @@ func (c *assumeCache) Get(objName string) (interface{}, error) {
}
}
func
(
c
*
assumeCache
)
List
(
indexObj
interface
{})
[]
interface
{}
{
func
(
c
*
assumeCache
)
List
(
indexObj
interface
{})
[]
interface
{}
{
c
.
mutex
.
Lock
()
c
.
rwMutex
.
R
Lock
()
defer
c
.
mutex
.
Unlock
()
defer
c
.
rwMutex
.
R
Unlock
()
allObjs
:=
[]
interface
{}{}
allObjs
:=
[]
interface
{}{}
objs
,
err
:=
c
.
store
.
Index
(
c
.
indexName
,
&
objInfo
{
latestObj
:
indexObj
})
objs
,
err
:=
c
.
store
.
Index
(
c
.
indexName
,
&
objInfo
{
latestObj
:
indexObj
})
...
@@ -277,8 +278,8 @@ func (c *assumeCache) Assume(obj interface{}) error {
...
@@ -277,8 +278,8 @@ func (c *assumeCache) Assume(obj interface{}) error {
return
&
errObjectName
{
err
}
return
&
errObjectName
{
err
}
}
}
c
.
m
utex
.
Lock
()
c
.
rwM
utex
.
Lock
()
defer
c
.
m
utex
.
Unlock
()
defer
c
.
rwM
utex
.
Unlock
()
objInfo
,
err
:=
c
.
getObjInfo
(
name
)
objInfo
,
err
:=
c
.
getObjInfo
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -306,8 +307,8 @@ func (c *assumeCache) Assume(obj interface{}) error {
...
@@ -306,8 +307,8 @@ func (c *assumeCache) Assume(obj interface{}) error {
}
}
func
(
c
*
assumeCache
)
Restore
(
objName
string
)
{
func
(
c
*
assumeCache
)
Restore
(
objName
string
)
{
c
.
m
utex
.
Lock
()
c
.
rwM
utex
.
Lock
()
defer
c
.
m
utex
.
Unlock
()
defer
c
.
rwM
utex
.
Unlock
()
objInfo
,
err
:=
c
.
getObjInfo
(
objName
)
objInfo
,
err
:=
c
.
getObjInfo
(
objName
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/controller/volume/persistentvolume/scheduler_binder_cache.go
View file @
8fcbcafc
...
@@ -50,7 +50,8 @@ type PodBindingCache interface {
...
@@ -50,7 +50,8 @@ type PodBindingCache interface {
}
}
type
podBindingCache
struct
{
type
podBindingCache
struct
{
mutex
sync
.
Mutex
// synchronizes bindingDecisions
rwMutex
sync
.
RWMutex
// Key = pod name
// Key = pod name
// Value = nodeDecisions
// Value = nodeDecisions
...
@@ -72,16 +73,16 @@ func NewPodBindingCache() PodBindingCache {
...
@@ -72,16 +73,16 @@ func NewPodBindingCache() PodBindingCache {
}
}
func
(
c
*
podBindingCache
)
DeleteBindings
(
pod
*
v1
.
Pod
)
{
func
(
c
*
podBindingCache
)
DeleteBindings
(
pod
*
v1
.
Pod
)
{
c
.
m
utex
.
Lock
()
c
.
rwM
utex
.
Lock
()
defer
c
.
m
utex
.
Unlock
()
defer
c
.
rwM
utex
.
Unlock
()
podName
:=
getPodName
(
pod
)
podName
:=
getPodName
(
pod
)
delete
(
c
.
bindingDecisions
,
podName
)
delete
(
c
.
bindingDecisions
,
podName
)
}
}
func
(
c
*
podBindingCache
)
UpdateBindings
(
pod
*
v1
.
Pod
,
node
string
,
bindings
[]
*
bindingInfo
)
{
func
(
c
*
podBindingCache
)
UpdateBindings
(
pod
*
v1
.
Pod
,
node
string
,
bindings
[]
*
bindingInfo
)
{
c
.
m
utex
.
Lock
()
c
.
rwM
utex
.
Lock
()
defer
c
.
m
utex
.
Unlock
()
defer
c
.
rwM
utex
.
Unlock
()
podName
:=
getPodName
(
pod
)
podName
:=
getPodName
(
pod
)
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
...
@@ -101,8 +102,8 @@ func (c *podBindingCache) UpdateBindings(pod *v1.Pod, node string, bindings []*b
...
@@ -101,8 +102,8 @@ func (c *podBindingCache) UpdateBindings(pod *v1.Pod, node string, bindings []*b
}
}
func
(
c
*
podBindingCache
)
GetBindings
(
pod
*
v1
.
Pod
,
node
string
)
[]
*
bindingInfo
{
func
(
c
*
podBindingCache
)
GetBindings
(
pod
*
v1
.
Pod
,
node
string
)
[]
*
bindingInfo
{
c
.
mutex
.
Lock
()
c
.
rwMutex
.
R
Lock
()
defer
c
.
mutex
.
Unlock
()
defer
c
.
rwMutex
.
R
Unlock
()
podName
:=
getPodName
(
pod
)
podName
:=
getPodName
(
pod
)
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
...
@@ -117,8 +118,8 @@ func (c *podBindingCache) GetBindings(pod *v1.Pod, node string) []*bindingInfo {
...
@@ -117,8 +118,8 @@ func (c *podBindingCache) GetBindings(pod *v1.Pod, node string) []*bindingInfo {
}
}
func
(
c
*
podBindingCache
)
UpdateProvisionedPVCs
(
pod
*
v1
.
Pod
,
node
string
,
pvcs
[]
*
v1
.
PersistentVolumeClaim
)
{
func
(
c
*
podBindingCache
)
UpdateProvisionedPVCs
(
pod
*
v1
.
Pod
,
node
string
,
pvcs
[]
*
v1
.
PersistentVolumeClaim
)
{
c
.
m
utex
.
Lock
()
c
.
rwM
utex
.
Lock
()
defer
c
.
m
utex
.
Unlock
()
defer
c
.
rwM
utex
.
Unlock
()
podName
:=
getPodName
(
pod
)
podName
:=
getPodName
(
pod
)
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
...
@@ -138,8 +139,8 @@ func (c *podBindingCache) UpdateProvisionedPVCs(pod *v1.Pod, node string, pvcs [
...
@@ -138,8 +139,8 @@ func (c *podBindingCache) UpdateProvisionedPVCs(pod *v1.Pod, node string, pvcs [
}
}
func
(
c
*
podBindingCache
)
GetProvisionedPVCs
(
pod
*
v1
.
Pod
,
node
string
)
[]
*
v1
.
PersistentVolumeClaim
{
func
(
c
*
podBindingCache
)
GetProvisionedPVCs
(
pod
*
v1
.
Pod
,
node
string
)
[]
*
v1
.
PersistentVolumeClaim
{
c
.
mutex
.
Lock
()
c
.
rwMutex
.
R
Lock
()
defer
c
.
mutex
.
Unlock
()
defer
c
.
rwMutex
.
R
Unlock
()
podName
:=
getPodName
(
pod
)
podName
:=
getPodName
(
pod
)
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
decisions
,
ok
:=
c
.
bindingDecisions
[
podName
]
...
...
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