Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Issue #1259 Fix topology-related API endpoints for group replication …
Browse files Browse the repository at this point in the history
…setups
  • Loading branch information
ejortegau committed Nov 7, 2020
1 parent b254d72 commit 7bb1d15
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions go/inst/instance_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ func getASCIITopologyEntry(depth int, instance *Instance, replicationMap map[*In
prefix := ""
if depth > 0 {
prefix = strings.Repeat(fillerCharacter, (depth-1)*2)
if instance.ReplicaRunning() && instance.IsLastCheckValid && instance.IsRecentlyChecked {
prefix += "+" + fillerCharacter
if instance.IsReplicationGroupSecondary() {
prefix += "" + fillerCharacter
} else {
prefix += "-" + fillerCharacter
if instance.ReplicaRunning() && instance.IsLastCheckValid && instance.IsRecentlyChecked {
prefix += "+" + fillerCharacter
} else {
prefix += "-" + fillerCharacter
}
}
}
entryAlias := ""
Expand Down Expand Up @@ -116,12 +120,22 @@ func ASCIITopology(clusterName string, historyTimestampPattern string, tabulated
var masterInstance *Instance
// Investigate replicas:
for _, instance := range instances {
master, ok := instancesMap[instance.MasterKey]
var masterOrGroupPrimary *Instance
var ok bool
// If the current instance is a a group member, get the group's primary instead of the classical replication
// source.
if instance.IsReplicationGroupMember() && instance.IsReplicationGroupSecondary() {
masterOrGroupPrimary, ok = instancesMap[instance.ReplicationGroupPrimaryInstanceKey]
} else {
masterOrGroupPrimary, ok = instancesMap[instance.MasterKey]
}
if ok {
if _, ok := replicationMap[master]; !ok {
replicationMap[master] = [](*Instance){}
if _, ok := replicationMap[masterOrGroupPrimary]; !ok {
replicationMap[masterOrGroupPrimary] = [](*Instance){}
}
if !instance.IsReplicationGroupPrimary() || (instance.IsReplicationGroupPrimary() && instance.IsReplica()) {
replicationMap[masterOrGroupPrimary] = append(replicationMap[masterOrGroupPrimary], instance)
}
replicationMap[master] = append(replicationMap[master], instance)
} else {
masterInstance = instance
}
Expand Down

0 comments on commit 7bb1d15

Please sign in to comment.