@@ -33,6 +33,7 @@ import (
33
33
"time"
34
34
35
35
"github.com/uber/cadence/common"
36
+ "github.com/uber/cadence/common/backoff"
36
37
"github.com/uber/cadence/common/clock"
37
38
"github.com/uber/cadence/common/cluster"
38
39
"github.com/uber/cadence/common/errors"
@@ -60,10 +61,7 @@ const (
60
61
domainCacheMinRefreshInterval = 1 * time .Second
61
62
// DomainCacheRefreshInterval domain cache refresh interval
62
63
DomainCacheRefreshInterval = 10 * time .Second
63
- // DomainCacheRefreshFailureRetryInterval is the wait time
64
- // if refreshment encounters error
65
- DomainCacheRefreshFailureRetryInterval = 1 * time .Second
66
- domainCacheRefreshPageSize = 200
64
+ domainCacheRefreshPageSize = 200
67
65
68
66
domainCachePersistenceTimeout = 3 * time .Second
69
67
@@ -119,6 +117,8 @@ type (
119
117
callbackLock sync.Mutex
120
118
prepareCallbacks map [int ]PrepareCallbackFn
121
119
callbacks map [int ]CallbackFn
120
+
121
+ throttleRetry * backoff.ThrottleRetry
122
122
}
123
123
124
124
// DomainCacheEntries is DomainCacheEntry slice
@@ -160,6 +160,11 @@ func NewDomainCache(
160
160
opts ... DomainCacheOption ,
161
161
) * DefaultDomainCache {
162
162
163
+ throttleRetry := backoff .NewThrottleRetry (
164
+ backoff .WithRetryPolicy (common .CreateDomainCacheRetryPolicy ()),
165
+ backoff .WithRetryableError (common .IsServiceTransientError ),
166
+ )
167
+
163
168
cache := & DefaultDomainCache {
164
169
status : domainCacheInitialized ,
165
170
shutdownChan : make (chan struct {}),
@@ -172,6 +177,7 @@ func NewDomainCache(
172
177
logger : logger ,
173
178
prepareCallbacks : make (map [int ]PrepareCallbackFn ),
174
179
callbacks : make (map [int ]CallbackFn ),
180
+ throttleRetry : throttleRetry ,
175
181
}
176
182
cache .cacheNameToID .Store (newDomainCache ())
177
183
cache .cacheByID .Store (newDomainCache ())
@@ -411,15 +417,12 @@ func (c *DefaultDomainCache) refreshLoop() {
411
417
case <- c .shutdownChan :
412
418
return
413
419
case <- timer .Chan ():
414
- for err := c .refreshDomains (); err != nil ; err = c .refreshDomains () {
415
- select {
416
- case <- c .shutdownChan :
417
- return
418
- default :
419
- c .logger .Error ("Error refreshing domain cache" , tag .Error (err ))
420
- c .timeSource .Sleep (DomainCacheRefreshFailureRetryInterval )
421
- }
420
+ err := c .refreshDomains ()
421
+ if err != nil {
422
+ c .logger .Error ("Error refreshing domain cache" , tag .Error (err ))
423
+ continue
422
424
}
425
+
423
426
c .logger .Debug ("Domain cache refreshed" )
424
427
}
425
428
}
@@ -428,7 +431,7 @@ func (c *DefaultDomainCache) refreshLoop() {
428
431
func (c * DefaultDomainCache ) refreshDomains () error {
429
432
c .refreshLock .Lock ()
430
433
defer c .refreshLock .Unlock ()
431
- return c .refreshDomainsLocked ( )
434
+ return c .throttleRetry . Do ( context . Background (), c . refreshDomainsLocked )
432
435
}
433
436
434
437
// this function only refresh the domains in the v2 table
0 commit comments