Skip to content

Commit

Permalink
client/http: fix the scan region parameter (#7870)
Browse files Browse the repository at this point in the history
close #7869

add null pointer check and fix http request format

Signed-off-by: Smityz <[email protected]>
  • Loading branch information
Smityz authored Mar 5, 2024
1 parent 2851db2 commit 3f67cac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion client/pd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +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)
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)
rgs, _ = client.GetRegionsByKeyRange(env.ctx, pd.NewKeyRange([]byte(""), []byte("")), 100)
re.Equal(int64(2), rgs.Count)
}

func (suite *httpClientTestSuite) TestGetMinResolvedTSByStoresIDs() {
Expand Down

0 comments on commit 3f67cac

Please sign in to comment.