Skip to content

Commit

Permalink
Refine GetMinResolvedTSByStoresIDs and its test
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Nov 7, 2023
1 parent ed963c5 commit 216b5b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 7 additions & 3 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Client interface {
GetHotReadRegions(context.Context) (*StoreHotPeersInfos, error)
GetHotWriteRegions(context.Context) (*StoreHotPeersInfos, error)
GetStores(context.Context) (*StoresInfo, error)
GetMinResolvedTSByStoresIDs(context.Context, []string) (uint64, map[uint64]uint64, error)
GetMinResolvedTSByStoresIDs(context.Context, []uint64) (uint64, map[uint64]uint64, error)
Close()
}

Expand Down Expand Up @@ -250,15 +250,19 @@ func (c *client) GetStores(ctx context.Context) (*StoresInfo, error) {
}

// GetMinResolvedTSByStoresIDs get min-resolved-ts by stores IDs.
func (c *client) GetMinResolvedTSByStoresIDs(ctx context.Context, storeIDs []string) (uint64, map[uint64]uint64, error) {
func (c *client) GetMinResolvedTSByStoresIDs(ctx context.Context, storeIDs []uint64) (uint64, map[uint64]uint64, error) {
uri := MinResolvedTSPrefix
// scope is an optional parameter, it can be `cluster` or specified store IDs.
// - When no scope is given, cluster-level's min_resolved_ts will be returned and storesMinResolvedTS will be nil.
// - When scope is `cluster`, cluster-level's min_resolved_ts will be returned and storesMinResolvedTS will be filled.
// - When scope given a list of stores, min_resolved_ts will be provided for each store
// and the scope-specific min_resolved_ts will be returned.
if len(storeIDs) != 0 {
uri = fmt.Sprintf("%s?scope=%s", uri, strings.Join(storeIDs, ","))
storeIDStrs := make([]string, len(storeIDs))
for idx, id := range storeIDs {
storeIDStrs[idx] = fmt.Sprintf("%d", id)
}
uri = fmt.Sprintf("%s?scope=%s", uri, strings.Join(storeIDStrs, ","))
}
resp := struct {
MinResolvedTS uint64 `json:"min_resolved_ts"`
Expand Down
16 changes: 15 additions & 1 deletion tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package client_test

import (
"context"
"math"
"testing"

"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -65,9 +66,22 @@ func (suite *httpClientTestSuite) TearDownSuite() {

func (suite *httpClientTestSuite) TestGetMinResolvedTSByStoresIDs() {
re := suite.Require()

// Get the cluster-level min resolved TS.
minResolvedTS, storeMinResolvedTSMap, err := suite.client.GetMinResolvedTSByStoresIDs(suite.ctx, nil)
re.NoError(err)
re.Greater(minResolvedTS, uint64(0))
re.Empty(storeMinResolvedTSMap)
// Get the store-level min resolved TS.
minResolvedTS, storeMinResolvedTSMap, err = suite.client.GetMinResolvedTSByStoresIDs(suite.ctx, []uint64{1})
re.NoError(err)
re.Greater(minResolvedTS, uint64(0))
re.Len(storeMinResolvedTSMap, 1)
re.Equal(minResolvedTS, storeMinResolvedTSMap[1])
// Get the store-level min resolved TS with an invalid store ID.
minResolvedTS, storeMinResolvedTSMap, err = suite.client.GetMinResolvedTSByStoresIDs(suite.ctx, []uint64{1, 2})
re.NoError(err)
re.Greater(minResolvedTS, uint64(0))
re.Len(storeMinResolvedTSMap, 2)
re.Equal(minResolvedTS, storeMinResolvedTSMap[1])
re.Equal(uint64(math.MaxUint64), storeMinResolvedTSMap[2])
}

0 comments on commit 216b5b7

Please sign in to comment.