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)