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
0cefb437
Commit
0cefb437
authored
Dec 04, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable listing from memory
parent
0caaf258
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
15 deletions
+15
-15
reflector.go
pkg/client/cache/reflector.go
+4
-1
cacher.go
pkg/storage/cacher.go
+7
-12
cacher_test.go
pkg/storage/cacher_test.go
+0
-1
load.go
test/e2e/load.go
+4
-1
No files found.
pkg/client/cache/reflector.go
View file @
0cefb437
...
@@ -227,7 +227,10 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
...
@@ -227,7 +227,10 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
resyncCh
,
cleanup
:=
r
.
resyncChan
()
resyncCh
,
cleanup
:=
r
.
resyncChan
()
defer
cleanup
()
defer
cleanup
()
options
:=
unversioned
.
ListOptions
{}
// Explicitly set "0" as resource version - it's fine for the List()
// to be served from cache and potentially be delayed relative to
// etcd contents. Reflector framework will catch up via Watch() eventually.
options
:=
unversioned
.
ListOptions
{
ResourceVersion
:
"0"
}
list
,
err
:=
r
.
listerWatcher
.
List
(
options
)
list
,
err
:=
r
.
listerWatcher
.
List
(
options
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%s: Failed to list %v: %v"
,
r
.
name
,
r
.
expectedType
,
err
)
return
fmt
.
Errorf
(
"%s: Failed to list %v: %v"
,
r
.
name
,
r
.
expectedType
,
err
)
...
...
pkg/storage/cacher.go
View file @
0cefb437
...
@@ -48,11 +48,6 @@ type CacherConfig struct {
...
@@ -48,11 +48,6 @@ type CacherConfig struct {
// An underlying storage.Versioner.
// An underlying storage.Versioner.
Versioner
Versioner
Versioner
Versioner
// Whether to serve Lists from in-memory cache.
//
// NOTE: DO NOT SET TO TRUE IN PRODUCTION CODE!
ListFromCache
bool
// The Cache will be caching objects of a given Type and assumes that they
// The Cache will be caching objects of a given Type and assumes that they
// are all stored under ResourcePrefix directory in the underlying database.
// are all stored under ResourcePrefix directory in the underlying database.
Type
interface
{}
Type
interface
{}
...
@@ -107,11 +102,6 @@ type Cacher struct {
...
@@ -107,11 +102,6 @@ type Cacher struct {
// keyFunc is used to get a key in the underyling storage for a given object.
// keyFunc is used to get a key in the underyling storage for a given object.
keyFunc
func
(
runtime
.
Object
)
(
string
,
error
)
keyFunc
func
(
runtime
.
Object
)
(
string
,
error
)
// Whether to serve Lists from in-memory cache.
//
// NOTE: DO NOT SET TO TRUE IN PRODUCTION CODE!
ListFromCache
bool
}
}
// Create a new Cacher responsible from service WATCH and LIST requests from its
// Create a new Cacher responsible from service WATCH and LIST requests from its
...
@@ -161,7 +151,6 @@ func NewCacherFromConfig(config CacherConfig) *Cacher {
...
@@ -161,7 +151,6 @@ func NewCacherFromConfig(config CacherConfig) *Cacher {
watchers
:
make
(
map
[
int
]
*
cacheWatcher
),
watchers
:
make
(
map
[
int
]
*
cacheWatcher
),
versioner
:
config
.
Versioner
,
versioner
:
config
.
Versioner
,
keyFunc
:
config
.
KeyFunc
,
keyFunc
:
config
.
KeyFunc
,
ListFromCache
:
config
.
ListFromCache
,
}
}
cacher
.
usable
.
Lock
()
cacher
.
usable
.
Lock
()
// See startCaching method for why explanation on it.
// See startCaching method for why explanation on it.
...
@@ -270,10 +259,16 @@ func (c *Cacher) GetToList(ctx context.Context, key string, filter FilterFunc, l
...
@@ -270,10 +259,16 @@ func (c *Cacher) GetToList(ctx context.Context, key string, filter FilterFunc, l
// Implements storage.Interface.
// Implements storage.Interface.
func
(
c
*
Cacher
)
List
(
ctx
context
.
Context
,
key
string
,
resourceVersion
string
,
filter
FilterFunc
,
listObj
runtime
.
Object
)
error
{
func
(
c
*
Cacher
)
List
(
ctx
context
.
Context
,
key
string
,
resourceVersion
string
,
filter
FilterFunc
,
listObj
runtime
.
Object
)
error
{
if
!
c
.
ListFromCache
{
if
resourceVersion
==
""
{
// If resourceVersion is not specified, serve it from underlying
// storage (for backward compatibility).
return
c
.
storage
.
List
(
ctx
,
key
,
resourceVersion
,
filter
,
listObj
)
return
c
.
storage
.
List
(
ctx
,
key
,
resourceVersion
,
filter
,
listObj
)
}
}
// If resourceVersion is specified, serve it from cache.
// It's guaranteed that the returned value is at least that
// fresh as the given resourceVersion.
listRV
,
err
:=
ParseListResourceVersion
(
resourceVersion
)
listRV
,
err
:=
ParseListResourceVersion
(
resourceVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/storage/cacher_test.go
View file @
0cefb437
...
@@ -52,7 +52,6 @@ func newTestCacher(s storage.Interface) *storage.Cacher {
...
@@ -52,7 +52,6 @@ func newTestCacher(s storage.Interface) *storage.Cacher {
CacheCapacity
:
10
,
CacheCapacity
:
10
,
Storage
:
s
,
Storage
:
s
,
Versioner
:
etcdstorage
.
APIObjectVersioner
{},
Versioner
:
etcdstorage
.
APIObjectVersioner
{},
ListFromCache
:
true
,
Type
:
&
api
.
Pod
{},
Type
:
&
api
.
Pod
{},
ResourcePrefix
:
prefix
,
ResourcePrefix
:
prefix
,
KeyFunc
:
func
(
obj
runtime
.
Object
)
(
string
,
error
)
{
return
storage
.
NamespaceKeyFunc
(
prefix
,
obj
)
},
KeyFunc
:
func
(
obj
runtime
.
Object
)
(
string
,
error
)
{
return
storage
.
NamespaceKeyFunc
(
prefix
,
obj
)
},
...
...
test/e2e/load.go
View file @
0cefb437
...
@@ -214,7 +214,10 @@ func scaleRC(wg *sync.WaitGroup, config *RCConfig) {
...
@@ -214,7 +214,10 @@ func scaleRC(wg *sync.WaitGroup, config *RCConfig) {
expectNoError
(
ScaleRC
(
config
.
Client
,
config
.
Namespace
,
config
.
Name
,
newSize
,
true
),
expectNoError
(
ScaleRC
(
config
.
Client
,
config
.
Namespace
,
config
.
Name
,
newSize
,
true
),
fmt
.
Sprintf
(
"scaling rc %s for the first time"
,
config
.
Name
))
fmt
.
Sprintf
(
"scaling rc %s for the first time"
,
config
.
Name
))
selector
:=
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"name"
:
config
.
Name
}))
selector
:=
labels
.
SelectorFromSet
(
labels
.
Set
(
map
[
string
]
string
{
"name"
:
config
.
Name
}))
options
:=
unversioned
.
ListOptions
{
LabelSelector
:
unversioned
.
LabelSelector
{
selector
}}
options
:=
unversioned
.
ListOptions
{
LabelSelector
:
unversioned
.
LabelSelector
{
selector
},
ResourceVersion
:
"0"
,
}
_
,
err
:=
config
.
Client
.
Pods
(
config
.
Namespace
)
.
List
(
options
)
_
,
err
:=
config
.
Client
.
Pods
(
config
.
Namespace
)
.
List
(
options
)
expectNoError
(
err
,
fmt
.
Sprintf
(
"listing pods from rc %v"
,
config
.
Name
))
expectNoError
(
err
,
fmt
.
Sprintf
(
"listing pods from rc %v"
,
config
.
Name
))
}
}
...
...
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