Skip to content

Commit

Permalink
cherry pick tikv#2830 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
jyz0309 authored and ti-srebot committed Sep 17, 2020
1 parent aeaac24 commit c324041
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions client/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ type baseClient struct {
security SecurityOption

gRPCDialOptions []grpc.DialOption

timeout time.Duration
timeout time.Duration
}

// SecurityOption records options about tls
Expand Down
20 changes: 20 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type Region struct {
type Client interface {
// GetClusterID gets the cluster ID from PD.
GetClusterID(ctx context.Context) uint64
// GetMemberInfo gets the members Info from PD
GetMemberInfo(ctx context.Context) ([]*pdpb.Member, error)
// GetLeaderAddr returns current leader's address. It returns "" before
// syncing leader from server.
GetLeaderAddr() string
Expand Down Expand Up @@ -219,6 +221,24 @@ func (c *client) checkStreamTimeout(loopCtx context.Context, cancel context.Canc
}
}

func (c *client) GetMemberInfo(ctx context.Context) ([]*pdpb.Member, error) {
start := time.Now()
defer func() { cmdDurationGetMemberInfo.Observe(time.Since(start).Seconds()) }()

ctx, cancel := context.WithTimeout(ctx, c.timeout)
resp, err := c.leaderClient().GetMembers(ctx, &pdpb.GetMembersRequest{
Header: c.requestHeader(),
})
cancel()
if err != nil {
cmdFailDurationGetMemberInfo.Observe(time.Since(start).Seconds())
c.ScheduleCheckLeader()
return nil, errors.WithStack(err)
}
members := resp.GetMembers()
return members, nil
}

func (c *client) tsLoop() {
defer c.wg.Done()

Expand Down
2 changes: 2 additions & 0 deletions client/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
cmdDurationTSO = cmdDuration.WithLabelValues("tso")
cmdDurationTSOAsyncWait = cmdDuration.WithLabelValues("tso_async_wait")
cmdDurationGetRegion = cmdDuration.WithLabelValues("get_region")
cmdDurationGetMemberInfo = cmdDuration.WithLabelValues("get_member_info")
cmdDurationGetPrevRegion = cmdDuration.WithLabelValues("get_prev_region")
cmdDurationGetRegionByID = cmdDuration.WithLabelValues("get_region_byid")
cmdDurationScanRegions = cmdDuration.WithLabelValues("scan_regions")
Expand All @@ -71,6 +72,7 @@ var (

cmdFailDurationGetRegion = cmdFailedDuration.WithLabelValues("get_region")
cmdFailDurationTSO = cmdFailedDuration.WithLabelValues("tso")
cmdFailDurationGetMemberInfo = cmdFailedDuration.WithLabelValues("get_member_info")
cmdFailDurationGetPrevRegion = cmdFailedDuration.WithLabelValues("get_prev_region")
cmdFailedDurationGetRegionByID = cmdFailedDuration.WithLabelValues("get_region_byid")
cmdFailedDurationScanRegions = cmdFailedDuration.WithLabelValues("scan_regions")
Expand Down

0 comments on commit c324041

Please sign in to comment.