From f7469c3f3808fed1c13ea5b8cafdac589f8dd343 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Thu, 14 Dec 2023 15:14:52 +0800 Subject: [PATCH] Add caller ID to the PD HTTP client on the hot path Signed-off-by: JmPotato --- DEPS.bzl | 12 ++++++------ go.mod | 2 +- go.sum | 4 ++-- pkg/domain/infosync/info.go | 4 +++- pkg/store/helper/helper.go | 10 +++++++++- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index ed8ea0b2c45f8..0b1d4db85f55b 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -7019,13 +7019,13 @@ def go_deps(): name = "com_github_tikv_pd_client", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/pd/client", - sha256 = "a1f7b29d753c60a373d29430d426be39a204fbedb62ceeb41296dee7bc6e5efe", - strip_prefix = "github.com/tikv/pd/client@v0.0.0-20231204034622-259435d93ae2", + sha256 = "5b31b38e151e03117ef9878c2dbac2b1f22c890e72ebb70935795ac5682c77c1", + strip_prefix = "github.com/tikv/pd/client@v0.0.0-20231213112719-f51f9134558e", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231204034622-259435d93ae2.zip", - "http://ats.apps.svc/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231204034622-259435d93ae2.zip", - "https://cache.hawkingrei.com/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231204034622-259435d93ae2.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231204034622-259435d93ae2.zip", + "http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231213112719-f51f9134558e.zip", + "http://ats.apps.svc/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231213112719-f51f9134558e.zip", + "https://cache.hawkingrei.com/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231213112719-f51f9134558e.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20231213112719-f51f9134558e.zip", ], ) go_repository( diff --git a/go.mod b/go.mod index 88a45cc41fb34..4831cb41af4f7 100644 --- a/go.mod +++ b/go.mod @@ -103,7 +103,7 @@ require ( github.com/tdakkota/asciicheck v0.2.0 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 github.com/tikv/client-go/v2 v2.0.8-0.20231204074048-e80e9ca1fe66 - github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2 + github.com/tikv/pd/client v0.0.0-20231213112719-f51f9134558e github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 github.com/twmb/murmur3 v1.1.6 github.com/uber/jaeger-client-go v2.22.1+incompatible diff --git a/go.sum b/go.sum index b88dd815f4776..b37179acd540b 100644 --- a/go.sum +++ b/go.sum @@ -853,8 +853,8 @@ github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM= github.com/tikv/client-go/v2 v2.0.8-0.20231204074048-e80e9ca1fe66 h1:+bCtNxUSYVmY/wmN8Zhf0UVl9mF+04/OjoseguM2aWY= github.com/tikv/client-go/v2 v2.0.8-0.20231204074048-e80e9ca1fe66/go.mod h1:IE0/o4zWJW5Wpvp15CK2jpbu49DSLLSJBMNmwjv6I6o= -github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2 h1:7fnKwFC9pgiOolvnUnquEAb60liIpna+0hFRkopaOSg= -github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ= +github.com/tikv/pd/client v0.0.0-20231213112719-f51f9134558e h1:FKyIJ13O2iIgbWmG3xNN+E2D10XAptcXYUrJY4S9AmI= +github.com/tikv/pd/client v0.0.0-20231213112719-f51f9134558e/go.mod h1:AwjTSpM7CgAynYwB6qTG5R5fVC9/eXlQXiTO6zDL1HI= github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 h1:quvGphlmUVU+nhpFa4gg4yJyTRJ13reZMDHrKwYw53M= github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966/go.mod h1:27bSVNWSBOHm+qRp1T9qzaIpsWEP6TbUnei/43HK+PQ= github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= diff --git a/pkg/domain/infosync/info.go b/pkg/domain/infosync/info.go index ba101953be528..4220a0d8fbf34 100644 --- a/pkg/domain/infosync/info.go +++ b/pkg/domain/infosync/info.go @@ -200,7 +200,9 @@ func GlobalInfoSyncerInit( skipRegisterToDashBoard bool, ) (*InfoSyncer, error) { if pdHTTPCli != nil { - pdHTTPCli = pdHTTPCli.WithRespHandler(pdResponseHandler) + pdHTTPCli = pdHTTPCli. + WithCallerID("tidb-info-syncer"). + WithRespHandler(pdResponseHandler) } is := &InfoSyncer{ etcdCli: etcdCli, diff --git a/pkg/store/helper/helper.go b/pkg/store/helper/helper.go index 82dd22b131b58..0205fedeba885 100644 --- a/pkg/store/helper/helper.go +++ b/pkg/store/helper/helper.go @@ -81,6 +81,10 @@ type Storage interface { type Helper struct { Store Storage RegionCache *tikv.RegionCache + // pdHTTPCli is used to send http request to PD. + // This field is lazy initialized in `TryGetPDHTTPClient`, + // and should be tagged with the caller ID before using. + pdHTTPCli pd.Client } // NewHelper gets a Helper from Storage @@ -93,11 +97,15 @@ func NewHelper(store Storage) *Helper { // TryGetPDHTTPClient tries to get a PD HTTP client if it's available. func (h *Helper) TryGetPDHTTPClient() (pd.Client, error) { + if h.pdHTTPCli != nil { + return h.pdHTTPCli, nil + } cli := h.Store.GetPDHTTPClient() if cli == nil { return nil, errors.New("pd http client unavailable") } - return cli, nil + h.pdHTTPCli = cli.WithCallerID("tidb-store-helper") + return h.pdHTTPCli, nil } // MaxBackoffTimeoutForMvccGet is a derived value from previous implementation possible experiencing value 5000ms.