Skip to content

Commit

Permalink
fix: checkrole for mongodb and mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
xuriwuyun committed Dec 13, 2024
1 parent 9e26c53 commit 6952395
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/lorry/engines/mongodb/get_replica_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ import (
)

func (mgr *Manager) GetReplicaRole(ctx context.Context, cluster *dcs.Cluster) (string, error) {
return mgr.GetMemberState(ctx)
role, err := mgr.GetMemberState(ctx)
if err != nil {
mgr.Logger.Info("get replica state failed", "error", err.Error())
// if get replica state failed, return "" to reset the pod role
return "", nil
}

return role, nil
}
3 changes: 1 addition & 2 deletions pkg/lorry/engines/mongodb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ func (mgr *Manager) IsDBStartupReady() bool {
func (mgr *Manager) GetMemberState(ctx context.Context) (string, error) {
status, err := mgr.GetReplSetStatus(ctx)
if err != nil {
mgr.Logger.Info("rs.status() error", "error", err.Error())
return "", err
return "", errors.Wrap(err, "rs.status() failed")
}

self := status.GetSelf()
Expand Down
3 changes: 3 additions & 0 deletions pkg/lorry/engines/mysql/get_replica_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func (mgr *Manager) GetReplicaRole(ctx context.Context, cluster *dcs.Cluster) (s
if cluster == nil {
return "", errors.New("cluster not found")
}
if cluster.HaConfig != nil && !cluster.HaConfig.IsEnable() {
return "", errors.New("cluster's ha is disabled")
}

leader, err := dcs.GetStore().GetLeader()
if err != nil {
Expand Down

0 comments on commit 6952395

Please sign in to comment.