Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get custom search attributes mapper in namespace registry #4317

Merged
merged 1 commit into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions common/namespace/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type (
// State, ReplicationState, ActiveCluster, or isGlobalNamespace config changed.
RegisterStateChangeCallback(key any, cb StateChangeCallbackFn)
UnregisterStateChangeCallback(key any)
// GetCustomSearchAttributesMapper is a temporary solution to be able to get search attributes
// with from persistence if forceSearchAttributesCacheRefreshOnRead is true.
GetCustomSearchAttributesMapper(name Name) (CustomSearchAttributesMapper, error)
}

registry struct {
Expand Down Expand Up @@ -172,6 +175,9 @@ type (
// readthroughNotFoundCache stores namespaces that missed the above caches
// AND was not found when reading through to the persistence layer
readthroughNotFoundCache cache.Cache

// Temporary solution to force read search attributes from persistence
forceSearchAttributesCacheRefreshOnRead dynamicconfig.BoolPropertyFn
}
)

Expand All @@ -181,6 +187,7 @@ func NewRegistry(
persistence Persistence,
enableGlobalNamespaces bool,
refreshInterval dynamicconfig.DurationPropertyFn,
forceSearchAttributesCacheRefreshOnRead dynamicconfig.BoolPropertyFn,
metricsHandler metrics.Handler,
logger log.Logger,
) Registry {
Expand All @@ -196,6 +203,8 @@ func NewRegistry(
refreshInterval: refreshInterval,
stateChangeCallbacks: make(map[any]StateChangeCallbackFn),
readthroughNotFoundCache: cache.New(cacheMaxSize, &readthroughNotFoundCacheOpts),

forceSearchAttributesCacheRefreshOnRead: forceSearchAttributesCacheRefreshOnRead,
}
return reg
}
Expand Down Expand Up @@ -335,6 +344,24 @@ func (r *registry) GetNamespaceName(
return ns.Name(), nil
}

// GetCustomSearchAttributesMapper is a temporary solution to be able to get search attributes
// with from persistence if forceSearchAttributesCacheRefreshOnRead is true.
func (r *registry) GetCustomSearchAttributesMapper(name Name) (CustomSearchAttributesMapper, error) {
var ns *Namespace
var err error
if r.forceSearchAttributesCacheRefreshOnRead() {
r.readthroughLock.Lock()
defer r.readthroughLock.Unlock()
ns, err = r.getNamespaceByNamePersistence(name)
} else {
ns, err = r.GetNamespace(name)
}
if err != nil {
return CustomSearchAttributesMapper{}, err
}
return ns.CustomSearchAttributesMapper(), nil
}

func (r *registry) refreshLoop(ctx context.Context) error {
// Put timer events on our channel so we can select on just one below.
go func() {
Expand Down
15 changes: 15 additions & 0 deletions common/namespace/registry_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/namespace/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (s *registrySuite) SetupTest() {
s.regPersistence,
true,
dynamicconfig.GetDurationPropertyFn(time.Second),
dynamicconfig.GetBoolPropertyFn(false),
metrics.NoopMetricsHandler,
log.NewTestLogger())
}
Expand Down
1 change: 1 addition & 0 deletions common/resource/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func NamespaceRegistryProvider(
metadataManager,
clusterMetadata.IsGlobalNamespaceEnabled(),
dynamicCollection.GetDurationProperty(dynamicconfig.NamespaceCacheRefreshInterval, 10*time.Second),
dynamicCollection.GetBoolProperty(dynamicconfig.ForceSearchAttributesCacheRefreshOnRead, false),
metricsHandler,
logger,
)
Expand Down
3 changes: 1 addition & 2 deletions common/searchattribute/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ func (m *mapperProviderImpl) GetMapper(nsName namespace.Name) (Mapper, error) {
if !m.enableMapperFromNamespace {
return &noopMapper{}, nil
}
ns, err := m.namespaceRegistry.GetNamespace(nsName)
saMapper, err := m.namespaceRegistry.GetCustomSearchAttributesMapper(nsName)
if err != nil {
return nil, err
}
saMapper := ns.CustomSearchAttributesMapper()
// if there's an error, it returns an empty object, which is expected here
emptyStringNameTypeMap, _ := m.searchAttributesProvider.GetSearchAttributes("", false)
return &backCompMapper_v1_20{
Expand Down