Skip to content

Commit 2faa977

Browse files
Remove explicit status tracking from namespace registry
1 parent 3005555 commit 2faa977

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

common/namespace/nsregistry/registry.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package nsregistry
55
import (
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-
4335
var (
4436
readthroughNotFoundCacheOpts = cache.Options{
4537
TTL: readthroughCacheTTL,
@@ -76,7 +68,6 @@ type (
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().
162154
func (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().
182169
func (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
}

common/namespace/nsregistry/registry_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func (s *registrySuite) SetupTest() {
5959
}
6060

6161
func (s *registrySuite) TearDownTest() {
62-
s.registry.Stop()
6362
s.controller.Finish()
6463
}
6564

@@ -831,14 +830,14 @@ func (s *registrySuite) TestNamespaceRename() {
831830
}).MinTimes(1)
832831

833832
s.registry.Start()
833+
defer s.registry.Stop()
834834
// Register callback to detect when the rename is applied
835835
refreshCompletedCh := make(chan struct{})
836836
s.registry.RegisterStateChangeCallback("test", func(ns *namespace.Namespace, deletedFromDb bool) {
837837
if ns.Name() == "renamed-name" {
838838
close(refreshCompletedCh)
839839
}
840840
})
841-
defer s.registry.Stop()
842841

843842
// Verify original name works before rename
844843
ns, err := s.registry.GetNamespace("original-name")

0 commit comments

Comments
 (0)