Skip to content

Commit

Permalink
http: add GetEmptyRegions API (tikv#7660)
Browse files Browse the repository at this point in the history
ref tikv#7300

Signed-off-by: lance6716 <[email protected]>
  • Loading branch information
lance6716 authored Jan 4, 2024
1 parent a4d2f1c commit 61b15c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Client interface {
GetRegions(context.Context) (*RegionsInfo, error)
GetRegionsByKeyRange(context.Context, *KeyRange, int) (*RegionsInfo, error)
GetRegionsByStoreID(context.Context, uint64) (*RegionsInfo, error)
GetEmptyRegions(context.Context) (*RegionsInfo, error)
GetRegionsReplicatedStateByKeyRange(context.Context, *KeyRange) (string, error)
GetHotReadRegions(context.Context) (*StoreHotPeersInfos, error)
GetHotWriteRegions(context.Context) (*StoreHotPeersInfos, error)
Expand Down Expand Up @@ -204,6 +205,20 @@ func (c *client) GetRegionsByStoreID(ctx context.Context, storeID uint64) (*Regi
return &regions, nil
}

// GetEmptyRegions gets the empty regions info.
func (c *client) GetEmptyRegions(ctx context.Context) (*RegionsInfo, error) {
var regions RegionsInfo
err := c.request(ctx, newRequestInfo().
WithName(getEmptyRegionsName).
WithURI(EmptyRegions).
WithMethod(http.MethodGet).
WithResp(&regions))
if err != nil {
return nil, err
}
return &regions, nil
}

// GetRegionsReplicatedStateByKeyRange gets the regions replicated state info by key range.
// The keys in the key range should be encoded in the hex bytes format (without encoding to the UTF-8 bytes).
func (c *client) GetRegionsReplicatedStateByKeyRange(ctx context.Context, keyRange *KeyRange) (string, error) {
Expand Down
1 change: 1 addition & 0 deletions client/http/request_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
getRegionsName = "GetRegions"
getRegionsByKeyRangeName = "GetRegionsByKeyRange"
getRegionsByStoreIDName = "GetRegionsByStoreID"
getEmptyRegionsName = "GetEmptyRegions"
getRegionsReplicatedStateByKeyRangeName = "GetRegionsReplicatedStateByKeyRange"
getHotReadRegionsName = "GetHotReadRegions"
getHotWriteRegionsName = "GetHotWriteRegions"
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func (suite *httpClientTestSuite) TestMeta() {
re.NoError(err)
re.Equal(int64(2), regions.Count)
re.Len(regions.Regions, 2)
regions, err = suite.client.GetEmptyRegions(suite.ctx)
re.NoError(err)
re.Equal(int64(2), regions.Count)
re.Len(regions.Regions, 2)
state, err := suite.client.GetRegionsReplicatedStateByKeyRange(suite.ctx, pd.NewKeyRange([]byte("a1"), []byte("a3")))
re.NoError(err)
re.Equal("INPROGRESS", state)
Expand Down

0 comments on commit 61b15c6

Please sign in to comment.