@@ -644,6 +644,15 @@ func ApplyClusterMetadataConfigProvider(
644
644
}
645
645
defer clusterMetadataManager .Close ()
646
646
647
+ var indexName string
648
+ var initialIndexSearchAttributes map [string ]* persistencespb.IndexSearchAttributes
649
+ if config .Persistence .IsSQLVisibilityStore () {
650
+ indexName = config .Persistence .DataStores [config .Persistence .VisibilityStore ].SQL .DatabaseName
651
+ initialIndexSearchAttributes = map [string ]* persistencespb.IndexSearchAttributes {
652
+ indexName : searchattribute .GetSqlDbIndexSearchAttributes (),
653
+ }
654
+ }
655
+
647
656
clusterData := config .ClusterMetadata
648
657
for clusterName , clusterInfo := range clusterData .ClusterInformation {
649
658
if clusterName != clusterData .CurrentClusterName {
@@ -671,6 +680,7 @@ func ApplyClusterMetadataConfigProvider(
671
680
IsGlobalNamespaceEnabled : clusterData .EnableGlobalNamespace ,
672
681
IsConnectionEnabled : clusterInfo .Enabled ,
673
682
UseClusterIdMembership : true , // Enable this for new cluster after 1.19. This is to prevent two clusters join into one ring.
683
+ IndexSearchAttributes : initialIndexSearchAttributes ,
674
684
},
675
685
})
676
686
if err != nil {
@@ -681,21 +691,51 @@ func ApplyClusterMetadataConfigProvider(
681
691
continue
682
692
}
683
693
684
- resp , err := clusterMetadataManager .GetClusterMetadata (ctx , & persistence.GetClusterMetadataRequest {
685
- ClusterName : clusterName ,
686
- })
694
+ resp , err := clusterMetadataManager .GetClusterMetadata (
695
+ ctx ,
696
+ & persistence.GetClusterMetadataRequest {ClusterName : clusterName },
697
+ )
687
698
if err != nil {
688
699
return config .ClusterMetadata , config .Persistence , fmt .Errorf ("error while fetching cluster metadata: %w" , err )
689
700
}
690
701
702
+ currentMetadata := resp .ClusterMetadata
703
+
704
+ // TODO (rodrigozhou): Remove this block for v1.21.
705
+ // Handle registering custom search attributes when upgrading to v1.20.
706
+ if config .Persistence .IsSQLVisibilityStore () {
707
+ needSave := false
708
+ if currentMetadata .IndexSearchAttributes == nil {
709
+ currentMetadata .IndexSearchAttributes = initialIndexSearchAttributes
710
+ needSave = true
711
+ } else if _ , ok := currentMetadata .IndexSearchAttributes [indexName ]; ! ok {
712
+ currentMetadata .IndexSearchAttributes [indexName ] = searchattribute .GetSqlDbIndexSearchAttributes ()
713
+ needSave = true
714
+ }
715
+
716
+ if needSave {
717
+ _ , err := clusterMetadataManager .SaveClusterMetadata (
718
+ ctx ,
719
+ & persistence.SaveClusterMetadataRequest {ClusterMetadata : currentMetadata },
720
+ )
721
+ if err != nil {
722
+ logger .Warn (
723
+ "Failed to register search attributes." ,
724
+ tag .Error (err ),
725
+ tag .ClusterName (clusterName ),
726
+ )
727
+ }
728
+ logger .Info ("Successfully registered search attributes." , tag .ClusterName (clusterName ))
729
+ }
730
+ }
731
+
691
732
// Allow updating cluster metadata if global namespace is disabled
692
733
if ! resp .IsGlobalNamespaceEnabled && clusterData .EnableGlobalNamespace {
693
- currentMetadata := resp .ClusterMetadata
694
734
currentMetadata .IsGlobalNamespaceEnabled = clusterData .EnableGlobalNamespace
695
735
currentMetadata .InitialFailoverVersion = clusterInfo .InitialFailoverVersion
696
736
currentMetadata .FailoverVersionIncrement = clusterData .FailoverVersionIncrement
697
737
698
- applied , err = clusterMetadataManager .SaveClusterMetadata (
738
+ applied , err : = clusterMetadataManager .SaveClusterMetadata (
699
739
ctx ,
700
740
& persistence.SaveClusterMetadataRequest {
701
741
ClusterMetadata : currentMetadata ,
0 commit comments