Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

graceful-takeover-auto switchover failed. when i set true for PreventCrossDataCenterMasterFailover. #1406

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
70 changes: 58 additions & 12 deletions go/inst/instance_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -2202,25 +2202,71 @@ func getPriorityBinlogFormatForCandidate(replicas [](*Instance)) (priorityBinlog
return sorted.First(), nil
}

// getPriorityDataCenterForCandidate returns the replica datacenter found
// among given instances. This will be used for choosing best candidate for promotion.
func getPriorityDataCenterForCandidate(replicas [](*Instance)) (priorityDataCenter string, err error) {
if len(replicas) == 0 {
return "", log.Errorf("empty replicas list in getPriorityBinlogFormatForCandidate")
}
candidate := ""
for _, replica := range replicas {
candidate = replica.DataCenter
return candidate, nil
}
return "", nil
}

// IsDataCenterCandiadateReplica compare master's datacenter and replica datacenter.
// if master's datacenter eq replica datacenter return true
func IsDataCenterCandiadateReplica(priorityDataCenter string, replica *Instance) bool {
masterOfDesignatedInstance, _ := GetInstanceMaster(replica)
if masterOfDesignatedInstance.DataCenter == priorityDataCenter {
log.Debugf("instance %+v is banned because of promotion rule", replica.Key)
return true
}
if matched, _ := regexp.MatchString(config.Config.DataCenterPattern, replica.Key.Hostname); matched {
return true
}
return false
}

// chooseCandidateReplica
func chooseCandidateReplica(replicas [](*Instance)) (candidateReplica *Instance, aheadReplicas, equalReplicas, laterReplicas, cannotReplicateReplicas [](*Instance), err error) {
if len(replicas) == 0 {
return candidateReplica, aheadReplicas, equalReplicas, laterReplicas, cannotReplicateReplicas, fmt.Errorf("No replicas found given in chooseCandidateReplica")
}
priorityMajorVersion, _ := getPriorityMajorVersionForCandidate(replicas)
priorityBinlogFormat, _ := getPriorityBinlogFormatForCandidate(replicas)

for _, replica := range replicas {
replica := replica
if isGenerallyValidAsCandidateReplica(replica) &&
!IsBannedFromBeingCandidateReplica(replica) &&
!IsSmallerMajorVersion(priorityMajorVersion, replica.MajorVersionString()) &&
!IsSmallerBinlogFormat(priorityBinlogFormat, replica.Binlog_format) {
// this is the one
candidateReplica = replica
break
}
}
// priorityDataCenter return boll for candidate
priorityDataCenter, _ := getPriorityDataCenterForCandidate(replicas)


if config.Config.PreventCrossDataCenterMasterFailover {
for _, replica := range replicas {
replica := replica
if isGenerallyValidAsCandidateReplica(replica) &&
!IsBannedFromBeingCandidateReplica(replica) &&
!IsSmallerMajorVersion(priorityMajorVersion, replica.MajorVersionString()) &&
!IsSmallerBinlogFormat(priorityBinlogFormat, replica.Binlog_format) &&
IsDataCenterCandiadateReplica(priorityDataCenter, replica) {
// this is the one
candidateReplica = replica
break
}
}
} else {
for _, replica := range replicas {
replica := replica
if isGenerallyValidAsCandidateReplica(replica) &&
!IsBannedFromBeingCandidateReplica(replica) &&
!IsSmallerMajorVersion(priorityMajorVersion, replica.MajorVersionString()) &&
!IsSmallerBinlogFormat(priorityBinlogFormat, replica.Binlog_format) {
// this is the one
candidateReplica = replica
break
}
}
}
if candidateReplica == nil {
// Unable to find a candidate that will master others.
// Instead, pick a (single) replica which is not banned.
Expand Down