From 38f0eb298bd6c7533758eb481838ba784e411f30 Mon Sep 17 00:00:00 2001 From: Rodrigo Zhou Date: Wed, 22 Nov 2023 12:04:46 -0600 Subject: [PATCH] Fix set up search attributes in secondary SQL visibility (#5143) **What changed?** Fix setting up pre-allocated search attributes when a secondary SQL visibility is added. **Why?** PR https://github.com/temporalio/temporal/pull/4531 removed code that did this. **How did you test it?** Started single SQL visibility, and then added secondary SQL visibility. Checked cluster metadata, it looks right. **Potential risks** No. **Is hotfix candidate?** No. --- temporal/fx.go | 25 ++++++++++++++++++------- temporal/fx_test.go | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/temporal/fx.go b/temporal/fx.go index 642395c773f..7ff1d1cdf62 100644 --- a/temporal/fx.go +++ b/temporal/fx.go @@ -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 @@ -656,6 +651,7 @@ func ApplyClusterMetadataConfigProvider( ctx, clusterMetadataManager, svc, + initialIndexSearchAttributes, resp, ); updateErr != nil { return svc.ClusterMetadata, svc.Persistence, updateErr @@ -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 @@ -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 } diff --git a/temporal/fx_test.go b/temporal/fx_test.go index 5fbb4d5abe3..03f0dff1d85 100644 --- a/temporal/fx_test.go +++ b/temporal/fx_test.go @@ -95,6 +95,7 @@ func TestUpdateCurrentClusterMetadataRecord(t *testing.T) { context.TODO(), mockClusterMetadataManager, cfg, + nil, updateRecord, ) require.NoError(t, err)