Skip to content

Commit

Permalink
Add GetIndexName method to visibility manager (#3820)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigozhou authored Jan 27, 2023
1 parent fc6efef commit dc257ce
Show file tree
Hide file tree
Showing 31 changed files with 253 additions and 108 deletions.
4 changes: 4 additions & 0 deletions common/persistence/sql/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (m *SqlStore) GetName() string {
return m.Db.PluginName()
}

func (m *SqlStore) GetDbName() string {
return m.Db.DbName()
}

func (m *SqlStore) Close() {
if m.Db != nil {
err := m.Db.Close()
Expand Down
1 change: 1 addition & 0 deletions common/persistence/sql/sqlplugin/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type (

BeginTx(ctx context.Context) (Tx, error)
PluginName() string
DbName() string
IsDupEntryError(err error) bool
Close() error
}
Expand Down
5 changes: 5 additions & 0 deletions common/persistence/sql/sqlplugin/mysql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func (mdb *db) PluginName() string {
return PluginName
}

// DbName returns the name of the database
func (mdb *db) DbName() string {
return mdb.dbName
}

// ExpectedVersion returns expected version.
func (mdb *db) ExpectedVersion() string {
switch mdb.dbKind {
Expand Down
5 changes: 5 additions & 0 deletions common/persistence/sql/sqlplugin/postgresql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func (pdb *db) PluginName() string {
return PluginName
}

// DbName returns the name of the database
func (pdb *db) DbName() string {
return pdb.dbName
}

// ExpectedVersion returns expected version.
func (pdb *db) ExpectedVersion() string {
switch pdb.dbKind {
Expand Down
5 changes: 5 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func (mdb *db) PluginName() string {
return PluginName
}

// DbName returns the name of the database
func (mdb *db) DbName() string {
return mdb.dbName
}

// ExpectedVersion returns expected version.
func (mdb *db) ExpectedVersion() string {
switch mdb.dbKind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type (
VisibilityManager interface {
persistence.Closeable
GetName() string
GetIndexName() string

// Write APIs.
RecordWorkflowExecutionStarted(ctx context.Context, request *RecordWorkflowExecutionStartedRequest) error
Expand Down
14 changes: 14 additions & 0 deletions common/persistence/visibility/manager/visibility_manager_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (s *visibilityStore) GetName() string {
return PersistenceName
}

func (s *visibilityStore) GetIndexName() string {
return s.index
}

func (s *visibilityStore) RecordWorkflowExecutionStarted(
ctx context.Context,
request *store.InternalRecordWorkflowExecutionStartedRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type (
visibilityStore struct {
session gocql.Session
lowConslevel gocql.Consistency
keyspace string
}
)

Expand All @@ -158,13 +159,18 @@ func NewVisibilityStore(
return &visibilityStore{
session: session,
lowConslevel: gocql.One,
keyspace: cfg.Keyspace,
}, nil
}

func (v *visibilityStore) GetName() string {
return CassandraPersistenceName
}

func (v *visibilityStore) GetIndexName() string {
return v.keyspace
}

// Close releases the resources held by this object
func (v *visibilityStore) Close() {
v.session.Close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (s *visibilityStore) GetName() string {
return s.sqlStore.GetName()
}

func (s *visibilityStore) GetIndexName() string {
return s.sqlStore.GetDbName()
}

func (s *visibilityStore) RecordWorkflowExecutionStarted(
ctx context.Context,
request *store.InternalRecordWorkflowExecutionStartedRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (s *standardStore) GetName() string {
return s.store.GetName()
}

func (s *standardStore) GetIndexName() string {
return s.store.GetIndexName()
}

func (s *standardStore) RecordWorkflowExecutionStarted(
ctx context.Context,
request *store.InternalRecordWorkflowExecutionStartedRequest,
Expand Down
1 change: 1 addition & 0 deletions common/persistence/visibility/store/visibility_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type (
VisibilityStore interface {
persistence.Closeable
GetName() string
GetIndexName() string

// Write APIs.
RecordWorkflowExecutionStarted(ctx context.Context, request *InternalRecordWorkflowExecutionStartedRequest) error
Expand Down
14 changes: 14 additions & 0 deletions common/persistence/visibility/store/visibility_store_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions common/persistence/visibility/visibility_manager_dual.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (v *visibilityManagerDual) GetName() string {
return strings.Join([]string{v.visibilityManager.GetName(), v.secondaryVisibilityManager.GetName()}, ",")
}

func (v *visibilityManagerDual) GetIndexName() string {
return v.visibilityManager.GetIndexName()
}

func (v *visibilityManagerDual) RecordWorkflowExecutionStarted(
ctx context.Context,
request *manager.RecordWorkflowExecutionStartedRequest,
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/visibility/visibility_manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (p *visibilityManagerImpl) GetName() string {
return p.store.GetName()
}

func (p *visibilityManagerImpl) GetIndexName() string {
return p.store.GetIndexName()
}

func (p *visibilityManagerImpl) RecordWorkflowExecutionStarted(
ctx context.Context,
request *manager.RecordWorkflowExecutionStartedRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (m *visibilityManagerRateLimited) GetName() string {
return m.delegate.GetName()
}

func (m *visibilityManagerRateLimited) GetIndexName() string {
return m.delegate.GetIndexName()
}

// Below are write APIs.

func (m *visibilityManagerRateLimited) RecordWorkflowExecutionStarted(
Expand Down
4 changes: 4 additions & 0 deletions common/persistence/visibility/visiblity_manager_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (m *visibilityManagerMetrics) GetName() string {
return m.delegate.GetName()
}

func (m *visibilityManagerMetrics) GetIndexName() string {
return m.delegate.GetIndexName()
}

func (m *visibilityManagerMetrics) RecordWorkflowExecutionStarted(
ctx context.Context,
request *manager.RecordWorkflowExecutionStartedRequest,
Expand Down
8 changes: 8 additions & 0 deletions common/resourcetest/resourceTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"go.temporal.io/server/common/persistence"
persistenceClient "go.temporal.io/server/common/persistence/client"
"go.temporal.io/server/common/persistence/serialization"
"go.temporal.io/server/common/persistence/visibility/manager"
esclient "go.temporal.io/server/common/persistence/visibility/store/elasticsearch/client"
"go.temporal.io/server/common/primitives"
"go.temporal.io/server/common/sdk"
Expand Down Expand Up @@ -96,6 +97,7 @@ type (
ClientBean *client.MockBean
ClientFactory *client.MockFactory
ESClient *esclient.MockClient
VisibilityManager *manager.MockVisibilityManager

// persistence clients

Expand Down Expand Up @@ -206,6 +208,7 @@ func NewTest(
ClientBean: clientBean,
ClientFactory: clientFactory,
ESClient: esclient.NewMockClient(controller),
VisibilityManager: manager.NewMockVisibilityManager(controller),

// persistence clients

Expand Down Expand Up @@ -373,6 +376,11 @@ func (t *Test) GetClientFactory() client.Factory {
return t.ClientFactory
}

// GetVisibilityManager for testing
func (t *Test) GetVisibilityManager() manager.VisibilityManager {
return t.VisibilityManager
}

// persistence clients

// GetMetadataManager for testing
Expand Down
16 changes: 12 additions & 4 deletions common/searchattribute/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewManager(
}

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

indexSearchAttributes, ok := saCache.searchAttributes[indexName]
if !ok {
return NameTypeMap{}, nil
if ok {
return indexSearchAttributes, nil
}

return indexSearchAttributes, nil
if indexName != "" {
// Try to look for the empty string indexName for backward compatibility: up to v1.19,
// empty string was used when Elasticsearch was not configured.
indexSearchAttributes, ok = saCache.searchAttributes[""]
if ok {
return indexSearchAttributes, nil
}
}
return NameTypeMap{}, nil
}

func (m *managerImpl) needRefreshCache(saCache cache, forceRefreshCache bool, now time.Time) bool {
Expand Down
9 changes: 3 additions & 6 deletions service/frontend/adminHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ type (

logger log.Logger
numberOfHistoryShards int32
ESConfig *esclient.Config
ESClient esclient.Client
config *Config
namespaceHandler namespace.Handler
Expand Down Expand Up @@ -127,7 +126,6 @@ type (
Config *Config
NamespaceReplicationQueue persistence.NamespaceReplicationQueue
ReplicatorNamespaceReplicationQueue persistence.NamespaceReplicationQueue
EsConfig *esclient.Config
EsClient esclient.Client
VisibilityMrg manager.VisibilityManager
Logger log.Logger
Expand Down Expand Up @@ -192,7 +190,6 @@ func NewAdminHandler(
),
eventSerializer: args.EventSerializer,
visibilityMgr: args.VisibilityMrg,
ESConfig: args.EsConfig,
ESClient: args.EsClient,
persistenceExecutionManager: args.PersistenceExecutionManager,
namespaceReplicationQueue: args.NamespaceReplicationQueue,
Expand Down Expand Up @@ -257,7 +254,7 @@ func (adh *AdminHandler) AddSearchAttributes(ctx context.Context, request *admin

indexName := request.GetIndexName()
if indexName == "" {
indexName = adh.ESConfig.GetVisibilityIndex()
indexName = adh.visibilityMgr.GetIndexName()
}

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

indexName := request.GetIndexName()
if indexName == "" {
indexName = adh.ESConfig.GetVisibilityIndex()
indexName = adh.visibilityMgr.GetIndexName()
}

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

indexName := request.GetIndexName()
if indexName == "" {
indexName = adh.ESConfig.GetVisibilityIndex()
indexName = adh.visibilityMgr.GetIndexName()
}

resp, err := adh.getSearchAttributes(ctx, indexName, "")
Expand Down
Loading

0 comments on commit dc257ce

Please sign in to comment.