Skip to content

Commit

Permalink
Address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Nov 28, 2023
1 parent fc17587 commit f62d10c
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type Client interface {
GetHistoryHotRegions(context.Context, *HistoryHotRegionsRequest) (*HistoryHotRegions, error)
GetRegionStatusByKeyRange(context.Context, *KeyRange) (*RegionStats, error)
GetStores(context.Context) (*StoresInfo, error)
/* Config-related interfaces */
GetScheduleConfig(context.Context) (map[string]interface{}, error)
SetScheduleConfig(context.Context, map[string]interface{}) error
/* Rule-related interfaces */
GetAllPlacementRuleBundles(context.Context) ([]*GroupBundle, error)
GetPlacementRuleBundleByGroup(context.Context, string) (*GroupBundle, error)
Expand Down Expand Up @@ -196,9 +199,9 @@ func (c *client) execDuration(name string, duration time.Duration) {
type HeaderOption func(header http.Header)

// WithAllowFollowerHandle sets the header field to allow a PD follower to handle this request.
func WithAllowFollowerHandle(allow bool) HeaderOption {
func WithAllowFollowerHandle() HeaderOption {
return func(header http.Header) {
header.Set("PD-Allow-follower-handle", fmt.Sprintf("%t", allow))
header.Set("PD-Allow-follower-handle", "true")
}
}

Expand Down Expand Up @@ -387,7 +390,7 @@ func (c *client) GetHistoryHotRegions(ctx context.Context, req *HistoryHotRegion
err = c.requestWithRetry(ctx,
"GetHistoryHotRegions", HotHistory,
http.MethodGet, bytes.NewBuffer(reqJSON), &historyHotRegions,
WithAllowFollowerHandle(true))
WithAllowFollowerHandle())
if err != nil {
return nil, err
}
Expand All @@ -408,6 +411,29 @@ func (c *client) GetRegionStatusByKeyRange(ctx context.Context, keyRange *KeyRan
return &regionStats, nil
}

// GetScheduleConfig gets the schedule configurations.
func (c *client) GetScheduleConfig(ctx context.Context) (map[string]interface{}, error) {
var config map[string]interface{}
err := c.requestWithRetry(ctx,
"GetScheduleConfig", ScheduleConfig,
http.MethodGet, http.NoBody, &config)
if err != nil {
return nil, err
}
return config, nil
}

// SetScheduleConfig sets the schedule configurations.
func (c *client) SetScheduleConfig(ctx context.Context, config map[string]interface{}) error {
configJSON, err := json.Marshal(config)
if err != nil {
return errors.Trace(err)
}
return c.requestWithRetry(ctx,
"SetScheduleConfig", ScheduleConfig,
http.MethodPost, bytes.NewBuffer(configJSON), nil)
}

// GetStores gets the stores info.
func (c *client) GetStores(ctx context.Context) (*StoresInfo, error) {
var stores StoresInfo
Expand Down

0 comments on commit f62d10c

Please sign in to comment.