diff --git a/pkg/lorry/engines/mongodb/get_replica_role.go b/pkg/lorry/engines/mongodb/get_replica_role.go index 2012a3b566d..7163a32da06 100644 --- a/pkg/lorry/engines/mongodb/get_replica_role.go +++ b/pkg/lorry/engines/mongodb/get_replica_role.go @@ -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 } diff --git a/pkg/lorry/engines/mongodb/manager.go b/pkg/lorry/engines/mongodb/manager.go index a8be2187015..bea7e22d2b1 100644 --- a/pkg/lorry/engines/mongodb/manager.go +++ b/pkg/lorry/engines/mongodb/manager.go @@ -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() diff --git a/pkg/lorry/engines/mysql/get_replica_role.go b/pkg/lorry/engines/mysql/get_replica_role.go index d264759573d..c9f4292c0e1 100644 --- a/pkg/lorry/engines/mysql/get_replica_role.go +++ b/pkg/lorry/engines/mysql/get_replica_role.go @@ -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 {