From 05cac2eab889df96bab534de9f84b27062ef7d67 Mon Sep 17 00:00:00 2001 From: crazycs Date: Mon, 29 Apr 2024 21:28:28 +0800 Subject: [PATCH] This is an automated cherry-pick of #52810 Signed-off-by: ti-chi-bot --- DEPS.bzl | 70 +++++++++++-------- go.mod | 10 ++- go.sum | 17 +++-- pkg/distsql/distsql_test.go | 10 +-- pkg/distsql/select_result.go | 31 +++----- pkg/executor/distsql_test.go | 14 ++-- pkg/executor/executor_failpoint_test.go | 10 +-- pkg/executor/explainfor_test.go | 2 +- pkg/server/conn_test.go | 2 +- pkg/store/copr/batch_request_sender.go | 2 +- pkg/store/copr/coprocessor.go | 12 +++- pkg/tablecodec/BUILD.bazel | 1 + pkg/tablecodec/tablecodec_test.go | 3 +- .../sessiontest/session_fail_test.go | 8 +-- 14 files changed, 106 insertions(+), 86 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 9e258eacc1fa1..70b09fd62eb20 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -1048,13 +1048,13 @@ def go_deps(): name = "com_github_cncf_udpa_go", build_file_proto_mode = "disable_global", importpath = "github.com/cncf/udpa/go", - sha256 = "8fe1585f25d40a5e3cd4243a92143d71ae4ee92e915e7192e72387047539438e", - strip_prefix = "github.com/cncf/udpa/go@v0.0.0-20220112060539-c52dc94e7fbe", + sha256 = "f2a2fee0b2024946ddd3b7ec5cd06a6d318cdb8421a8d5afff4c2fd69f1e74a7", + strip_prefix = "github.com/cncf/udpa/go@v0.0.0-20191209042840-269d4d468f6f", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", - "http://ats.apps.svc/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", - "https://cache.hawkingrei.com/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20220112060539-c52dc94e7fbe.zip", + "http://bazel-cache.pingcap.net:8080/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20191209042840-269d4d468f6f.zip", + "http://ats.apps.svc/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20191209042840-269d4d468f6f.zip", + "https://cache.hawkingrei.com/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20191209042840-269d4d468f6f.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/cncf/udpa/go/com_github_cncf_udpa_go-v0.0.0-20191209042840-269d4d468f6f.zip", ], ) go_repository( @@ -7080,6 +7080,7 @@ def go_deps(): name = "com_github_tikv_client_go_v2", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/client-go/v2", +<<<<<<< HEAD sha256 = "401c279de8a754c7de7a59aafff07202ad07fcdad21a8553afccf8d44b4833ce", strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20240424065757-6b7d20069135", urls = [ @@ -7087,6 +7088,15 @@ def go_deps(): "http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240424065757-6b7d20069135.zip", "https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240424065757-6b7d20069135.zip", "https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240424065757-6b7d20069135.zip", +======= + sha256 = "2f8055e91a004d5e9063bfcfb9dab489e86c485ac544fd21add700c7f325546b", + strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20240429075632-31a502b9ba4d", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240429075632-31a502b9ba4d.zip", + "http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240429075632-31a502b9ba4d.zip", + "https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240429075632-31a502b9ba4d.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240429075632-31a502b9ba4d.zip", +>>>>>>> 245f7a9a55f (*: add rpc error stats and refine log (#52810)) ], ) go_repository( @@ -9004,13 +9014,13 @@ def go_deps(): name = "com_google_cloud_go_spanner", build_file_proto_mode = "disable_global", importpath = "cloud.google.com/go/spanner", - sha256 = "2f120e8a85e8a06dc6183447903ff7624b1e5d22ce4fd9026968d78b32335462", - strip_prefix = "cloud.google.com/go/spanner@v1.56.0", + sha256 = "869ec23f371ad0565a1fe89933ed34ff76f5b673fdb7c225cfc4305e78637a90", + strip_prefix = "cloud.google.com/go/spanner@v1.57.0", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.56.0.zip", - "http://ats.apps.svc/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.56.0.zip", - "https://cache.hawkingrei.com/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.56.0.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.56.0.zip", + "http://bazel-cache.pingcap.net:8080/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.57.0.zip", + "http://ats.apps.svc/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.57.0.zip", + "https://cache.hawkingrei.com/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.57.0.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/cloud.google.com/go/spanner/com_google_cloud_go_spanner-v1.57.0.zip", ], ) go_repository( @@ -10087,13 +10097,13 @@ def go_deps(): name = "org_golang_google_genproto", build_file_proto_mode = "disable_global", importpath = "google.golang.org/genproto", - sha256 = "9b1952b84fe434fd61f9aeb6ca3766f9bd69537a5e32868a25049d135a908043", - strip_prefix = "google.golang.org/genproto@v0.0.0-20240213162025-012b6fc9bca9", + sha256 = "d623f4156476f85beae7e6ed60fd7ea8a6202029074eb391a39252f3ed7d380d", + strip_prefix = "google.golang.org/genproto@v0.0.0-20240227224415-6ceb2ff114de", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240213162025-012b6fc9bca9.zip", - "http://ats.apps.svc/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240213162025-012b6fc9bca9.zip", - "https://cache.hawkingrei.com/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240213162025-012b6fc9bca9.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240213162025-012b6fc9bca9.zip", + "http://bazel-cache.pingcap.net:8080/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240227224415-6ceb2ff114de.zip", + "http://ats.apps.svc/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240227224415-6ceb2ff114de.zip", + "https://cache.hawkingrei.com/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240227224415-6ceb2ff114de.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/genproto/org_golang_google_genproto-v0.0.0-20240227224415-6ceb2ff114de.zip", ], ) go_repository( @@ -10126,26 +10136,26 @@ def go_deps(): name = "org_golang_google_genproto_googleapis_rpc", build_file_proto_mode = "disable_global", importpath = "google.golang.org/genproto/googleapis/rpc", - sha256 = "755a36227e2551491d44533ef50df7f47964db44911e6d4d84e4d4842a5339d6", - strip_prefix = "google.golang.org/genproto/googleapis/rpc@v0.0.0-20240308144416-29370a3891b7", + sha256 = "5520055455146fd452a014e10bfa069a5e132f30f8fea905431333dabb24c394", + strip_prefix = "google.golang.org/genproto/googleapis/rpc@v0.0.0-20240401170217-c3f982113cda", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240308144416-29370a3891b7.zip", - "http://ats.apps.svc/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240308144416-29370a3891b7.zip", - "https://cache.hawkingrei.com/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240308144416-29370a3891b7.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240308144416-29370a3891b7.zip", + "http://bazel-cache.pingcap.net:8080/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240401170217-c3f982113cda.zip", + "http://ats.apps.svc/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240401170217-c3f982113cda.zip", + "https://cache.hawkingrei.com/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240401170217-c3f982113cda.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/genproto/googleapis/rpc/org_golang_google_genproto_googleapis_rpc-v0.0.0-20240401170217-c3f982113cda.zip", ], ) go_repository( name = "org_golang_google_grpc", build_file_proto_mode = "disable_global", importpath = "google.golang.org/grpc", - sha256 = "95226c98d052d7e4cd308c4df972464ba90e302cf12b5f180e245c4c3d2cc02f", - strip_prefix = "google.golang.org/grpc@v1.62.1", + sha256 = "1d49288986efd05a7b4ac6cee078f84e29e464678c776f25e09efddfba852fd1", + strip_prefix = "google.golang.org/grpc@v1.63.2", urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.62.1.zip", - "http://ats.apps.svc/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.62.1.zip", - "https://cache.hawkingrei.com/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.62.1.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.62.1.zip", + "http://bazel-cache.pingcap.net:8080/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.63.2.zip", + "http://ats.apps.svc/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.63.2.zip", + "https://cache.hawkingrei.com/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.63.2.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/google.golang.org/grpc/org_golang_google_grpc-v1.63.2.zip", ], ) go_repository( diff --git a/go.mod b/go.mod index b50d3751f1616..0f5d0e553a4eb 100644 --- a/go.mod +++ b/go.mod @@ -107,7 +107,11 @@ require ( github.com/tdakkota/asciicheck v0.2.0 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 github.com/tidwall/btree v1.7.0 +<<<<<<< HEAD github.com/tikv/client-go/v2 v2.0.8-0.20240424065757-6b7d20069135 +======= + github.com/tikv/client-go/v2 v2.0.8-0.20240429075632-31a502b9ba4d +>>>>>>> 245f7a9a55f (*: add rpc error stats and refine log (#52810)) github.com/tikv/pd/client v0.0.0-20240322051414-fb9e2d561b6e github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a github.com/twmb/murmur3 v1.1.6 @@ -138,7 +142,7 @@ require ( golang.org/x/time v0.5.0 golang.org/x/tools v0.20.0 google.golang.org/api v0.162.0 - google.golang.org/grpc v1.62.1 + google.golang.org/grpc v1.63.2 gopkg.in/yaml.v2 v2.4.0 honnef.co/go/tools v0.4.7 k8s.io/api v0.28.6 @@ -293,9 +297,9 @@ require ( golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gonum.org/v1/gonum v0.8.2 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect + google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240308144416-29370a3891b7 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect diff --git a/go.sum b/go.sum index a997d4ff15b1c..19a731d3a56fa 100644 --- a/go.sum +++ b/go.sum @@ -869,8 +869,13 @@ 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/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= +<<<<<<< HEAD github.com/tikv/client-go/v2 v2.0.8-0.20240424065757-6b7d20069135 h1:mElNS+XLxZtRIpnlez15cK84WdnPG86iaLURANrF79w= github.com/tikv/client-go/v2 v2.0.8-0.20240424065757-6b7d20069135/go.mod h1:+vXk4Aex17GnI8gfSMPxrL0SQLbBYgP3Db4FvHiImwM= +======= +github.com/tikv/client-go/v2 v2.0.8-0.20240429075632-31a502b9ba4d h1:U6z0O+bc1zu27dYMrpvIJjcC2F2/PQvDBoldiZ96fLY= +github.com/tikv/client-go/v2 v2.0.8-0.20240429075632-31a502b9ba4d/go.mod h1:eCmtXyF9SZMNb9CZypLOlA6HL8FLkPJF9xRvhaeAAVU= +>>>>>>> 245f7a9a55f (*: add rpc error stats and refine log (#52810)) github.com/tikv/pd/client v0.0.0-20240322051414-fb9e2d561b6e h1:u2OoEvmh3qyjIiAKXUPRiFCOSwznByMINDx2fsorjAo= github.com/tikv/pd/client v0.0.0-20240322051414-fb9e2d561b6e/go.mod h1:Z/QAgOt29zvwBTd0H6pdx45VO6KRNc/O/DzGkVmSyZg= github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a h1:A6uKudFIfAEpoPdaal3aSqGxBzLyU8TqyXImLwo6dIo= @@ -1400,12 +1405,12 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y= -google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:mqHbVIp48Muh7Ywss/AD6I5kNVKZMmAa/QEW58Gxp2s= +google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= +google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8 h1:8eadJkXbwDEMNwcB5O0s5Y5eCfyuCLdvaiOIaGTrWmQ= google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240308144416-29370a3891b7 h1:em/y72n4XlYRtayY/cVj6pnVzHa//BDA1BdoO+z9mdE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240308144416-29370a3891b7/go.mod h1:UCOku4NytXMJuLQE5VuqA5lX3PcHCBo8pxNyvkf4xBs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v0.0.0-20180607172857-7a6a684ca69e/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -1423,8 +1428,8 @@ google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= -google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= +google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= google.golang.org/grpc/examples v0.0.0-20231221225426-4f03f3ff32c9 h1:ATnmU8nL2NfIyTSiBvJVDIDIr3qBmeW+c7z7XU21eWs= google.golang.org/grpc/examples v0.0.0-20231221225426-4f03f3ff32c9/go.mod h1:j5uROIAAgi3YmtiETMt1LW0d/lHqQ7wwrIY4uGRXLQ4= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= diff --git a/pkg/distsql/distsql_test.go b/pkg/distsql/distsql_test.go index 7031e494f636e..5385041b47474 100644 --- a/pkg/distsql/distsql_test.go +++ b/pkg/distsql/distsql_test.go @@ -111,7 +111,7 @@ func TestSelectResultRuntimeStats(t *testing.T) { backoffSleep: map[string]time.Duration{"RegionMiss": time.Millisecond}, totalProcessTime: time.Second, totalWaitTime: time.Second, - rpcStat: tikv.NewRegionRequestRuntimeStats(), + reqStat: tikv.NewRegionRequestRuntimeStats(), distSQLConcurrency: 15, } s1.copRespTime.Add(execdetails.Duration(time.Second)) @@ -128,13 +128,15 @@ func TestSelectResultRuntimeStats(t *testing.T) { // Test for idempotence. require.Equal(t, expect, stats.String()) - s1.rpcStat.Stats[tikvrpc.CmdCop] = &tikv.RPCRuntimeStats{ + s1.reqStat.RPCStats[tikvrpc.CmdCop] = &tikv.RPCRuntimeStats{ Count: 1, Consume: int64(time.Second), } + s1.reqStat.RecordRPCErrorStats("server_is_busy") + s1.reqStat.RecordRPCErrorStats("server_is_busy") stmtStats.RegisterStats(2, s1) stats = stmtStats.GetRootStats(2) - expect = "cop_task: {num: 2, max: 1s, min: 1ms, avg: 500.5ms, p95: 1s, max_proc_keys: 200, p95_proc_keys: 200, tot_proc: 1s, tot_wait: 1s, rpc_num: 1, rpc_time: 1s, copr_cache_hit_ratio: 0.00, max_distsql_concurrency: 15}, backoff{RegionMiss: 1ms}" + expect = "cop_task: {num: 2, max: 1s, min: 1ms, avg: 500.5ms, p95: 1s, max_proc_keys: 200, p95_proc_keys: 200, tot_proc: 1s, tot_wait: 1s, copr_cache_hit_ratio: 0.00, max_distsql_concurrency: 15}, rpc_info:{Cop:{num_rpc:1, total_time:1s}, rpc_errors:{server_is_busy:2}}, backoff{RegionMiss: 1ms}" require.Equal(t, expect, stats.String()) // Test for idempotence. require.Equal(t, expect, stats.String()) @@ -143,7 +145,7 @@ func TestSelectResultRuntimeStats(t *testing.T) { backoffSleep: map[string]time.Duration{"RegionMiss": time.Millisecond}, totalProcessTime: time.Second, totalWaitTime: time.Second, - rpcStat: tikv.NewRegionRequestRuntimeStats(), + reqStat: tikv.NewRegionRequestRuntimeStats(), } s1.copRespTime.Add(execdetails.Duration(time.Second)) s1.procKeys.Add(100) diff --git a/pkg/distsql/select_result.go b/pkg/distsql/select_result.go index 49c90710920cd..ae4a0b44f2c74 100644 --- a/pkg/distsql/select_result.go +++ b/pkg/distsql/select_result.go @@ -44,7 +44,6 @@ import ( "github.com/pingcap/tipb/go-tipb" tikvmetrics "github.com/tikv/client-go/v2/metrics" "github.com/tikv/client-go/v2/tikv" - "github.com/tikv/client-go/v2/tikvrpc" clientutil "github.com/tikv/client-go/v2/util" "go.uber.org/zap" "golang.org/x/exp/maps" @@ -499,7 +498,7 @@ func recordExecutionSummariesForTiFlashTasks(runtimeStatsColl *execdetails.Runti func (r *selectResult) updateCopRuntimeStats(ctx context.Context, copStats *copr.CopRuntimeStats, respTime time.Duration) (err error) { callee := copStats.CalleeAddress - if r.rootPlanID <= 0 || r.ctx.RuntimeStatsColl == nil || (callee == "" && len(copStats.Stats) == 0) { + if r.rootPlanID <= 0 || r.ctx.RuntimeStatsColl == nil || (callee == "" && (copStats.ReqStats == nil || len(copStats.ReqStats.RPCStats) == 0)) { return } @@ -513,7 +512,7 @@ func (r *selectResult) updateCopRuntimeStats(ctx context.Context, copStats *copr if r.stats == nil { r.stats = &selectResultRuntimeStats{ backoffSleep: make(map[string]time.Duration), - rpcStat: tikv.NewRegionRequestRuntimeStats(), + reqStat: tikv.NewRegionRequestRuntimeStats(), distSQLConcurrency: r.distSQLConcurrency, } if ci, ok := r.resp.(copr.CopInfo); ok { @@ -639,7 +638,7 @@ type selectResultRuntimeStats struct { backoffSleep map[string]time.Duration totalProcessTime time.Duration totalWaitTime time.Duration - rpcStat tikv.RegionRequestRuntimeStats + reqStat *tikv.RegionRequestRuntimeStats distSQLConcurrency int extraConcurrency int CoprCacheHitNum int64 @@ -658,7 +657,7 @@ func (s *selectResultRuntimeStats) mergeCopRuntimeStats(copStats *copr.CopRuntim maps.Copy(s.backoffSleep, copStats.BackoffSleep) s.totalProcessTime += copStats.TimeDetail.ProcessTime s.totalWaitTime += copStats.TimeDetail.WaitTime - s.rpcStat.Merge(copStats.RegionRequestRuntimeStats) + s.reqStat.Merge(copStats.ReqStats) if copStats.CoprCacheHit { s.CoprCacheHitNum++ } @@ -669,7 +668,7 @@ func (s *selectResultRuntimeStats) Clone() execdetails.RuntimeStats { copRespTime: execdetails.Percentile[execdetails.Duration]{}, procKeys: execdetails.Percentile[execdetails.Int64]{}, backoffSleep: make(map[string]time.Duration, len(s.backoffSleep)), - rpcStat: tikv.NewRegionRequestRuntimeStats(), + reqStat: tikv.NewRegionRequestRuntimeStats(), distSQLConcurrency: s.distSQLConcurrency, extraConcurrency: s.extraConcurrency, CoprCacheHitNum: s.CoprCacheHitNum, @@ -684,7 +683,7 @@ func (s *selectResultRuntimeStats) Clone() execdetails.RuntimeStats { } newRs.totalProcessTime += s.totalProcessTime newRs.totalWaitTime += s.totalWaitTime - maps.Copy(newRs.rpcStat.Stats, s.rpcStat.Stats) + newRs.reqStat = s.reqStat.Clone() return &newRs } @@ -701,7 +700,7 @@ func (s *selectResultRuntimeStats) Merge(rs execdetails.RuntimeStats) { } s.totalProcessTime += other.totalProcessTime s.totalWaitTime += other.totalWaitTime - s.rpcStat.Merge(other.rpcStat) + s.reqStat.Merge(other.reqStat) s.CoprCacheHitNum += other.CoprCacheHitNum if other.distSQLConcurrency > s.distSQLConcurrency { s.distSQLConcurrency = other.distSQLConcurrency @@ -716,7 +715,7 @@ func (s *selectResultRuntimeStats) Merge(rs execdetails.RuntimeStats) { func (s *selectResultRuntimeStats) String() string { buf := bytes.NewBuffer(nil) - rpcStat := s.rpcStat + reqStat := s.reqStat if s.copRespTime.Size() > 0 { size := s.copRespTime.Size() if size == 1 { @@ -747,15 +746,6 @@ func (s *selectResultRuntimeStats) String() string { buf.WriteString(execdetails.FormatDuration(s.totalWaitTime)) } } - copRPC := rpcStat.Stats[tikvrpc.CmdCop] - if copRPC != nil && copRPC.Count > 0 { - rpcStat = rpcStat.Clone() - delete(rpcStat.Stats, tikvrpc.CmdCop) - buf.WriteString(", rpc_num: ") - buf.WriteString(strconv.FormatInt(copRPC.Count, 10)) - buf.WriteString(", rpc_time: ") - buf.WriteString(execdetails.FormatDuration(time.Duration(copRPC.Consume))) - } if config.GetGlobalConfig().TiKVClient.CoprCache.CapacityMB > 0 { fmt.Fprintf(buf, ", copr_cache_hit_ratio: %v", strconv.FormatFloat(s.calcCacheHit(), 'f', 2, 64)) @@ -785,10 +775,11 @@ func (s *selectResultRuntimeStats) String() string { buf.WriteString("}") } - rpcStatsStr := rpcStat.String() + rpcStatsStr := reqStat.String() if len(rpcStatsStr) > 0 { - buf.WriteString(", ") + buf.WriteString(", rpc_info:{") buf.WriteString(rpcStatsStr) + buf.WriteString("}") } if len(s.backoffSleep) > 0 { diff --git a/pkg/executor/distsql_test.go b/pkg/executor/distsql_test.go index d8628f09344c1..935d2f9f3f7ad 100644 --- a/pkg/executor/distsql_test.go +++ b/pkg/executor/distsql_test.go @@ -314,16 +314,16 @@ func TestCoprocessorPagingSize(t *testing.T) { // Check 'rpc_num' in the execution information // // mysql> explain analyze select * from t_paging; - // +--------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - // | id |task | execution info | - // +--------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - // | TableReader_5 |root | time:7.27ms, loops:2, cop_task: {num: 10, max: 1.57ms, min: 313.3µs, avg: 675.9µs, p95: 1.57ms, tot_proc: 2ms, rpc_num: 10, rpc_time: 6.69ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15} | - // | └─TableFullScan_4 |cop[tikv] | tikv_task:{proc max:1.48ms, min:294µs, avg: 629µs, p80:1.21ms, p95:1.48ms, iters:0, tasks:10} | - // +--------------------+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + // +--------------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + // | id |task | execution info | + // +--------------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + // | TableReader_5 |root | time:7.27ms, loops:2, cop_task: {num: 10, max: 1.57ms, min: 313.3µs, avg: 675.9µs, p95: 1.57ms, tot_proc: 2ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}, rpc_info:{Cop:{num_rpc:10, total_time:6.69ms}} | + // | └─TableFullScan_4 |cop[tikv] | tikv_task:{proc max:1.48ms, min:294µs, avg: 629µs, p80:1.21ms, p95:1.48ms, iters:0, tasks:10} | + // +--------------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ // 2 rows in set (0.01 sec) getRPCNumFromExplain := func(rows [][]any) (res uint64) { - re := regexp.MustCompile("rpc_num: ([0-9]+)") + re := regexp.MustCompile("num_rpc:([0-9]+)") for _, row := range rows { buf := bytes.NewBufferString("") _, _ = fmt.Fprintf(buf, "%s\n", row) diff --git a/pkg/executor/executor_failpoint_test.go b/pkg/executor/executor_failpoint_test.go index f791b1f0132a9..ed98e47c422cf 100644 --- a/pkg/executor/executor_failpoint_test.go +++ b/pkg/executor/executor_failpoint_test.go @@ -276,7 +276,7 @@ func TestCollectCopRuntimeStats(t *testing.T) { rows := tk.MustQuery("explain analyze select * from t1").Rows() require.Len(t, rows, 2) explain := fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*rpc_num: .*, .*regionMiss:.*", explain) + require.Regexp(t, ".*num_rpc:.*, .*regionMiss:.*", explain) require.NoError(t, failpoint.Disable("tikvclient/tikvStoreRespResult")) } @@ -591,7 +591,7 @@ func TestTiKVClientReadTimeout(t *testing.T) { rows = tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 2.*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:2.*", explain) // Test for stale read. tk.MustExec("set @a=now(6);") @@ -599,7 +599,7 @@ func TestTiKVClientReadTimeout(t *testing.T) { rows = tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t as of timestamp(@a) where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 2.*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:2.*", explain) // Test for tikv_client_read_timeout session variable. tk.MustExec("set @@tikv_client_read_timeout=1;") @@ -619,7 +619,7 @@ func TestTiKVClientReadTimeout(t *testing.T) { rows = tk.MustQuery("explain analyze select * from t where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 2.*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:2.*", explain) // Test for stale read. tk.MustExec("set @a=now(6);") @@ -627,7 +627,7 @@ func TestTiKVClientReadTimeout(t *testing.T) { rows = tk.MustQuery("explain analyze select * from t as of timestamp(@a) where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 2.*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:2.*", explain) } func TestGetMvccByEncodedKeyRegionError(t *testing.T) { diff --git a/pkg/executor/explainfor_test.go b/pkg/executor/explainfor_test.go index 444ac0c1304c2..3d0fecaf79b62 100644 --- a/pkg/executor/explainfor_test.go +++ b/pkg/executor/explainfor_test.go @@ -75,7 +75,7 @@ func TestExplainFor(t *testing.T) { buf.WriteString(fmt.Sprintf("%v", v)) } } - require.Regexp(t, "TableReader_5 10000.00 0 root time:.*, loops:1,( RU:.*,)? cop_task: {num:.*, max:.*, proc_keys:.* rpc_num: 1, rpc_time:.*} data:TableFullScan_4 N/A N/A\n"+ + require.Regexp(t, "TableReader_5 10000.00 0 root time:.*, loops:1,( RU:.*,)? cop_task: {num:.*, max:.*, proc_keys:.*num_rpc:1, total_time:.*} data:TableFullScan_4 N/A N/A\n"+ "└─TableFullScan_4 10000.00 0 cop.* table:t1 tikv_task:{time:.*, loops:0} keep order:false, stats:pseudo N/A N/A", buf.String()) } diff --git a/pkg/server/conn_test.go b/pkg/server/conn_test.go index e0f7b19d0d62d..859bb981ed44d 100644 --- a/pkg/server/conn_test.go +++ b/pkg/server/conn_test.go @@ -733,7 +733,7 @@ func TestConnExecutionTimeout(t *testing.T) { require.Equal(t, "[executor:3024]Query execution was interrupted, maximum statement execution time exceeded", err.Error()) planInfo, err := plancodec.DecodePlan(tk.Session().GetSessionVars().StmtCtx.GetEncodedPlan()) require.NoError(t, err) - require.Regexp(t, "TableReader.*cop_task: {num: .*, rpc_num: .*, rpc_time: .*", planInfo) + require.Regexp(t, "TableReader.*cop_task: {num: .*num_rpc:.*, total_time:.*", planInfo) // Killed because of max execution time, reset Killed to 0. tk.Session().GetSessionVars().SQLKiller.SendKillSignal(sqlkiller.MaxExecTimeExceeded) diff --git a/pkg/store/copr/batch_request_sender.go b/pkg/store/copr/batch_request_sender.go index 52ae8735925c1..ccb138f7753c3 100644 --- a/pkg/store/copr/batch_request_sender.go +++ b/pkg/store/copr/batch_request_sender.go @@ -76,7 +76,7 @@ func (ss *RegionBatchRequestSender) SendReqToAddr(bo *Backoffer, rpcCtx *tikv.RP start := time.Now() resp, err = ss.GetClient().SendRequest(ctx, rpcCtx.Addr, req, timout) if ss.Stats != nil && ss.enableCollectExecutionInfo { - tikv.RecordRegionRequestRuntimeStats(ss.Stats, req.Type, time.Since(start)) + ss.Stats.RecordRPCRuntimeStats(req.Type, time.Since(start)) } if err != nil { cancel() diff --git a/pkg/store/copr/coprocessor.go b/pkg/store/copr/coprocessor.go index 8230266c6e2a1..faaaba6d6f7cb 100644 --- a/pkg/store/copr/coprocessor.go +++ b/pkg/store/copr/coprocessor.go @@ -1254,7 +1254,7 @@ func (worker *copIteratorWorker) handleTaskOnce(bo *Backoffer, task *copTask, ch req.StoreTp = getEndPointType(task.storeType) startTime := time.Now() if worker.kvclient.Stats == nil { - worker.kvclient.Stats = make(map[tikvrpc.CmdType]*tikv.RPCRuntimeStats) + worker.kvclient.Stats = tikv.NewRegionRequestRuntimeStats() } // set ReadReplicaScope and TxnScope so that req.IsStaleRead will be true when it's a global scope stale read. req.ReadReplicaScope = worker.req.ReadReplicaScope @@ -1340,10 +1340,16 @@ const ( func (worker *copIteratorWorker) logTimeCopTask(costTime time.Duration, task *copTask, bo *Backoffer, resp *coprocessor.Response) { logStr := fmt.Sprintf("[TIME_COP_PROCESS] resp_time:%s txnStartTS:%d region_id:%d store_addr:%s", costTime, worker.req.StartTs, task.region.GetID(), task.storeAddr) + if worker.kvclient.Stats != nil { + logStr += fmt.Sprintf(" stats:%s", worker.kvclient.Stats.String()) + } if bo.GetTotalSleep() > minLogBackoffTime { backoffTypes := strings.ReplaceAll(fmt.Sprintf("%v", bo.TiKVBackoffer().GetTypes()), " ", ",") logStr += fmt.Sprintf(" backoff_ms:%d backoff_types:%s", bo.GetTotalSleep(), backoffTypes) } + if regionErr := resp.GetRegionError(); regionErr != nil { + logStr += fmt.Sprintf(" region_err:%s", regionErr.String()) + } // resp might be nil, but it is safe to call resp.GetXXX here. detailV2 := resp.GetExecDetailsV2() detail := resp.GetExecDetails() @@ -1795,7 +1801,7 @@ func (worker *copIteratorWorker) handleCollectExecutionInfo(bo *Backoffer, rpcCt } func (worker *copIteratorWorker) collectCopRuntimeStats(copStats *CopRuntimeStats, bo *Backoffer, rpcCtx *tikv.RPCContext, resp *copResponse) { - copStats.Stats = worker.kvclient.Stats + copStats.ReqStats = worker.kvclient.Stats backoffTimes := bo.GetBackoffTimes() copStats.BackoffTime = time.Duration(bo.GetTotalSleep()) * time.Millisecond copStats.BackoffSleep = make(map[string]time.Duration, len(backoffTimes)) @@ -1850,7 +1856,7 @@ func (worker *copIteratorWorker) collectUnconsumedCopRuntimeStats(bo *Backoffer, // CopRuntimeStats contains execution detail information. type CopRuntimeStats struct { execdetails.ExecDetails - tikv.RegionRequestRuntimeStats + ReqStats *tikv.RegionRequestRuntimeStats CoprCacheHit bool } diff --git a/pkg/tablecodec/BUILD.bazel b/pkg/tablecodec/BUILD.bazel index 8c891275c29f0..c51b894fed44b 100644 --- a/pkg/tablecodec/BUILD.bazel +++ b/pkg/tablecodec/BUILD.bazel @@ -48,6 +48,7 @@ go_test( "//pkg/util/collate", "//pkg/util/rowcodec", "@com_github_pingcap_failpoint//:failpoint", + "@com_github_pingcap_kvproto//pkg/keyspacepb", "@com_github_stretchr_testify//require", "@com_github_tikv_client_go_v2//tikv", "@org_uber_go_goleak//:goleak", diff --git a/pkg/tablecodec/tablecodec_test.go b/pkg/tablecodec/tablecodec_test.go index 89d9659619acd..0a3b3bbbe56f2 100644 --- a/pkg/tablecodec/tablecodec_test.go +++ b/pkg/tablecodec/tablecodec_test.go @@ -22,6 +22,7 @@ import ( "time" "github.com/pingcap/failpoint" + "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" @@ -729,7 +730,7 @@ func TestTempIndexValueCodec(t *testing.T) { func TestV2TableCodec(t *testing.T) { const tableID int64 = 31415926 key := EncodeTablePrefix(tableID) - c, err := tikv.NewCodecV2(tikv.ModeTxn, 271828) + c, err := tikv.NewCodecV2(tikv.ModeTxn, &keyspacepb.KeyspaceMeta{Id: 271828}) require.NoError(t, err) key = c.EncodeKey(key) tbid := DecodeTableID(key) diff --git a/tests/realtikvtest/sessiontest/session_fail_test.go b/tests/realtikvtest/sessiontest/session_fail_test.go index f56bc952c7483..b4220ce56a2ff 100644 --- a/tests/realtikvtest/sessiontest/session_fail_test.go +++ b/tests/realtikvtest/sessiontest/session_fail_test.go @@ -284,7 +284,7 @@ func TestTiKVClientReadTimeout(t *testing.T) { rows = tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 4.*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:4.*", explain) // Test for stale read. tk.MustExec("insert into t values (1,1), (2,2);") @@ -292,7 +292,7 @@ func TestTiKVClientReadTimeout(t *testing.T) { rows = tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t as of timestamp(@stale_read_ts_var) where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: (3|4|5).*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:(3|4|5).*", explain) // Test for tikv_client_read_timeout session variable. tk.MustExec("set @@tikv_client_read_timeout=1;") @@ -313,12 +313,12 @@ func TestTiKVClientReadTimeout(t *testing.T) { rows = tk.MustQuery("explain analyze select * from t where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 4.*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:4.*", explain) // Test for stale read. tk.MustExec("set @@tidb_replica_read='closest-replicas';") rows = tk.MustQuery("explain analyze select * from t as of timestamp(@stale_read_ts_var) where b > 1").Rows() require.Len(t, rows, 3) explain = fmt.Sprintf("%v", rows[0]) - require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: (3|4|5).*", explain) + require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:(3|4|5).*", explain) }