Skip to content

Commit af00719

Browse files
authored
Merge custom search attributes from index name with empty string key (#3877)
1 parent 2bc48d2 commit af00719

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

common/searchattribute/manager.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
enumspb "go.temporal.io/api/enums/v1"
3434
"go.temporal.io/api/serviceerror"
35+
"golang.org/x/exp/maps"
3536

3637
persistencespb "go.temporal.io/server/api/persistence/v1"
3738
"go.temporal.io/server/common/clock"
@@ -110,20 +111,24 @@ func (m *managerImpl) GetSearchAttributes(
110111
m.cacheUpdateMutex.Unlock()
111112
}
112113

114+
result := NameTypeMap{}
113115
indexSearchAttributes, ok := saCache.searchAttributes[indexName]
114116
if ok {
115-
return indexSearchAttributes, nil
117+
result.customSearchAttributes = maps.Clone(indexSearchAttributes.customSearchAttributes)
116118
}
117119

120+
// TODO (rodrigozhou): remove following block for v1.21.
121+
// Try to look for the empty string indexName for backward compatibility: up to v1.19,
122+
// empty string was used when Elasticsearch was not configured.
123+
// If there's a value, merging with current index name value. This is to avoid handling
124+
// all code references to GetSearchAttributes.
118125
if indexName != "" {
119-
// Try to look for the empty string indexName for backward compatibility: up to v1.19,
120-
// empty string was used when Elasticsearch was not configured.
121126
indexSearchAttributes, ok = saCache.searchAttributes[""]
122127
if ok {
123-
return indexSearchAttributes, nil
128+
maps.Copy(result.customSearchAttributes, indexSearchAttributes.customSearchAttributes)
124129
}
125130
}
126-
return NameTypeMap{}, nil
131+
return result, nil
127132
}
128133

129134
func (m *managerImpl) needRefreshCache(saCache cache, forceRefreshCache bool, now time.Time) bool {

common/searchattribute/validator.go

-7
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ func (v *Validator) Validate(searchAttributes *commonpb.SearchAttributes, namesp
9292
)
9393
}
9494

95-
// TODO (rodrigozhou): this is to be backwards compatible with custom search attributes
96-
// registered before v1.20. Ignoring error as this key might not exist.
97-
emptyStringSaTypeMap, _ := v.searchAttributesProvider.GetSearchAttributes("", false)
98-
9995
for saFieldName, saPayload := range searchAttributes.GetIndexedFields() {
10096
// user search attribute cannot be a system search attribute
10197
if _, err = saTypeMap.getType(saFieldName, systemCategory); err == nil {
@@ -105,9 +101,6 @@ func (v *Validator) Validate(searchAttributes *commonpb.SearchAttributes, namesp
105101
}
106102

107103
saType, err := saTypeMap.getType(saFieldName, customCategory|predefinedCategory)
108-
if err != nil {
109-
saType, err = emptyStringSaTypeMap.getType(saFieldName, customCategory)
110-
}
111104
if err != nil {
112105
if errors.Is(err, ErrInvalidName) {
113106
return v.validationError(

0 commit comments

Comments
 (0)