From 614f289a4964151baae56b6f676d9b6b58d60935 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 19 Mar 2024 17:30:43 +0800 Subject: [PATCH] This is an automated cherry-pick of #51892 Signed-off-by: ti-chi-bot --- DEPS.bzl | 22 +++++ go.mod | 95 +++++++++++++++++++++ go.sum | 11 +++ store/mockstore/unistore/pd.go | 123 +++++++++++++++++++++++++++- store/mockstore/unistore/pd_test.go | 21 +++++ 5 files changed, 271 insertions(+), 1 deletion(-) diff --git a/DEPS.bzl b/DEPS.bzl index a6017fc4847b9..68b38a77f79ef 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -4179,8 +4179,19 @@ def go_deps(): name = "com_github_tikv_client_go_v2", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/client-go/v2", +<<<<<<< HEAD sum = "h1:PcnOn0jObDWXvEWyAxBm7qrxokAVghEbHWXhK4ZVWNg=", version = "v2.0.8-0.20240417121055-7b4535c36317", +======= + sha256 = "070de80c4f3f4a56559f52462e5a8518e38f78bbbf4f5011530c6d051b3c21b6", + strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20240319080847-c9767e55585b", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240319080847-c9767e55585b.zip", + "http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240319080847-c9767e55585b.zip", + "https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240319080847-c9767e55585b.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240319080847-c9767e55585b.zip", + ], +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) ) go_repository( name = "com_github_tikv_pd", @@ -4194,8 +4205,19 @@ def go_deps(): name = "com_github_tikv_pd_client", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/pd/client", +<<<<<<< HEAD sum = "h1:BBwUZAaBl7DKdyaduOxXqias4xCtdDgIAGsDBuri3lg=", version = "v0.0.0-20231211083919-fe6fd1721aa6", +======= + sha256 = "cca1c3b7e41dc7f511ebbd99c948d9636b407bec1e271881c224934a83061e6d", + strip_prefix = "github.com/tikv/pd/client@v0.0.0-20240319071242-d3b94c97c12b", + urls = [ + "http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20240319071242-d3b94c97c12b.zip", + "http://ats.apps.svc/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20240319071242-d3b94c97c12b.zip", + "https://cache.hawkingrei.com/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20240319071242-d3b94c97c12b.zip", + "https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/pd/client/com_github_tikv_pd_client-v0.0.0-20240319071242-d3b94c97c12b.zip", + ], +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) ) go_repository( name = "com_github_timakin_bodyclose", diff --git a/go.mod b/go.mod index 002328fcfc5c4..2f2d89eb25224 100644 --- a/go.mod +++ b/go.mod @@ -94,9 +94,16 @@ require ( github.com/stretchr/testify v1.8.2 github.com/tdakkota/asciicheck v0.2.0 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 +<<<<<<< HEAD github.com/tikv/client-go/v2 v2.0.8-0.20240417121055-7b4535c36317 github.com/tikv/pd/client v0.0.0-20231211083919-fe6fd1721aa6 github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e +======= + github.com/tidwall/btree v1.7.0 + github.com/tikv/client-go/v2 v2.0.8-0.20240319080847-c9767e55585b + github.com/tikv/pd/client v0.0.0-20240319071242-d3b94c97c12b + github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) github.com/twmb/murmur3 v1.1.6 github.com/uber/jaeger-client-go v2.22.1+incompatible github.com/vbauerster/mpb/v7 v7.5.3 @@ -133,8 +140,13 @@ require ( ) require ( +<<<<<<< HEAD cloud.google.com/go v0.110.0 // indirect cloud.google.com/go/compute v1.19.0 // indirect +======= + cloud.google.com/go v0.112.0 // indirect + cloud.google.com/go/compute v1.24.0 // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v0.13.0 // indirect cloud.google.com/go/pubsub v1.30.0 // indirect @@ -152,7 +164,11 @@ require ( github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bmatcuk/doublestar/v2 v2.0.4 // indirect +<<<<<<< HEAD github.com/cespare/xxhash v1.1.0 // indirect +======= + github.com/cenkalti/backoff/v4 v4.2.1 // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 // indirect github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect @@ -160,10 +176,19 @@ require ( github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect github.com/coocood/bbloom v0.0.0-20190830030839-58deb6228d64 // indirect github.com/coocood/rtutil v0.0.0-20190304133409-c84515f646f2 // indirect +<<<<<<< HEAD github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect +======= + github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/dennwc/varint v1.0.0 // indirect + github.com/dolthub/maphash v0.1.0 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) github.com/eapache/go-resiliency v1.2.0 // indirect github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect github.com/eapache/queue v1.1.0 // indirect @@ -172,25 +197,45 @@ require ( github.com/felixge/httpsnoop v1.0.2 // indirect github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect +<<<<<<< HEAD github.com/go-kit/kit v0.9.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/goccy/go-json v0.9.11 // indirect github.com/golang/glog v1.0.0 // indirect +======= + github.com/go-kit/log v0.2.1 // indirect + github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang-jwt/jwt/v5 v5.2.0 // indirect + github.com/golang/glog v1.2.0 // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/google/licensecheck v0.3.1 // indirect github.com/google/renameio/v2 v2.0.0 // indirect +<<<<<<< HEAD github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.7.1 // indirect +======= + github.com/google/s2a-go v0.1.7 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect + github.com/googleapis/gax-go/v2 v2.12.0 // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/gostaticanalysis/analysisutil v0.7.1 // indirect github.com/gostaticanalysis/comment v1.4.2 // indirect + github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect github.com/hashicorp/go-uuid v1.0.2 // indirect github.com/hexops/gotextdiff v1.0.3 // indirect github.com/huandu/xstrings v1.3.1 // indirect @@ -202,6 +247,7 @@ require ( github.com/jcmturner/gofork v1.0.0 // indirect github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect + github.com/jfcg/sixb v1.3.8 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jonboulle/clockwork v0.2.2 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -231,17 +277,32 @@ require ( github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712 // indirect github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 // indirect +<<<<<<< HEAD github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 // indirect +======= + github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect + github.com/pkg/errors v0.9.1 // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) github.com/pkg/xattr v0.4.9 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect github.com/prometheus/procfs v0.9.0 // indirect github.com/prometheus/tsdb v0.8.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect +<<<<<<< HEAD github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/shoenig/go-m1cpu v0.1.5 // indirect +======= + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/rivo/uniseg v0.4.6 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect + github.com/segmentio/asm v1.2.0 // indirect + github.com/shabbyrobe/gocovmerge v0.0.0-20190829150210-3e036491d500 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) github.com/shopspring/decimal v1.2.0 // indirect github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect @@ -254,6 +315,7 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect github.com/uber/jaeger-lib v2.4.1+incompatible // indirect +<<<<<<< HEAD github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect go.etcd.io/bbolt v1.3.6 // indirect @@ -284,6 +346,39 @@ require ( k8s.io/apimachinery v0.27.2 // indirect k8s.io/klog/v2 v2.90.1 // indirect k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect +======= + github.com/xiang90/probing v0.0.0-20221125231312-a49e3df8f510 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + go.etcd.io/bbolt v1.3.8 // indirect + go.etcd.io/etcd/client/v2 v2.305.12 // indirect + go.etcd.io/etcd/pkg/v3 v3.5.12 // indirect + go.etcd.io/etcd/raft/v3 v3.5.12 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect + go.opentelemetry.io/otel v1.22.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.22.0 // indirect + go.opentelemetry.io/otel/metric v1.22.0 // indirect + go.opentelemetry.io/otel/sdk v1.22.0 // indirect + go.opentelemetry.io/otel/trace v1.22.0 // indirect + go.opentelemetry.io/proto/otlp v1.1.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/exp/typeparams v0.0.0-20231219180239-dc181d75b848 // indirect + golang.org/x/mod v0.16.0 // indirect + 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/googleapis/api v0.0.0-20240304212257-790db918fca8 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240308144416-29370a3891b7 // 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 + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/apimachinery v0.28.6 // indirect + k8s.io/klog/v2 v2.120.1 // indirect + k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect diff --git a/go.sum b/go.sum index 84bce7c951418..7e5ecfc10b440 100644 --- a/go.sum +++ b/go.sum @@ -967,12 +967,23 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJf github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= 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= +<<<<<<< HEAD github.com/tikv/client-go/v2 v2.0.8-0.20240417121055-7b4535c36317 h1:PcnOn0jObDWXvEWyAxBm7qrxokAVghEbHWXhK4ZVWNg= github.com/tikv/client-go/v2 v2.0.8-0.20240417121055-7b4535c36317/go.mod h1:45NuHB8x+VAoztMIjF6hEgXvPQXhXWPfMxDg0N8CoRY= github.com/tikv/pd/client v0.0.0-20231211083919-fe6fd1721aa6 h1:BBwUZAaBl7DKdyaduOxXqias4xCtdDgIAGsDBuri3lg= github.com/tikv/pd/client v0.0.0-20231211083919-fe6fd1721aa6/go.mod h1:8XEP9aqUvvc9guWJZ7vo0av0H6QsJtjIrOmLAQlL2Jo= github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e h1:MV6KaVu/hzByHP0UvJ4HcMGE/8a6A4Rggc/0wx2AvJo= github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e/go.mod h1:27bSVNWSBOHm+qRp1T9qzaIpsWEP6TbUnei/43HK+PQ= +======= +github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= +github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= +github.com/tikv/client-go/v2 v2.0.8-0.20240319080847-c9767e55585b h1:kLzd0wYIL3XqPSoFnrrrCYO2YYn2zVU7TxgOW781y98= +github.com/tikv/client-go/v2 v2.0.8-0.20240319080847-c9767e55585b/go.mod h1:bFBqiszy79M/wvhfF2WANGp+QBiUIrswemx+GuiL8ko= +github.com/tikv/pd/client v0.0.0-20240319071242-d3b94c97c12b h1:LUeYme5++BRU4DSEi2BmdIki0dRki4dFt2/8IhmIXy4= +github.com/tikv/pd/client v0.0.0-20240319071242-d3b94c97c12b/go.mod h1:Z/QAgOt29zvwBTd0H6pdx45VO6KRNc/O/DzGkVmSyZg= +github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a h1:A6uKudFIfAEpoPdaal3aSqGxBzLyU8TqyXImLwo6dIo= +github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a/go.mod h1:mkjARE7Yr8qU23YcGMSALbIxTQ9r9QBVahQOBRfU460= +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)) 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/store/mockstore/unistore/pd.go b/store/mockstore/unistore/pd.go index 0082a335016fe..8b71c3535d77e 100644 --- a/store/mockstore/unistore/pd.go +++ b/store/mockstore/unistore/pd.go @@ -125,6 +125,127 @@ func (c *pdClient) GetLocalTSAsync(ctx context.Context, dcLocation string) pd.TS return &mockTSFuture{c, ctx, false} } +<<<<<<< HEAD:store/mockstore/unistore/pd.go +======= +func (c *pdClient) GetServiceDiscovery() pd.ServiceDiscovery { + return NewMockPDServiceDiscovery(c.addrs) +} + +var ( + _ pd.ServiceDiscovery = (*mockPDServiceDiscovery)(nil) + _ pd.ServiceClient = (*mockPDServiceClient)(nil) +) + +type mockPDServiceClient struct { + addr string +} + +func newMockPDServiceClient(addr string) pd.ServiceClient { + if !strings.HasPrefix(addr, "http") { + addr = fmt.Sprintf("%s://%s", "http", addr) + } + return &mockPDServiceClient{addr: addr} +} + +func (c *mockPDServiceClient) GetAddress() string { + return c.addr +} + +func (c *mockPDServiceClient) GetURL() string { + return c.addr +} + +func (c *mockPDServiceClient) GetClientConn() *grpc.ClientConn { + return nil +} + +func (c *mockPDServiceClient) BuildGRPCTargetContext(ctx context.Context, _ bool) context.Context { + return ctx +} + +func (c *mockPDServiceClient) Available() bool { + return true +} + +func (c *mockPDServiceClient) NeedRetry(*pdpb.Error, error) bool { + return false +} + +func (c *mockPDServiceClient) IsConnectedToLeader() bool { + return true +} + +type mockPDServiceDiscovery struct { + addrs []string + clis []pd.ServiceClient +} + +// NewMockPDServiceDiscovery returns a mock PD ServiceDiscovery +func NewMockPDServiceDiscovery(addrs []string) pd.ServiceDiscovery { + addresses := make([]string, 0) + clis := make([]pd.ServiceClient, 0) + for _, addr := range addrs { + if check := govalidator.IsURL(addr); !check { + continue + } + addresses = append(addresses, addr) + clis = append(clis, newMockPDServiceClient(addr)) + } + return &mockPDServiceDiscovery{addrs: addresses, clis: clis} +} + +func (c *mockPDServiceDiscovery) Init() error { + return nil +} + +func (c *mockPDServiceDiscovery) Close() {} + +func (c *mockPDServiceDiscovery) GetClusterID() uint64 { return 0 } + +func (c *mockPDServiceDiscovery) GetKeyspaceID() uint32 { return 0 } + +func (c *mockPDServiceDiscovery) GetKeyspaceGroupID() uint32 { return 0 } + +func (c *mockPDServiceDiscovery) GetServiceURLs() []string { + return c.addrs +} + +func (c *mockPDServiceDiscovery) GetServingEndpointClientConn() *grpc.ClientConn { return nil } + +func (c *mockPDServiceDiscovery) GetClientConns() *sync.Map { return nil } + +func (c *mockPDServiceDiscovery) GetServingURL() string { return "" } + +func (c *mockPDServiceDiscovery) GetBackupURLs() []string { return nil } + +func (c *mockPDServiceDiscovery) GetServiceClient() pd.ServiceClient { + if len(c.clis) > 0 { + return c.clis[0] + } + return nil +} + +func (c *mockPDServiceDiscovery) GetAllServiceClients() []pd.ServiceClient { + return c.clis +} + +func (c *mockPDServiceDiscovery) GetOrCreateGRPCConn(addr string) (*grpc.ClientConn, error) { + return nil, nil +} + +func (c *mockPDServiceDiscovery) ScheduleCheckMemberChanged() {} + +func (c *mockPDServiceDiscovery) CheckMemberChanged() error { return nil } + +func (c *mockPDServiceDiscovery) AddServingAddrSwitchedCallback(callbacks ...func()) {} + +func (c *mockPDServiceDiscovery) AddServiceAddrsSwitchedCallback(callbacks ...func()) {} + +func (c *mockPDServiceDiscovery) AddServingURLSwitchedCallback(callbacks ...func()) {} + +func (c *mockPDServiceDiscovery) AddServiceURLsSwitchedCallback(callbacks ...func()) {} + +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)):pkg/store/mockstore/unistore/pd.go type mockTSFuture struct { pdc *pdClient ctx context.Context @@ -139,7 +260,7 @@ func (m *mockTSFuture) Wait() (int64, int64, error) { return m.pdc.GetTS(m.ctx) } -func (c *pdClient) GetLeaderAddr() string { return "mockpd" } +func (c *pdClient) GetLeaderURL() string { return "mockpd" } func (c *pdClient) UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error) { c.gcSafePointMu.Lock() diff --git a/store/mockstore/unistore/pd_test.go b/store/mockstore/unistore/pd_test.go index 4cfbfd094e396..ac76b94f62757 100644 --- a/store/mockstore/unistore/pd_test.go +++ b/store/mockstore/unistore/pd_test.go @@ -93,3 +93,24 @@ func (s *GlobalConfigTestSuite) TearDownSuite() { s.rpc.Close() s.cluster.Close() } +<<<<<<< HEAD:store/mockstore/unistore/pd_test.go +======= + +func TestMockPDServiceDiscovery(t *testing.T) { + re := require.New(t) + pdAddrs := []string{"invalid_pd_address", "127.0.0.1:2379", "http://172.32.21.32:2379"} + for i, addr := range pdAddrs { + check := govalidator.IsURL(addr) + if i > 0 { + re.True(check) + } else { + re.False(check) + } + } + sd := NewMockPDServiceDiscovery(pdAddrs) + clis := sd.GetAllServiceClients() + re.Len(clis, 2) + re.Equal(clis[0].GetURL(), "http://127.0.0.1:2379") + re.Equal(clis[1].GetURL(), "http://172.32.21.32:2379") +} +>>>>>>> 61eab4304ee (go.mod: upgrade PD client to fix the TSO hang bug (#51892)):pkg/store/mockstore/unistore/pd_test.go