Merge pull request #49688 from wojtek-t/skip_cacher_if_not_initialized

Automatic merge from submit-queue (batch tested with PRs 49581, 49652, 49681, 49688, 44655)

Don't use cacher if uninitialized

Ref #49684
pull/6/head
Kubernetes Submit Queue 2017-07-28 13:45:51 -07:00 committed by GitHub
commit 0f6a64453c
1 changed files with 26 additions and 0 deletions

View File

@ -369,6 +369,12 @@ func (c *Cacher) Get(ctx context.Context, key string, resourceVersion string, ob
return err
}
if getRV == 0 && !c.ready.check() {
// If Cacher is not yet initialized and we don't require any specific
// minimal resource version, simply forward the request to storage.
return c.storage.Get(ctx, key, resourceVersion, objPtr, ignoreNotFound)
}
// Do not create a trace - it's not for free and there are tons
// of Get requests. We can add it if it will be really needed.
c.ready.wait()
@ -414,6 +420,12 @@ func (c *Cacher) GetToList(ctx context.Context, key string, resourceVersion stri
return err
}
if listRV == 0 && !c.ready.check() {
// If Cacher is not yet initialized and we don't require any specific
// minimal resource version, simply forward the request to storage.
return c.storage.GetToList(ctx, key, resourceVersion, pred, listObj)
}
trace := utiltrace.New(fmt.Sprintf("cacher %v: List", c.objectType.String()))
defer trace.LogIfLong(500 * time.Millisecond)
@ -470,6 +482,12 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, p
return err
}
if listRV == 0 && !c.ready.check() {
// If Cacher is not yet initialized and we don't require any specific
// minimal resource version, simply forward the request to storage.
return c.storage.List(ctx, key, resourceVersion, pred, listObj)
}
trace := utiltrace.New(fmt.Sprintf("cacher %v: List", c.objectType.String()))
defer trace.LogIfLong(500 * time.Millisecond)
@ -966,6 +984,14 @@ func (r *ready) wait() {
r.c.L.Unlock()
}
// TODO: Make check() function more sophisticated, in particular
// allow it to behave as "waitWithTimeout".
func (r *ready) check() bool {
r.c.L.Lock()
defer r.c.L.Unlock()
return r.ok
}
func (r *ready) set(ok bool) {
r.c.L.Lock()
defer r.c.L.Unlock()