Files
tasks/service/frontend/cluster_removal_validation.go
Qian ChenandGitHub af4106ec64 address comments on cluster removal validation (#10414)
## What changed?
Disallow removal of remote cluster only for global namespaces with
multiple clusters.

## Why?
Treat global namespace with only one cluster the same as local clusters.
This change addresses a comment on
https://github.com/temporalio/temporal/pull/10366 and makes the behavior
more explicit.

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2026-05-29 10:49:11 -07:00

39 lines
1.2 KiB
Go

package frontend
import (
"fmt"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common/namespace"
)
// validateClusterNotInUseByNamespaces returns an error if any active
// multi-cluster namespace still references clusterName in its replication
// cluster list. Single-cluster namespaces (local, or global with only one
// cluster) are ignored because they do not replicate. Namespaces in
// NAMESPACE_STATE_DELETED are ignored because the delete worker is tearing
// them down and cluster connectivity is not required for that teardown. The
// check reads from the in-memory namespace registry, which may lag persistence
// by up to the configured refresh interval.
func validateClusterNotInUseByNamespaces(
namespaceRegistry namespace.Registry,
clusterName string,
) error {
for _, ns := range namespaceRegistry.GetAllNamespaces() {
if ns.ReplicationPolicy() != namespace.ReplicationPolicyMultiCluster {
continue
}
if ns.State() == enumspb.NAMESPACE_STATE_DELETED {
continue
}
if ns.IsOnCluster(clusterName) {
return serviceerror.NewFailedPrecondition(fmt.Sprintf(
"cannot remove cluster %q: still referenced by namespace %q",
clusterName, ns.Name().String(),
))
}
}
return nil
}