@@ -5,7 +5,6 @@ package nsregistry
55import (
66 "context"
77 "sync"
8- "sync/atomic"
98 "time"
109
1110 "go.temporal.io/api/serviceerror"
@@ -33,13 +32,6 @@ const (
3332 readthroughTimeout = 3 * time .Second
3433)
3534
36- const (
37- stopped int32 = iota
38- starting
39- running
40- stopping
41- )
42-
4335var (
4436 readthroughNotFoundCacheOpts = cache.Options {
4537 TTL : readthroughCacheTTL ,
7668 GetMetadata (context.Context ) (* persistence.GetMetadataResponse , error )
7769 }
7870 registry struct {
79- status int32
8071 refresher * goro.Handle
8172 persistence Persistence
8273 globalNamespacesEnabled bool
@@ -158,14 +149,9 @@ func (r *registry) RefreshNamespaceById(id namespace.ID) (*namespace.Namespace,
158149 return ns , nil
159150}
160151
161- // Start the background refresh of Namespace data.
152+ // Start begins background refresh. Should only be invoked by fx lifecycle hook.
153+ // Should not be called multiple times or concurrently with Stop().
162154func (r * registry ) Start () {
163- if ! atomic .CompareAndSwapInt32 (& r .status , stopped , starting ) {
164- return
165- }
166- defer atomic .StoreInt32 (& r .status , running )
167-
168- // initialize the namespace registry by initial scan
169155 ctx := headers .SetCallerInfo (
170156 context .Background (),
171157 headers .SystemBackgroundHighCallerInfo ,
@@ -178,12 +164,9 @@ func (r *registry) Start() {
178164 r .refresher = goro .NewHandle (ctx ).Go (r .refreshLoop )
179165}
180166
181- // Stop the background refresh of Namespace data
167+ // Stop ends background refresh. Should only be invoked by fx lifecycle hook.
168+ // Should not be called multiple times or concurrently with Start().
182169func (r * registry ) Stop () {
183- if ! atomic .CompareAndSwapInt32 (& r .status , running , stopping ) {
184- return
185- }
186- defer atomic .StoreInt32 (& r .status , stopped )
187170 r .refresher .Cancel ()
188171 <- r .refresher .Done ()
189172}
0 commit comments