Skip to content

Commit

Permalink
K8SPS-372: fix bootstrap for cluster with 2 mysql pods
Browse files Browse the repository at this point in the history
  • Loading branch information
pooknull committed Aug 8, 2024
1 parent 786fa5f commit badb039
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cmd/bootstrap/async_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ func bootstrapAsyncReplication(ctx context.Context) error {
}
log.Printf("Peers: %v", sets.List(peers))

primary, replicas, err := getTopology(ctx, peers)
if err != nil {
return errors.Wrap(err, "select donor")
}
log.Printf("Primary: %s Replicas: %v", primary, replicas)

fqdn, err := getFQDN(mysqlSvc)
if err != nil {
return errors.Wrap(err, "get FQDN")
}
log.Printf("FQDN: %s", fqdn)

primary, replicas, err := getTopology(ctx, fqdn, peers)
if err != nil {
return errors.Wrap(err, "select donor")
}
log.Printf("Primary: %s Replicas: %v", primary, replicas)

podHostname, err := os.Hostname()
if err != nil {
return errors.Wrap(err, "get hostname")
Expand Down Expand Up @@ -189,7 +189,7 @@ func bootstrapAsyncReplication(ctx context.Context) error {
return nil
}

func getTopology(ctx context.Context, peers sets.Set[string]) (string, []string, error) {
func getTopology(ctx context.Context, fqdn string, peers sets.Set[string]) (string, []string, error) {
replicas := sets.New[string]()
primary := ""

Expand Down Expand Up @@ -227,7 +227,15 @@ func getTopology(ctx context.Context, peers sets.Set[string]) (string, []string,
if primary == "" && peers.Len() == 1 {
primary = sets.List(peers)[0]
} else if primary == "" {
primary = sets.List(replicas)[0]
for _, r := range sets.List(replicas) {
// We should set primary to the first replica, which is not the bootstrapped pod.
// The bootstrapped pod can't be a primary.
// Even if it was a primary before, orchestrator will promote another replica "as result of DeadMaster".
if r != fqdn {
primary = r
break
}
}
}

if replicas.Len() > 0 {
Expand Down

0 comments on commit badb039

Please sign in to comment.