Skip to content

Commit

Permalink
mcs: fix panic of get leader (#7472)
Browse files Browse the repository at this point in the history
close #7280

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
rleungx and ti-chi-bot authored Dec 7, 2023
1 parent ad232d1 commit d8550f0
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions pkg/member/participant.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,16 @@ func (m *Participant) Client() *clientv3.Client {
// IsLeader returns whether the participant is the leader or not by checking its leadership's
// lease and leader info.
func (m *Participant) IsLeader() bool {
if m.GetLeader() == nil {
return false
}
return m.leadership.Check() && m.GetLeader().GetId() == m.member.GetId() && m.campaignCheck()
}

// IsLeaderElected returns true if the leader exists; otherwise false
func (m *Participant) IsLeaderElected() bool {
return m.GetLeader() != nil
return m.GetLeader().GetId() != 0
}

// GetLeaderListenUrls returns current leader's listen urls
func (m *Participant) GetLeaderListenUrls() []string {
if m.GetLeader() == nil {
return nil
}
return m.GetLeader().GetListenUrls()
}

Expand All @@ -149,13 +143,9 @@ func (m *Participant) GetLeaderID() uint64 {
func (m *Participant) GetLeader() participant {
leader := m.leader.Load()
if leader == nil {
return nil
}
member := leader.(participant)
if member.GetId() == 0 {
return nil
return NewParticipantByService(m.serviceName)
}
return member
return leader.(participant)
}

// setLeader sets the member's leader.
Expand Down

0 comments on commit d8550f0

Please sign in to comment.