Skip to content

Commit dc257ce

Browse files
authored
Add GetIndexName method to visibility manager (#3820)
1 parent fc6efef commit dc257ce

31 files changed

+253
-108
lines changed

common/persistence/sql/common.go

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func (m *SqlStore) GetName() string {
5757
return m.Db.PluginName()
5858
}
5959

60+
func (m *SqlStore) GetDbName() string {
61+
return m.Db.DbName()
62+
}
63+
6064
func (m *SqlStore) Close() {
6165
if m.Db != nil {
6266
err := m.Db.Close()

common/persistence/sql/sqlplugin/interfaces.go

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type (
110110

111111
BeginTx(ctx context.Context) (Tx, error)
112112
PluginName() string
113+
DbName() string
113114
IsDupEntryError(err error) bool
114115
Close() error
115116
}

common/persistence/sql/sqlplugin/mysql/db.go

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func (mdb *db) PluginName() string {
111111
return PluginName
112112
}
113113

114+
// DbName returns the name of the database
115+
func (mdb *db) DbName() string {
116+
return mdb.dbName
117+
}
118+
114119
// ExpectedVersion returns expected version.
115120
func (mdb *db) ExpectedVersion() string {
116121
switch mdb.dbKind {

common/persistence/sql/sqlplugin/postgresql/db.go

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ func (pdb *db) PluginName() string {
110110
return PluginName
111111
}
112112

113+
// DbName returns the name of the database
114+
func (pdb *db) DbName() string {
115+
return pdb.dbName
116+
}
117+
113118
// ExpectedVersion returns expected version.
114119
func (pdb *db) ExpectedVersion() string {
115120
switch pdb.dbKind {

common/persistence/sql/sqlplugin/sqlite/db.go

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ func (mdb *db) PluginName() string {
122122
return PluginName
123123
}
124124

125+
// DbName returns the name of the database
126+
func (mdb *db) DbName() string {
127+
return mdb.dbName
128+
}
129+
125130
// ExpectedVersion returns expected version.
126131
func (mdb *db) ExpectedVersion() string {
127132
switch mdb.dbKind {

common/persistence/visibility/manager/visibility_manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type (
4444
VisibilityManager interface {
4545
persistence.Closeable
4646
GetName() string
47+
GetIndexName() string
4748

4849
// Write APIs.
4950
RecordWorkflowExecutionStarted(ctx context.Context, request *RecordWorkflowExecutionStartedRequest) error

common/persistence/visibility/manager/visibility_manager_mock.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/persistence/visibility/store/elasticsearch/visibility_store.go

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func (s *visibilityStore) GetName() string {
130130
return PersistenceName
131131
}
132132

133+
func (s *visibilityStore) GetIndexName() string {
134+
return s.index
135+
}
136+
133137
func (s *visibilityStore) RecordWorkflowExecutionStarted(
134138
ctx context.Context,
135139
request *store.InternalRecordWorkflowExecutionStartedRequest,

common/persistence/visibility/store/standard/cassandra/visibility_store.go

+6
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ type (
140140
visibilityStore struct {
141141
session gocql.Session
142142
lowConslevel gocql.Consistency
143+
keyspace string
143144
}
144145
)
145146

@@ -158,13 +159,18 @@ func NewVisibilityStore(
158159
return &visibilityStore{
159160
session: session,
160161
lowConslevel: gocql.One,
162+
keyspace: cfg.Keyspace,
161163
}, nil
162164
}
163165

164166
func (v *visibilityStore) GetName() string {
165167
return CassandraPersistenceName
166168
}
167169

170+
func (v *visibilityStore) GetIndexName() string {
171+
return v.keyspace
172+
}
173+
168174
// Close releases the resources held by this object
169175
func (v *visibilityStore) Close() {
170176
v.session.Close()

common/persistence/visibility/store/standard/sql/visibility_store.go

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (s *visibilityStore) GetName() string {
8080
return s.sqlStore.GetName()
8181
}
8282

83+
func (s *visibilityStore) GetIndexName() string {
84+
return s.sqlStore.GetDbName()
85+
}
86+
8387
func (s *visibilityStore) RecordWorkflowExecutionStarted(
8488
ctx context.Context,
8589
request *store.InternalRecordWorkflowExecutionStartedRequest,

common/persistence/visibility/store/standard/visibility_store.go

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ func (s *standardStore) GetName() string {
7373
return s.store.GetName()
7474
}
7575

76+
func (s *standardStore) GetIndexName() string {
77+
return s.store.GetIndexName()
78+
}
79+
7680
func (s *standardStore) RecordWorkflowExecutionStarted(
7781
ctx context.Context,
7882
request *store.InternalRecordWorkflowExecutionStartedRequest,

common/persistence/visibility/store/visibility_store.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type (
4343
VisibilityStore interface {
4444
persistence.Closeable
4545
GetName() string
46+
GetIndexName() string
4647

4748
// Write APIs.
4849
RecordWorkflowExecutionStarted(ctx context.Context, request *InternalRecordWorkflowExecutionStartedRequest) error

common/persistence/visibility/store/visibility_store_mock.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/persistence/visibility/visibility_manager_dual.go

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func (v *visibilityManagerDual) GetName() string {
6464
return strings.Join([]string{v.visibilityManager.GetName(), v.secondaryVisibilityManager.GetName()}, ",")
6565
}
6666

67+
func (v *visibilityManagerDual) GetIndexName() string {
68+
return v.visibilityManager.GetIndexName()
69+
}
70+
6771
func (v *visibilityManagerDual) RecordWorkflowExecutionStarted(
6872
ctx context.Context,
6973
request *manager.RecordWorkflowExecutionStartedRequest,

common/persistence/visibility/visibility_manager_impl.go

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (p *visibilityManagerImpl) GetName() string {
7676
return p.store.GetName()
7777
}
7878

79+
func (p *visibilityManagerImpl) GetIndexName() string {
80+
return p.store.GetIndexName()
81+
}
82+
7983
func (p *visibilityManagerImpl) RecordWorkflowExecutionStarted(
8084
ctx context.Context,
8185
request *manager.RecordWorkflowExecutionStartedRequest,

common/persistence/visibility/visibility_manager_rate_limited.go

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (m *visibilityManagerRateLimited) GetName() string {
6767
return m.delegate.GetName()
6868
}
6969

70+
func (m *visibilityManagerRateLimited) GetIndexName() string {
71+
return m.delegate.GetIndexName()
72+
}
73+
7074
// Below are write APIs.
7175

7276
func (m *visibilityManagerRateLimited) RecordWorkflowExecutionStarted(

common/persistence/visibility/visiblity_manager_metrics.go

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ func (m *visibilityManagerMetrics) GetName() string {
6969
return m.delegate.GetName()
7070
}
7171

72+
func (m *visibilityManagerMetrics) GetIndexName() string {
73+
return m.delegate.GetIndexName()
74+
}
75+
7276
func (m *visibilityManagerMetrics) RecordWorkflowExecutionStarted(
7377
ctx context.Context,
7478
request *manager.RecordWorkflowExecutionStartedRequest,

common/resourcetest/resourceTest.go

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"go.temporal.io/server/common/persistence"
5252
persistenceClient "go.temporal.io/server/common/persistence/client"
5353
"go.temporal.io/server/common/persistence/serialization"
54+
"go.temporal.io/server/common/persistence/visibility/manager"
5455
esclient "go.temporal.io/server/common/persistence/visibility/store/elasticsearch/client"
5556
"go.temporal.io/server/common/primitives"
5657
"go.temporal.io/server/common/sdk"
@@ -96,6 +97,7 @@ type (
9697
ClientBean *client.MockBean
9798
ClientFactory *client.MockFactory
9899
ESClient *esclient.MockClient
100+
VisibilityManager *manager.MockVisibilityManager
99101

100102
// persistence clients
101103

@@ -206,6 +208,7 @@ func NewTest(
206208
ClientBean: clientBean,
207209
ClientFactory: clientFactory,
208210
ESClient: esclient.NewMockClient(controller),
211+
VisibilityManager: manager.NewMockVisibilityManager(controller),
209212

210213
// persistence clients
211214

@@ -373,6 +376,11 @@ func (t *Test) GetClientFactory() client.Factory {
373376
return t.ClientFactory
374377
}
375378

379+
// GetVisibilityManager for testing
380+
func (t *Test) GetVisibilityManager() manager.VisibilityManager {
381+
return t.VisibilityManager
382+
}
383+
376384
// persistence clients
377385

378386
// GetMetadataManager for testing

common/searchattribute/manager.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewManager(
8787
}
8888

8989
// GetSearchAttributes returns all search attributes (including system and build-in) for specified index.
90-
// indexName can be an empty string when Elasticsearch is not configured.
90+
// indexName can be an empty string for backward compatibility.
9191
func (m *managerImpl) GetSearchAttributes(
9292
indexName string,
9393
forceRefreshCache bool,
@@ -111,11 +111,19 @@ func (m *managerImpl) GetSearchAttributes(
111111
}
112112

113113
indexSearchAttributes, ok := saCache.searchAttributes[indexName]
114-
if !ok {
115-
return NameTypeMap{}, nil
114+
if ok {
115+
return indexSearchAttributes, nil
116116
}
117117

118-
return indexSearchAttributes, nil
118+
if indexName != "" {
119+
// Try to look for the empty string indexName for backward compatibility: up to v1.19,
120+
// empty string was used when Elasticsearch was not configured.
121+
indexSearchAttributes, ok = saCache.searchAttributes[""]
122+
if ok {
123+
return indexSearchAttributes, nil
124+
}
125+
}
126+
return NameTypeMap{}, nil
119127
}
120128

121129
func (m *managerImpl) needRefreshCache(saCache cache, forceRefreshCache bool, now time.Time) bool {

service/frontend/adminHandler.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ type (
9797

9898
logger log.Logger
9999
numberOfHistoryShards int32
100-
ESConfig *esclient.Config
101100
ESClient esclient.Client
102101
config *Config
103102
namespaceHandler namespace.Handler
@@ -127,7 +126,6 @@ type (
127126
Config *Config
128127
NamespaceReplicationQueue persistence.NamespaceReplicationQueue
129128
ReplicatorNamespaceReplicationQueue persistence.NamespaceReplicationQueue
130-
EsConfig *esclient.Config
131129
EsClient esclient.Client
132130
VisibilityMrg manager.VisibilityManager
133131
Logger log.Logger
@@ -192,7 +190,6 @@ func NewAdminHandler(
192190
),
193191
eventSerializer: args.EventSerializer,
194192
visibilityMgr: args.VisibilityMrg,
195-
ESConfig: args.EsConfig,
196193
ESClient: args.EsClient,
197194
persistenceExecutionManager: args.PersistenceExecutionManager,
198195
namespaceReplicationQueue: args.NamespaceReplicationQueue,
@@ -257,7 +254,7 @@ func (adh *AdminHandler) AddSearchAttributes(ctx context.Context, request *admin
257254

258255
indexName := request.GetIndexName()
259256
if indexName == "" {
260-
indexName = adh.ESConfig.GetVisibilityIndex()
257+
indexName = adh.visibilityMgr.GetIndexName()
261258
}
262259

263260
currentSearchAttributes, err := adh.saProvider.GetSearchAttributes(indexName, true)
@@ -322,7 +319,7 @@ func (adh *AdminHandler) RemoveSearchAttributes(ctx context.Context, request *ad
322319

323320
indexName := request.GetIndexName()
324321
if indexName == "" {
325-
indexName = adh.ESConfig.GetVisibilityIndex()
322+
indexName = adh.visibilityMgr.GetIndexName()
326323
}
327324

328325
currentSearchAttributes, err := adh.saProvider.GetSearchAttributes(indexName, true)
@@ -359,7 +356,7 @@ func (adh *AdminHandler) GetSearchAttributes(ctx context.Context, request *admin
359356

360357
indexName := request.GetIndexName()
361358
if indexName == "" {
362-
indexName = adh.ESConfig.GetVisibilityIndex()
359+
indexName = adh.visibilityMgr.GetIndexName()
363360
}
364361

365362
resp, err := adh.getSearchAttributes(ctx, indexName, "")

0 commit comments

Comments
 (0)