Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1259 Fix topology-related API endpoints for group replication setups #1263

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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