Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: Bug Fix/CLUSTER_INFO system table may not work after PD is scaled-in #2830

Merged
merged 9 commits into from
Aug 26, 2020
Merged
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
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
timeout time.Duration
}
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved

// 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 @@ -203,6 +205,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
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@ github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d h1:F8vp38kTAckN+
github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d/go.mod h1:DNS3Qg7bEDhU6EXNHF+XSv/PGznQaMJ5FWvctpm6pQI=
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
github.com/pingcap/kvproto v0.0.0-20200411081810-b85805c9476c/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/kvproto v0.0.0-20200810113304-6157337686b1 h1:hv22UEhdqeIqa5Jx0oeqDQNGHUBSW3LVOx02gqbd5Gg=
github.com/pingcap/kvproto v0.0.0-20200810113304-6157337686b1/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/kvproto v0.0.0-20200715040832-c3e2e0b163ee h1:DVIvoPsg68XMQje9ivq7l8Iz8sTCBZGrHeaSwg+mwjw=
github.com/pingcap/kvproto v0.0.0-20200715040832-c3e2e0b163ee/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/kvproto v0.0.0-20200821061039-7771f65e7756 h1:RQWDa7Q7u+ESZAPMrCyg0D4oqoq/VQE5JwbufLPmxl4=
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 h1:AJD9pZYm72vMgPcQDww9rkZ1DnWfl0pXV3BOWlkYIjA=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd h1:CV3VsP3Z02MVtdpTMfEgRJ4T9NGgGTxdHpJerent7rM=
Expand Down
1 change: 0 additions & 1 deletion server/api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ func (h *statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Version: versioninfo.PDReleaseVersion,
StartTimestamp: h.svr.StartTimestamp(),
}

jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
h.rd.JSON(w, http.StatusOK, version)
}