mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-29 00:17:46 +00:00
Improve backoff policy in reflector.
Before, we've used two separate backoff managers for List and Watch calls, now they share single backoff manager. Kubernetes-commit: 337728b02559dec8a613fdef174f732da9cae310
This commit is contained in:
parent
c670796be1
commit
bae10246dd
9
tools/cache/reflector.go
vendored
9
tools/cache/reflector.go
vendored
@ -70,8 +70,6 @@ type Reflector struct {
|
|||||||
listerWatcher ListerWatcher
|
listerWatcher ListerWatcher
|
||||||
// backoff manages backoff of ListWatch
|
// backoff manages backoff of ListWatch
|
||||||
backoffManager wait.BackoffManager
|
backoffManager wait.BackoffManager
|
||||||
// initConnBackoffManager manages backoff the initial connection with the Watch call of ListAndWatch.
|
|
||||||
initConnBackoffManager wait.BackoffManager
|
|
||||||
resyncPeriod time.Duration
|
resyncPeriod time.Duration
|
||||||
// clock allows tests to manipulate time
|
// clock allows tests to manipulate time
|
||||||
clock clock.Clock
|
clock clock.Clock
|
||||||
@ -222,7 +220,6 @@ func NewReflectorWithOptions(lw ListerWatcher, expectedType interface{}, store S
|
|||||||
// API server is not healthy. With these parameters, backoff will stop at [30,60) sec interval which is
|
// API server is not healthy. With these parameters, backoff will stop at [30,60) sec interval which is
|
||||||
// 0.22 QPS. If we don't backoff for 2min, assume API server is healthy and we reset the backoff.
|
// 0.22 QPS. If we don't backoff for 2min, assume API server is healthy and we reset the backoff.
|
||||||
backoffManager: wait.NewExponentialBackoffManager(800*time.Millisecond, 30*time.Second, 2*time.Minute, 2.0, 1.0, reflectorClock),
|
backoffManager: wait.NewExponentialBackoffManager(800*time.Millisecond, 30*time.Second, 2*time.Minute, 2.0, 1.0, reflectorClock),
|
||||||
initConnBackoffManager: wait.NewExponentialBackoffManager(800*time.Millisecond, 30*time.Second, 2*time.Minute, 2.0, 1.0, reflectorClock),
|
|
||||||
clock: reflectorClock,
|
clock: reflectorClock,
|
||||||
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
||||||
expectedType: reflect.TypeOf(expectedType),
|
expectedType: reflect.TypeOf(expectedType),
|
||||||
@ -425,7 +422,7 @@ func (r *Reflector) watch(w watch.Interface, stopCh <-chan struct{}, resyncerrc
|
|||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
return nil
|
return nil
|
||||||
case <-r.initConnBackoffManager.Backoff().C():
|
case <-r.backoffManager.Backoff().C():
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,7 +448,7 @@ func (r *Reflector) watch(w watch.Interface, stopCh <-chan struct{}, resyncerrc
|
|||||||
select {
|
select {
|
||||||
case <-stopCh:
|
case <-stopCh:
|
||||||
return nil
|
return nil
|
||||||
case <-r.initConnBackoffManager.Backoff().C():
|
case <-r.backoffManager.Backoff().C():
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case apierrors.IsInternalError(err) && retry.ShouldRetry():
|
case apierrors.IsInternalError(err) && retry.ShouldRetry():
|
||||||
@ -604,7 +601,7 @@ func (r *Reflector) watchList(stopCh <-chan struct{}) (watch.Interface, error) {
|
|||||||
isErrorRetriableWithSideEffectsFn := func(err error) bool {
|
isErrorRetriableWithSideEffectsFn := func(err error) bool {
|
||||||
if canRetry := isWatchErrorRetriable(err); canRetry {
|
if canRetry := isWatchErrorRetriable(err); canRetry {
|
||||||
klog.V(2).Infof("%s: watch-list of %v returned %v - backing off", r.name, r.typeDescription, err)
|
klog.V(2).Infof("%s: watch-list of %v returned %v - backing off", r.name, r.typeDescription, err)
|
||||||
<-r.initConnBackoffManager.Backoff().C()
|
<-r.backoffManager.Backoff().C()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if isExpiredError(err) || isTooLargeResourceVersionError(err) {
|
if isExpiredError(err) || isTooLargeResourceVersionError(err) {
|
||||||
|
6
tools/cache/reflector_test.go
vendored
6
tools/cache/reflector_test.go
vendored
@ -414,7 +414,7 @@ func TestReflectorListAndWatchInitConnBackoff(t *testing.T) {
|
|||||||
name: "test-reflector",
|
name: "test-reflector",
|
||||||
listerWatcher: lw,
|
listerWatcher: lw,
|
||||||
store: NewFIFO(MetaNamespaceKeyFunc),
|
store: NewFIFO(MetaNamespaceKeyFunc),
|
||||||
initConnBackoffManager: bm,
|
backoffManager: bm,
|
||||||
clock: fakeClock,
|
clock: fakeClock,
|
||||||
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
||||||
}
|
}
|
||||||
@ -474,7 +474,7 @@ func TestBackoffOnTooManyRequests(t *testing.T) {
|
|||||||
name: "test-reflector",
|
name: "test-reflector",
|
||||||
listerWatcher: lw,
|
listerWatcher: lw,
|
||||||
store: NewFIFO(MetaNamespaceKeyFunc),
|
store: NewFIFO(MetaNamespaceKeyFunc),
|
||||||
initConnBackoffManager: bm,
|
backoffManager: bm,
|
||||||
clock: clock,
|
clock: clock,
|
||||||
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
||||||
}
|
}
|
||||||
@ -543,7 +543,7 @@ func TestRetryInternalError(t *testing.T) {
|
|||||||
name: "test-reflector",
|
name: "test-reflector",
|
||||||
listerWatcher: lw,
|
listerWatcher: lw,
|
||||||
store: NewFIFO(MetaNamespaceKeyFunc),
|
store: NewFIFO(MetaNamespaceKeyFunc),
|
||||||
initConnBackoffManager: bm,
|
backoffManager: bm,
|
||||||
clock: fakeClock,
|
clock: fakeClock,
|
||||||
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user