Skip to content

Commit

Permalink
Update Master cluster to Primary cluster (cadence-workflow#4185)
Browse files Browse the repository at this point in the history
  • Loading branch information
yux0 authored May 10, 2021
1 parent 95713db commit b2adb71
Show file tree
Hide file tree
Showing 26 changed files with 124 additions and 115 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can find a list of previous releases on the [github releases](https://github
- Added GRPC support. Cadence server will accept requests on both TChannel and GRPC. With dynamic config flag `system.enableGRPCOutbound` it will also switch to GRPC communication internally between server components.

### Fixed
- Fixed a bug where an error message is always displayed in Cadence UI `persistence max qps reached for list operations` on the workflow list screen (#3958)
- This change contains breaking change on user config. The masterClusterName config key is deprecated and is replaced with primaryClusterName key. (#4185)

### Changed
- Bump CLI version to v0.18.3 (#3959)
Expand Down
9 changes: 8 additions & 1 deletion cmd/server/cadence/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,18 @@ func (s *server) startService() common.Daemon {

params.MetricsClient = metrics.NewClient(params.MetricScope, service.GetMetricsServiceIdx(params.Name, params.Logger))

//TODO: remove this after 0.23 and mention a breaking change in config.
primaryClusterName := clusterMetadata.PrimaryClusterName
if len(primaryClusterName) == 0 {
primaryClusterName = clusterMetadata.MasterClusterName
log.Println("[Warning]MasterClusterName config is deprecated. " +
"Please replace it with PrimaryClusterName.")
}
params.ClusterMetadata = cluster.NewMetadata(
params.Logger,
dc.GetBoolProperty(dynamicconfig.EnableGlobalDomain, clusterMetadata.EnableGlobalDomain),
clusterMetadata.FailoverVersionIncrement,
clusterMetadata.MasterClusterName,
primaryClusterName,
clusterMetadata.CurrentClusterName,
clusterMetadata.ClusterInformation,
)
Expand Down
34 changes: 17 additions & 17 deletions common/cluster/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ type (
// IsGlobalDomainEnabled whether the global domain is enabled,
// this attr should be discarded when cross DC is made public
IsGlobalDomainEnabled() bool
// IsMasterCluster whether current cluster is master cluster
IsMasterCluster() bool
// IsPrimaryCluster whether current cluster is the primary cluster
IsPrimaryCluster() bool
// GetNextFailoverVersion return the next failover version for domain failover
GetNextFailoverVersion(string, int64) int64
// IsVersionFromSameCluster return true if 2 version are used for the same cluster
IsVersionFromSameCluster(version1 int64, version2 int64) bool
// GetMasterClusterName return the master cluster name
GetMasterClusterName() string
// GetPrimaryClusterName return the primary cluster name
GetPrimaryClusterName() string
// GetCurrentClusterName return the current cluster name
GetCurrentClusterName() string
// GetAllClusterInfo return the all cluster name -> corresponding info
Expand All @@ -60,9 +60,9 @@ type (
enableGlobalDomain dynamicconfig.BoolPropertyFn
// failoverVersionIncrement is the increment of each cluster's version when failover happen
failoverVersionIncrement int64
// masterClusterName is the name of the master cluster, only the master cluster can register / update domain
// primaryClusterName is the name of the primary cluster, only the primary cluster can register / update domain
// all clusters can do domain failover
masterClusterName string
primaryClusterName string
// currentClusterName is the name of the current cluster
currentClusterName string
// clusterInfo contains all cluster name -> corresponding information
Expand All @@ -77,15 +77,15 @@ func NewMetadata(
logger log.Logger,
enableGlobalDomain dynamicconfig.BoolPropertyFn,
failoverVersionIncrement int64,
masterClusterName string,
primaryClusterName string,
currentClusterName string,
clusterInfo map[string]config.ClusterInformation,
) Metadata {

if len(clusterInfo) == 0 {
panic("Empty cluster information")
} else if len(masterClusterName) == 0 {
panic("Master cluster name is empty")
} else if len(primaryClusterName) == 0 {
panic("Primary cluster name is empty")
} else if len(currentClusterName) == 0 {
panic("Current cluster name is empty")
} else if failoverVersionIncrement == 0 {
Expand Down Expand Up @@ -114,8 +114,8 @@ func NewMetadata(
if _, ok := clusterInfo[currentClusterName]; !ok {
panic("Current cluster is not specified in cluster info")
}
if _, ok := clusterInfo[masterClusterName]; !ok {
panic("Master cluster is not specified in cluster info")
if _, ok := clusterInfo[primaryClusterName]; !ok {
panic("Primary cluster is not specified in cluster info")
}
if len(versionToClusterName) != len(clusterInfo) {
panic("Cluster info initial versions have duplicates")
Expand All @@ -125,7 +125,7 @@ func NewMetadata(
logger: logger,
enableGlobalDomain: enableGlobalDomain,
failoverVersionIncrement: failoverVersionIncrement,
masterClusterName: masterClusterName,
primaryClusterName: primaryClusterName,
currentClusterName: currentClusterName,
clusterInfo: clusterInfo,
versionToClusterName: versionToClusterName,
Expand Down Expand Up @@ -160,13 +160,13 @@ func (metadata *metadataImpl) IsVersionFromSameCluster(version1 int64, version2
return (version1-version2)%metadata.failoverVersionIncrement == 0
}

func (metadata *metadataImpl) IsMasterCluster() bool {
return metadata.masterClusterName == metadata.currentClusterName
func (metadata *metadataImpl) IsPrimaryCluster() bool {
return metadata.primaryClusterName == metadata.currentClusterName
}

// GetMasterClusterName return the master cluster name
func (metadata *metadataImpl) GetMasterClusterName() string {
return metadata.masterClusterName
// GetPrimaryClusterName return the primary cluster name
func (metadata *metadataImpl) GetPrimaryClusterName() string {
return metadata.primaryClusterName
}

// GetCurrentClusterName return the current cluster name
Expand Down
10 changes: 5 additions & 5 deletions common/cluster/metadataTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ var (
)

// GetTestClusterMetadata return an cluster metadata instance, which is initialized
func GetTestClusterMetadata(enableGlobalDomain bool, isMasterCluster bool) Metadata {
masterClusterName := TestCurrentClusterName
if !isMasterCluster {
masterClusterName = TestAlternativeClusterName
func GetTestClusterMetadata(enableGlobalDomain bool, isPrimaryCluster bool) Metadata {
primaryClusterName := TestCurrentClusterName
if !isPrimaryCluster {
primaryClusterName = TestAlternativeClusterName
}

if enableGlobalDomain {
return NewMetadata(
loggerimpl.NewNopLogger(),
dynamicconfig.GetBoolPropertyFn(true),
TestFailoverVersionIncrement,
masterClusterName,
primaryClusterName,
TestCurrentClusterName,
TestAllClusterInfo,
)
Expand Down
24 changes: 12 additions & 12 deletions common/cluster/metadata_mock.go

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

4 changes: 3 additions & 1 deletion common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ type (
EnableGlobalDomain bool `yaml:"enableGlobalDomain"`
// FailoverVersionIncrement is the increment of each cluster version when failover happens
FailoverVersionIncrement int64 `yaml:"failoverVersionIncrement"`
// MasterClusterName is the master cluster name, only the master cluster can register / update domain
// PrimaryClusterName is the primary cluster name, only the primary cluster can register / update domain
// all clusters can do domain failover
PrimaryClusterName string `yaml:"primaryClusterName"`
// MasterClusterName is deprecated. Please use PrimaryClusterName.
MasterClusterName string `yaml:"masterClusterName"`
// CurrentClusterName is the name of the current cluster
CurrentClusterName string `yaml:"currentClusterName"`
Expand Down
4 changes: 2 additions & 2 deletions common/domain/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
)

var (
// err indicating that this cluster is not the master, so cannot do domain registration or update
errNotMasterCluster = &types.BadRequestError{Message: "Cluster is not master cluster, cannot do domain registration or domain update."}
// err indicating that this cluster is not the primary, so cannot do domain registration or update
errNotPrimaryCluster = &types.BadRequestError{Message: "Cluster is not primary cluster, cannot do domain registration or domain update."}
errCannotRemoveClustersFromDomain = &types.BadRequestError{Message: "Cannot remove existing replicated clusters from a domain."}
errActiveClusterNotInClusters = &types.BadRequestError{Message: "Active cluster is not contained in all clusters."}
errCannotDoDomainFailoverAndUpdate = &types.BadRequestError{Message: "Cannot set active cluster to current cluster when other parameters are set."}
Expand Down
12 changes: 6 additions & 6 deletions common/domain/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func (d *handlerImpl) RegisterDomain(
}
} else {
// cluster global domain enabled
if !d.clusterMetadata.IsMasterCluster() && registerRequest.GetIsGlobalDomain() {
return errNotMasterCluster
if !d.clusterMetadata.IsPrimaryCluster() && registerRequest.GetIsGlobalDomain() {
return errNotPrimaryCluster
}
}

Expand Down Expand Up @@ -486,8 +486,8 @@ func (d *handlerImpl) UpdateDomain(
return nil, errCannotDoDomainFailoverAndUpdate
}

if !activeClusterChanged && !d.clusterMetadata.IsMasterCluster() {
return nil, errNotMasterCluster
if !activeClusterChanged && !d.clusterMetadata.IsPrimaryCluster() {
return nil, errNotPrimaryCluster
}
} else {
if err := d.domainAttrValidator.validateDomainReplicationConfigForLocalDomain(
Expand Down Expand Up @@ -590,8 +590,8 @@ func (d *handlerImpl) DeprecateDomain(
}

isGlobalDomain := getResponse.IsGlobalDomain
if isGlobalDomain && !d.clusterMetadata.IsMasterCluster() {
return errNotMasterCluster
if isGlobalDomain && !d.clusterMetadata.IsPrimaryCluster() {
return errNotPrimaryCluster
}
getResponse.ConfigVersion = getResponse.ConfigVersion + 1
getResponse.Info.Status = persistence.DomainStatusDeprecated
Expand Down
Loading

0 comments on commit b2adb71

Please sign in to comment.