Skip to content

Commit

Permalink
mcs: fix checkMembershipCh blocking (tikv#7272)
Browse files Browse the repository at this point in the history
close tikv#7207

Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and rleungx committed Dec 1, 2023
1 parent 7736243 commit 511bb06
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (c *Cluster) AllocID() (uint64, error) {
defer cancel()
resp, err := client.AllocID(ctx, &pdpb.AllocIDRequest{Header: &pdpb.RequestHeader{ClusterId: c.clusterID}})
if err != nil {
c.checkMembershipCh <- struct{}{}
c.triggerMembershipCheck()
return 0, err
}
return resp.GetId(), nil
Expand All @@ -215,12 +215,19 @@ func (c *Cluster) AllocID() (uint64, error) {
func (c *Cluster) getAPIServerLeaderClient() (pdpb.PDClient, error) {
cli := c.apiServerLeader.Load()
if cli == nil {
c.checkMembershipCh <- struct{}{}
c.triggerMembershipCheck()
return nil, errors.New("API server leader is not found")
}
return cli.(pdpb.PDClient), nil
}

func (c *Cluster) triggerMembershipCheck() {
select {
case c.checkMembershipCh <- struct{}{}:
default: // avoid blocking
}
}

// SwitchAPIServerLeader switches the API server leader.
func (c *Cluster) SwitchAPIServerLeader(new pdpb.PDClient) bool {
old := c.apiServerLeader.Load()
Expand Down

0 comments on commit 511bb06

Please sign in to comment.