From 9caddec1314fc756f843d7b6046038d97612f7a9 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Mon, 13 Nov 2023 14:11:07 +0800 Subject: [PATCH] Update PD client to the latest version (#1056) Signed-off-by: JmPotato --- go.mod | 4 +--- go.sum | 4 ++-- integration_tests/go.mod | 4 +--- integration_tests/go.sum | 4 ++-- integration_tests/pd_api_test.go | 3 ++- tikv/kv.go | 14 ++++++++++++-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index b30464f384..6559e5aec9 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/tikv/client-go/v2 go 1.21 -replace github.com/tikv/pd/client v0.0.0-20230724080549-de985b8e0afc => github.com/JmPotato/pd/client v0.0.0-20231107024609-216b5b763864 - require ( github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 @@ -23,7 +21,7 @@ require ( github.com/prometheus/client_model v0.3.0 github.com/stretchr/testify v1.8.2 github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a - github.com/tikv/pd/client v0.0.0-20230724080549-de985b8e0afc + github.com/tikv/pd/client v0.0.0-20231113054113-7dbe6079ca2f github.com/twmb/murmur3 v1.1.3 go.etcd.io/etcd/api/v3 v3.5.10 go.etcd.io/etcd/client/v3 v3.5.10 diff --git a/go.sum b/go.sum index b6580095a3..a0ae4e5bd9 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/JmPotato/pd/client v0.0.0-20231107024609-216b5b763864 h1:q7k2boDgGSdnX/gXaIhk59V33J6GcxhpI53eoyVvMM0= -github.com/JmPotato/pd/client v0.0.0-20231107024609-216b5b763864/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -114,6 +112,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4= github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM= +github.com/tikv/pd/client v0.0.0-20231113054113-7dbe6079ca2f h1:DwMOkPfUf9euj/7I25r2d7/NJxneZ/BjnA7vRnD6/cg= +github.com/tikv/pd/client v0.0.0-20231113054113-7dbe6079ca2f/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ= github.com/twmb/murmur3 v1.1.3 h1:D83U0XYKcHRYwYIpBKf3Pks91Z0Byda/9SJ8B6EMRcA= github.com/twmb/murmur3 v1.1.3/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/integration_tests/go.mod b/integration_tests/go.mod index 3cbe43b239..26b4dfe9c7 100644 --- a/integration_tests/go.mod +++ b/integration_tests/go.mod @@ -2,8 +2,6 @@ module integration_tests go 1.21 -replace github.com/tikv/pd/client v0.0.0-20230912103610-2f57a9f050eb => github.com/JmPotato/pd/client v0.0.0-20231107024609-216b5b763864 - require ( github.com/ninedraft/israce v0.0.3 github.com/pingcap/errors v0.11.5-0.20221009092201-b66cddb77c32 @@ -14,7 +12,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tidwall/gjson v1.14.1 github.com/tikv/client-go/v2 v2.0.8-0.20231025022411-cad314220659 - github.com/tikv/pd/client v0.0.0-20230912103610-2f57a9f050eb + github.com/tikv/pd/client v0.0.0-20231113054113-7dbe6079ca2f go.uber.org/goleak v1.2.1 ) diff --git a/integration_tests/go.sum b/integration_tests/go.sum index ff9c88b529..54ffbc8ce2 100644 --- a/integration_tests/go.sum +++ b/integration_tests/go.sum @@ -31,8 +31,6 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM= github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= -github.com/JmPotato/pd/client v0.0.0-20231107024609-216b5b763864 h1:q7k2boDgGSdnX/gXaIhk59V33J6GcxhpI53eoyVvMM0= -github.com/JmPotato/pd/client v0.0.0-20231107024609-216b5b763864/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= @@ -509,6 +507,8 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tikv/pd/client v0.0.0-20231113054113-7dbe6079ca2f h1:DwMOkPfUf9euj/7I25r2d7/NJxneZ/BjnA7vRnD6/cg= +github.com/tikv/pd/client v0.0.0-20231113054113-7dbe6079ca2f/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ= github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= diff --git a/integration_tests/pd_api_test.go b/integration_tests/pd_api_test.go index 9d33bd5387..47fc701331 100644 --- a/integration_tests/pd_api_test.go +++ b/integration_tests/pd_api_test.go @@ -55,7 +55,8 @@ func (s *apiTestSuite) SetupTest() { rpcClient := tikv.NewRPCClient() require.NoError(failpoint.Enable("tikvclient/mockFastSafeTSUpdater", `return()`)) // Set PD HTTP client. - s.store, err = tikv.NewTestTiKVStore(rpcClient, pdClient, nil, nil, 0, tikv.WithPDHTTPClient(addrs, nil)) + s.store, err = tikv.NewTestTiKVStore(rpcClient, pdClient, nil, nil, 0, + tikv.WithPDHTTPClient(addrs, nil, nil, nil)) require.NoError(err) storeID := uint64(1) s.store.GetRegionCache().SetRegionCacheStore(storeID, s.storeAddr(storeID), s.storeAddr(storeID), tikvrpc.TiKV, 1, nil) diff --git a/tikv/kv.go b/tikv/kv.go index 73d0ceda29..9610dd107c 100644 --- a/tikv/kv.go +++ b/tikv/kv.go @@ -48,6 +48,7 @@ import ( "github.com/opentracing/opentracing-go" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pkg/errors" + "github.com/prometheus/client_golang/prometheus" "github.com/tikv/client-go/v2/config" tikverr "github.com/tikv/client-go/v2/error" "github.com/tikv/client-go/v2/internal/client" @@ -198,9 +199,18 @@ func WithPool(gp Pool) Option { } // WithPDHTTPClient set the PD HTTP client with the given address and TLS config. -func WithPDHTTPClient(pdAddrs []string, tlsConf *tls.Config) Option { +func WithPDHTTPClient( + pdAddrs []string, + tlsConf *tls.Config, + requestCounter *prometheus.CounterVec, + executionDuration *prometheus.HistogramVec, +) Option { return func(o *KVStore) { - o.pdHttpClient = pdhttp.NewClient(pdAddrs, pdhttp.WithTLSConfig(tlsConf)) + o.pdHttpClient = pdhttp.NewClient( + pdAddrs, + pdhttp.WithTLSConfig(tlsConf), + pdhttp.WithMetrics(requestCounter, executionDuration), + ) } }