diff --git a/common/searchattribute/manager.go b/common/searchattribute/manager.go index 1fd5f272bd3..9ecf8e6b198 100644 --- a/common/searchattribute/manager.go +++ b/common/searchattribute/manager.go @@ -32,6 +32,7 @@ import ( enumspb "go.temporal.io/api/enums/v1" "go.temporal.io/api/serviceerror" + "golang.org/x/exp/maps" persistencespb "go.temporal.io/server/api/persistence/v1" "go.temporal.io/server/common/clock" @@ -110,20 +111,24 @@ func (m *managerImpl) GetSearchAttributes( m.cacheUpdateMutex.Unlock() } + result := NameTypeMap{} indexSearchAttributes, ok := saCache.searchAttributes[indexName] if ok { - return indexSearchAttributes, nil + result.customSearchAttributes = maps.Clone(indexSearchAttributes.customSearchAttributes) } + // TODO (rodrigozhou): remove following block for v1.21. + // Try to look for the empty string indexName for backward compatibility: up to v1.19, + // empty string was used when Elasticsearch was not configured. + // If there's a value, merging with current index name value. This is to avoid handling + // all code references to GetSearchAttributes. 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 + maps.Copy(result.customSearchAttributes, indexSearchAttributes.customSearchAttributes) } } - return NameTypeMap{}, nil + return result, nil } func (m *managerImpl) needRefreshCache(saCache cache, forceRefreshCache bool, now time.Time) bool { diff --git a/common/searchattribute/validator.go b/common/searchattribute/validator.go index 37838cc22cc..89141a39405 100644 --- a/common/searchattribute/validator.go +++ b/common/searchattribute/validator.go @@ -92,10 +92,6 @@ func (v *Validator) Validate(searchAttributes *commonpb.SearchAttributes, namesp ) } - // TODO (rodrigozhou): this is to be backwards compatible with custom search attributes - // registered before v1.20. Ignoring error as this key might not exist. - emptyStringSaTypeMap, _ := v.searchAttributesProvider.GetSearchAttributes("", false) - for saFieldName, saPayload := range searchAttributes.GetIndexedFields() { // user search attribute cannot be a system search attribute if _, err = saTypeMap.getType(saFieldName, systemCategory); err == nil { @@ -105,9 +101,6 @@ func (v *Validator) Validate(searchAttributes *commonpb.SearchAttributes, namesp } saType, err := saTypeMap.getType(saFieldName, customCategory|predefinedCategory) - if err != nil { - saType, err = emptyStringSaTypeMap.getType(saFieldName, customCategory) - } if err != nil { if errors.Is(err, ErrInvalidName) { return v.validationError(