Skip to content

Commit dfe9dfb

Browse files
committed
status: Skip the unavailable node and set default node status. #417
1 parent 49384da commit dfe9dfb

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

mysqlcluster/syncer/status.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ func (s *StatusSyncer) updateNodeStatus(ctx context.Context, cli client.Client,
193193
node.Message = ""
194194

195195
if err := s.updateNodeRaftStatus(node); err != nil {
196-
return err
196+
log.Error(err, "failed to get/update node raft status", "node", node.Name)
197+
node.Message = err.Error()
197198
}
198199

199200
isLagged, isReplicating, isReadOnly := corev1.ConditionUnknown, corev1.ConditionUnknown, corev1.ConditionUnknown
@@ -296,19 +297,24 @@ func (s *StatusSyncer) updateNodeCondition(node *apiv1alpha1.NodeStatus, idx int
296297

297298
// updateNodeRaftStatus Update Node RaftStatus.
298299
func (s *StatusSyncer) updateNodeRaftStatus(node *apiv1alpha1.NodeStatus) error {
299-
raftStatus, err := s.XenonExecutor.RaftStatus(node.Name)
300-
if err != nil {
301-
return err
300+
isLeader := corev1.ConditionFalse
301+
node.RaftStatus = apiv1alpha1.RaftStatus{
302+
Role: string(utils.Unknown),
303+
Leader: "UNKNOWN",
304+
Nodes: nil,
302305
}
303-
node.RaftStatus = *raftStatus
304306

305-
isLeader := corev1.ConditionFalse
306-
if node.RaftStatus.Role == string(utils.Leader) {
307-
isLeader = corev1.ConditionTrue
307+
raftStatus, err := s.XenonExecutor.RaftStatus(node.Name)
308+
if err == nil && raftStatus != nil {
309+
node.RaftStatus = *raftStatus
310+
if raftStatus.Role == string(utils.Leader) {
311+
isLeader = corev1.ConditionTrue
312+
}
308313
}
314+
309315
// update apiv1alpha1.NodeConditionLeader.
310316
s.updateNodeCondition(node, int(apiv1alpha1.IndexLeader), isLeader)
311-
return nil
317+
return err
312318
}
313319

314320
func (s *StatusSyncer) reconcileXenon(readyNodes int) error {

utils/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const (
166166
Leader RaftRole = "LEADER"
167167
Follower RaftRole = "FOLLOWER"
168168
Candidate RaftRole = "CANDIDATE"
169+
Unknown RaftRole = "UNKNOWN"
169170
)
170171

171172
// XenonHttpUrl is a http url corresponding to the xenon instruction.

0 commit comments

Comments
 (0)