Files
tasks/common/namespace/nsreplication/replication_admitter.go
jiechenzandGitHub 1feb473d2b Add NamespaceReplicationAdmitter extension point for custom cluster replication admission logic (#10038)
## What changed?

This PR extracts the “should this cluster process an incoming namespace
replication task?” decision into a new `NamespaceReplicationAdmitter`
interface.

Allows custom override that decides whether the current cluster should
admit an incoming namespace replication task for a namespace that does
not yet exist locally.

> Note: The default behavior is unchanged.

## Why?
Allow integrate with custom `admitter` to override the replication
logic.

## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2026-04-23 15:16:15 -07:00

43 lines
1.3 KiB
Go

package nsreplication
import (
"context"
replicationpb "go.temporal.io/api/replication/v1"
replicationspb "go.temporal.io/server/api/replication/v1"
)
// NamespaceReplicationAdmitter decides whether to process a namespace
// replication task when the namespace does not yet exist locally.
type NamespaceReplicationAdmitter interface {
Admit(ctx context.Context, currentCluster string, task *replicationspb.NamespaceTaskAttributes) bool
}
// DefaultAdmitter is the default implementation: admit the task iff the
// current cluster is listed in task.ReplicationConfig.Clusters.
type DefaultAdmitter struct{}
// NewDefaultAdmitter creates the default NamespaceReplicationAdmitter.
func NewDefaultAdmitter() NamespaceReplicationAdmitter {
return &DefaultAdmitter{}
}
// Admit returns true iff currentCluster appears in the task's replication
// config cluster list.
func (*DefaultAdmitter) Admit(
_ context.Context,
currentCluster string,
task *replicationspb.NamespaceTaskAttributes,
) bool {
return checkClusterIncludedInReplicationConfig(currentCluster, task.GetReplicationConfig().GetClusters())
}
func checkClusterIncludedInReplicationConfig(clusterName string, repCfg []*replicationpb.ClusterReplicationConfig) bool {
for _, cluster := range repCfg {
if clusterName == cluster.GetClusterName() {
return true
}
}
return false
}