Skip to content

Commit

Permalink
Fix set up search attributes in secondary SQL visibility (#5143)
Browse files Browse the repository at this point in the history
<!-- Describe what has changed in this PR -->
**What changed?**
Fix setting up pre-allocated search attributes when a secondary SQL
visibility is added.

<!-- Tell your future self why have you made these changes -->
**Why?**
PR #4531 removed code that
did this.

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
Started single SQL visibility, and then added secondary SQL visibility.
Checked cluster metadata, it looks right.

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**
No.

<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
No.
  • Loading branch information
rodrigozhou committed Nov 22, 2023
1 parent 1f04629 commit 38f0eb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
25 changes: 18 additions & 7 deletions temporal/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,12 @@ func ApplyClusterMetadataConfigProvider(
}
defer clusterMetadataManager.Close()

var sqlIndexNames []string
initialIndexSearchAttributes := make(map[string]*persistencespb.IndexSearchAttributes)
if ds := svc.Persistence.GetVisibilityStoreConfig(); ds.SQL != nil {
indexName := ds.GetIndexName()
sqlIndexNames = append(sqlIndexNames, indexName)
initialIndexSearchAttributes[indexName] = searchattribute.GetSqlDbIndexSearchAttributes()
initialIndexSearchAttributes[ds.GetIndexName()] = searchattribute.GetSqlDbIndexSearchAttributes()
}
if ds := svc.Persistence.GetSecondaryVisibilityStoreConfig(); ds.SQL != nil {
indexName := ds.GetIndexName()
sqlIndexNames = append(sqlIndexNames, indexName)
initialIndexSearchAttributes[indexName] = searchattribute.GetSqlDbIndexSearchAttributes()
initialIndexSearchAttributes[ds.GetIndexName()] = searchattribute.GetSqlDbIndexSearchAttributes()
}

clusterMetadata := svc.ClusterMetadata
Expand All @@ -656,6 +651,7 @@ func ApplyClusterMetadataConfigProvider(
ctx,
clusterMetadataManager,
svc,
initialIndexSearchAttributes,
resp,
); updateErr != nil {
return svc.ClusterMetadata, svc.Persistence, updateErr
Expand Down Expand Up @@ -792,6 +788,7 @@ func updateCurrentClusterMetadataRecord(
ctx context.Context,
clusterMetadataManager persistence.ClusterMetadataManager,
svc *config.Config,
initialIndexSearchAttributes map[string]*persistencespb.IndexSearchAttributes,
currentClusterDBRecord *persistence.GetClusterMetadataResponse,
) error {
updateDBRecord := false
Expand All @@ -814,6 +811,20 @@ func updateCurrentClusterMetadataRecord(
updateDBRecord = true
}

if len(initialIndexSearchAttributes) > 0 {
if currentClusterDBRecord.IndexSearchAttributes == nil {
currentClusterDBRecord.IndexSearchAttributes = initialIndexSearchAttributes
updateDBRecord = true
} else {
for indexName, initialValue := range initialIndexSearchAttributes {
if _, ok := currentClusterDBRecord.IndexSearchAttributes[indexName]; !ok {
currentClusterDBRecord.IndexSearchAttributes[indexName] = initialValue
updateDBRecord = true
}
}
}
}

if !updateDBRecord {
return nil
}
Expand Down
1 change: 1 addition & 0 deletions temporal/fx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestUpdateCurrentClusterMetadataRecord(t *testing.T) {
context.TODO(),
mockClusterMetadataManager,
cfg,
nil,
updateRecord,
)
require.NoError(t, err)
Expand Down

0 comments on commit 38f0eb2

Please # to comment.