func (e BadBinaryError) Operator() string {
	return e.info.Operator
}
Operator returns the operator associated with this bad binary.
package namespace
import (
	"hash/fnv"
	"strconv"
	"time"
	namespacepb "go.temporal.io/api/namespace/v1"
	persistencespb "go.temporal.io/server/api/persistence/v1"
	"go.temporal.io/server/common/persistence"
	"go.temporal.io/server/common/primitives/timestamp"
)
const (
	SampleRetentionKey = "sample_retention_days"
	SampleRateKey = "sample_retention_rate"
)
type (
	Mutation interface {
		apply(*persistence.GetNamespaceResponse)
	}
	BadBinaryError struct {
		cksum string
		info  *namespacepb.BadBinaryInfo
	}
	Namespaces []*Namespace
	Namespace struct {
		info                        persistencespb.NamespaceInfo
		config                      persistencespb.NamespaceConfig
		replicationConfig           persistencespb.NamespaceReplicationConfig
		configVersion               int64
		failoverVersion             int64
		isGlobalNamespace           bool
		failoverNotificationVersion int64
		notificationVersion         int64
	}
)
func FromPersistentState(record *persistence.GetNamespaceResponse) *Namespace {
	return &Namespace{
		info:                        *record.Namespace.Info,
		config:                      *record.Namespace.Config,
		replicationConfig:           *record.Namespace.ReplicationConfig,
		configVersion:               record.Namespace.ConfigVersion,
		failoverVersion:             record.Namespace.FailoverVersion,
		isGlobalNamespace:           record.IsGlobalNamespace,
		failoverNotificationVersion: record.Namespace.FailoverNotificationVersion,
		notificationVersion:         record.NotificationVersion,
	}
}
func (ns *Namespace) Clone(ms ...Mutation) *Namespace {
	newns := *ns
	r := persistence.GetNamespaceResponse{
		Namespace: &persistencespb.NamespaceDetail{
			Info:                        &newns.info,
			Config:                      &newns.config,
			ReplicationConfig:           &newns.replicationConfig,
			ConfigVersion:               newns.configVersion,
			FailoverNotificationVersion: newns.failoverNotificationVersion,
			FailoverVersion:             newns.failoverVersion,
		},
		IsGlobalNamespace:   newns.isGlobalNamespace,
		NotificationVersion: newns.notificationVersion,
	}
	for _, m := range ms {
		m.apply(&r)
	}
	return FromPersistentState(&r)
}
func (ns *Namespace) VisibilityArchivalState() ArchivalState {
	return ArchivalState{
		State: ns.config.VisibilityArchivalState,
		URI:   ns.config.VisibilityArchivalUri,
	}
}
func (ns *Namespace) HistoryArchivalState() ArchivalState {
	return ArchivalState{
		State: ns.config.HistoryArchivalState,
		URI:   ns.config.HistoryArchivalUri,
	}
}
func (ns *Namespace) VerifyBinaryChecksum(cksum string) error {
	badBinMap := ns.config.GetBadBinaries().GetBinaries()
	if badBinMap == nil {
		return nil
	}
	if info, ok := badBinMap[cksum]; ok {
		return BadBinaryError{cksum: cksum, info: info}
	}
	return nil
}
func (ns *Namespace) ID() string {
	return ns.info.Id
}
func (ns *Namespace) Name() string {
	return ns.info.Name
}
func (ns *Namespace) ActiveClusterName() string {
	return ns.replicationConfig.ActiveClusterName
}
func (ns *Namespace) ClusterNames() []string {
	out := make([]string, len(ns.replicationConfig.Clusters))
	copy(out, ns.replicationConfig.Clusters)
	return out
}
func (ns *Namespace) ConfigVersion() int64 {
	return ns.configVersion
}
func (ns *Namespace) FailoverVersion() int64 {
	return ns.failoverVersion
}
func (ns *Namespace) IsGlobalNamespace() bool {
	return ns.isGlobalNamespace
}
func (ns *Namespace) FailoverNotificationVersion() int64 {
	return ns.failoverNotificationVersion
}
func (ns *Namespace) NotificationVersion() int64 {
	return ns.notificationVersion
}
func (ns *Namespace) ActiveInCluster(clusterName string) bool {
	if !ns.isGlobalNamespace {
		return true
	}
	return clusterName == ns.ActiveClusterName()
}
func (ns *Namespace) ReplicationPolicy() ReplicationPolicy {
	if ns.isGlobalNamespace && len(ns.replicationConfig.Clusters) > 1 {
		return ReplicationPolicyMultiCluster
	}
	return ReplicationPolicyOneCluster
}
func (t Namespaces) Len() int {
	return len(t)
}
func (t Namespaces) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}
func (t Namespaces) Less(i, j int) bool {
	return t[i].notificationVersion < t[j].notificationVersion
}
func (ns *Namespace) Retention(workflowID string) time.Duration {
	if ns.config.Retention == nil {
		return 0
	}
	if ns.IsSampledForLongerRetention(workflowID) {
		if sampledRetentionValue, ok := ns.info.Data[SampleRetentionKey]; ok {
			sampledRetentionDays, err := strconv.Atoi(sampledRetentionValue)
			sampledRetention := *timestamp.DurationFromDays(int32(sampledRetentionDays))
			if err != nil || sampledRetention < *ns.config.Retention {
				return *ns.config.Retention
			}
			return sampledRetention
		}
	}
	return *ns.config.Retention
}
func (ns *Namespace) IsSampledForLongerRetentionEnabled(string) bool {
	_, ok := ns.info.Data[SampleRateKey]
	return ok
}
func (ns *Namespace) IsSampledForLongerRetention(workflowID string) bool {
	sampledRateValue, ok := ns.info.Data[SampleRateKey]
	if !ok {
		return false
	}
	sampledRate, err := strconv.ParseFloat(sampledRateValue, 64)
	if err != nil {
		return false
	}
	h := fnv.New32a()
	_, err = h.Write([]byte(workflowID))
	if err != nil {
		return false
	}
	hash := h.Sum32()
	r := float64(hash%1000) / float64(1000)
	return r < sampledRate
}
func (e BadBinaryError) Error() string {
	return e.info.Reason
}
func (e BadBinaryError) Reason() string {
	return e.info.Reason
}