From 61b15c61b0f5015b30336bca0f279493c6a57123 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Thu, 4 Jan 2024 14:56:02 +0800 Subject: [PATCH] http: add GetEmptyRegions API (#7660) ref tikv/pd#7300 Signed-off-by: lance6716 --- client/http/interface.go | 15 +++++++++++++++ client/http/request_info.go | 1 + tests/integrations/client/http_client_test.go | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/client/http/interface.go b/client/http/interface.go index 4c2bb596002..6e2900dee00 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -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) @@ -204,6 +205,20 @@ func (c *client) GetRegionsByStoreID(ctx context.Context, storeID uint64) (*Regi return ®ions, 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(®ions)) + if err != nil { + return nil, err + } + return ®ions, 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) { diff --git a/client/http/request_info.go b/client/http/request_info.go index 060c7fabff6..9acbdd03d2a 100644 --- a/client/http/request_info.go +++ b/client/http/request_info.go @@ -26,6 +26,7 @@ const ( getRegionsName = "GetRegions" getRegionsByKeyRangeName = "GetRegionsByKeyRange" getRegionsByStoreIDName = "GetRegionsByStoreID" + getEmptyRegionsName = "GetEmptyRegions" getRegionsReplicatedStateByKeyRangeName = "GetRegionsReplicatedStateByKeyRange" getHotReadRegionsName = "GetHotReadRegions" getHotWriteRegionsName = "GetHotWriteRegions" diff --git a/tests/integrations/client/http_client_test.go b/tests/integrations/client/http_client_test.go index 3ba22e664d8..5d892674a7e 100644 --- a/tests/integrations/client/http_client_test.go +++ b/tests/integrations/client/http_client_test.go @@ -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)