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

*: fix the change master bug #821

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions mysqlcluster/syncer/readonly_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,16 @@ func putMySQLReadOnly(s *StatefulSetSyncer, host string) error {
s.log.V(1).Info("slave status has gotten error", "error", err)
}
if isReplicating == corev1.ConditionFalse {
// chang master
changeSql := fmt.Sprintf(`stop slave;CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='%s', MASTER_PASSWORD='%s',
// No.1 start slave
if errStart := sqlRunner.QueryExec(internal.NewQuery("start slave;")); errStart != nil {
s.log.V(1).Info("start slave gotten error", "error", errStart)
// No2. change master and start
changeSql := fmt.Sprintf(`stop slave;CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='%s', MASTER_PASSWORD='%s',
MASTER_AUTO_POSITION=1; start slave;`, buildMasterName(s), 3306, "root", cfg.Password)
sqlRunner.QueryExec(internal.NewQuery(changeSql))
if err2 := sqlRunner.QueryExec(internal.NewQuery(changeSql)); err2 != nil {
s.log.V(1).Info("change master and start slave gotten error", "error", err2)
}
}
}
}
return errOut
Expand Down
17 changes: 15 additions & 2 deletions mysqlcluster/syncer/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,6 @@ func (s *StatusSyncer) RoCheckStatus(ctx context.Context, cli client.Client, pod
host := fmt.Sprintf("%s.%s.%s", podName, s.GetNameForResource(utils.ReadOnlyHeadlessSVC), s.Namespace)
index := s.getRoStatusIndex(host)
node := &s.Status.Nodes[index]
node.Message = ""

isInitial, isReadonly, isCloseSemi, isReplicating := corev1.ConditionUnknown, corev1.ConditionUnknown, corev1.ConditionUnknown, corev1.ConditionUnknown
isSupperReadOnly := corev1.ConditionUnknown
Expand Down Expand Up @@ -661,7 +660,21 @@ func (s *StatusSyncer) RoCheckStatus(ctx context.Context, cli client.Client, pod
}
// 3. change master
if _, isReplicating, err = internal.CheckSlaveStatus(sqlRunner, s.Spec.ReplicaLag); err != nil {
node.Message = err.Error()
parts := strings.Split(node.Message, " ")
now := time.Now().Unix()
var last int64
var err2 error
if len(parts[0]) == 0 {
node.Message = fmt.Sprintf("%d unixtime error:", now) + err.Error()
} else if last, err2 = strconv.ParseInt(parts[0], 10, 64); err2 != nil {
s.log.Info("get times from message", "times", last)
}
if now-last > 10 {
node.Message = fmt.Sprintf("%d unixseconds error:", now) + err.Error()
}

} else {
node.Message = ""
}
}
//update node Rostatus
Expand Down