diff --git a/client/http/client.go b/client/http/client.go index 2f4a060c8b68..5b6aaa003652 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -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) @@ -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") } } @@ -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 } @@ -408,6 +411,29 @@ func (c *client) GetRegionStatusByKeyRange(ctx context.Context, keyRange *KeyRan return ®ionStats, 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