From cf23605809cb23e220e442a6f10ee1e005c48386 Mon Sep 17 00:00:00 2001 From: Smityz Date: Fri, 1 Mar 2024 20:01:50 +0800 Subject: [PATCH 1/3] fix bugs Signed-off-by: Smityz --- client/http/api.go | 2 +- client/pd_service_discovery.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/http/api.go b/client/http/api.go index 398307ec1ba..434bf0d1fe4 100644 --- a/client/http/api.go +++ b/client/http/api.go @@ -95,7 +95,7 @@ func RegionByKey(key []byte) string { // RegionsByKeyRange returns the path of PD HTTP API to scan regions with given start key, end key and limit parameters. func RegionsByKeyRange(keyRange *KeyRange, limit int) string { startKeyStr, endKeyStr := keyRange.EscapeAsUTF8Str() - return fmt.Sprintf("%s?start_key=%s&end_key=%s&limit=%d", + return fmt.Sprintf("%s?key=%s&end_key=%s&limit=%d", regionsByKey, startKeyStr, endKeyStr, limit) } diff --git a/client/pd_service_discovery.go b/client/pd_service_discovery.go index bc446440215..b9fdd76d971 100644 --- a/client/pd_service_discovery.go +++ b/client/pd_service_discovery.go @@ -893,7 +893,9 @@ func (c *pdServiceDiscovery) checkServiceModeChanged() error { // If the method is not supported, we set it to pd mode. // TODO: it's a hack way to solve the compatibility issue. // we need to remove this after all maintained version supports the method. - c.serviceModeUpdateCb(pdpb.ServiceMode_PD_SVC_MODE) + if c.serviceModeUpdateCb != nil { + c.serviceModeUpdateCb(pdpb.ServiceMode_PD_SVC_MODE) + } return nil } return err From 9db2c067bad47b762d689451adde270e04bdb5e4 Mon Sep 17 00:00:00 2001 From: Smityz Date: Mon, 4 Mar 2024 21:57:33 +0800 Subject: [PATCH 2/3] add tests Signed-off-by: Smityz --- tests/integrations/client/http_client_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/integrations/client/http_client_test.go b/tests/integrations/client/http_client_test.go index 4fe6b955c5d..c3249115cf6 100644 --- a/tests/integrations/client/http_client_test.go +++ b/tests/integrations/client/http_client_test.go @@ -204,6 +204,12 @@ func (suite *httpClientTestSuite) checkMeta(mode mode, client pd.Client) { version, err := client.GetClusterVersion(env.ctx) re.NoError(err) re.Equal("0.0.0", version) + rgs,_:=client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a"), []byte("a1")), 100) + re.Equal(int64(0), rgs.Count) + rgs,_=client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a1"), []byte("a3")), 100) + re.Equal(int64(2), rgs.Count) + rgs,_=client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a2"), []byte("b")), 100) + re.Equal(int64(1), rgs.Count) } func (suite *httpClientTestSuite) TestGetMinResolvedTSByStoresIDs() { From 2ee08632164547712eec31169abf88ec02a99ef4 Mon Sep 17 00:00:00 2001 From: Smityz Date: Tue, 5 Mar 2024 10:39:35 +0800 Subject: [PATCH 3/3] add test case and fmt Signed-off-by: Smityz --- tests/integrations/client/http_client_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/integrations/client/http_client_test.go b/tests/integrations/client/http_client_test.go index c3249115cf6..9bcc7bc9fbd 100644 --- a/tests/integrations/client/http_client_test.go +++ b/tests/integrations/client/http_client_test.go @@ -204,12 +204,14 @@ func (suite *httpClientTestSuite) checkMeta(mode mode, client pd.Client) { version, err := client.GetClusterVersion(env.ctx) re.NoError(err) re.Equal("0.0.0", version) - rgs,_:=client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a"), []byte("a1")), 100) + rgs, _ := client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a"), []byte("a1")), 100) re.Equal(int64(0), rgs.Count) - rgs,_=client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a1"), []byte("a3")), 100) + rgs, _ = client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a1"), []byte("a3")), 100) re.Equal(int64(2), rgs.Count) - rgs,_=client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a2"), []byte("b")), 100) + rgs, _ = client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte("a2"), []byte("b")), 100) re.Equal(int64(1), rgs.Count) + rgs, _ = client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte(""), []byte("")), 100) + re.Equal(int64(2), rgs.Count) } func (suite *httpClientTestSuite) TestGetMinResolvedTSByStoresIDs() {