pdutil

package
v1.1.0-beta.0...-56c07d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2024 License: Apache-2.0, Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// pd request retry time when connection fail
	PDRequestRetryTime = 120
)

Variables

View Source
var (

	// Schedulers represent region/leader schedulers which can impact on performance.
	Schedulers = map[string]struct{}{
		"balance-leader-scheduler":     {},
		"balance-hot-region-scheduler": {},
		"balance-region-scheduler":     {},

		"shuffle-leader-scheduler":     {},
		"shuffle-region-scheduler":     {},
		"shuffle-hot-region-scheduler": {},

		"evict-slow-store-scheduler": {},
	}
)

Functions

func DefaultExpectPDCfgGenerators

func DefaultExpectPDCfgGenerators() map[string]pauseConfigGenerator

DefaultExpectPDCfgGenerators returns default pd config generators

func FetchPDVersion

func FetchPDVersion(ctx context.Context, pdHTTPCli pdhttp.Client) (*semver.Version, error)

FetchPDVersion get pd version

func GetPlacementRules

func GetPlacementRules(ctx context.Context, pdAddr string, tlsConf *tls.Config) ([]pdtypes.Rule, error)

GetPlacementRules return the current placement rules.

func PauseSchedulersByKeyRange

func PauseSchedulersByKeyRange(
	ctx context.Context,
	pdHTTPCli pdhttp.Client,
	startKey, endKey []byte,
) (done <-chan struct{}, err error)

PauseSchedulersByKeyRange will pause schedulers for regions in the specific key range. This function will spawn a goroutine to keep pausing schedulers periodically until the context is done. The return done channel is used to notify the caller that the background goroutine is exited.

func SearchPlacementRule

func SearchPlacementRule(tableID int64, placementRules []pdtypes.Rule, role pdtypes.PeerRoleType) *pdtypes.Rule

SearchPlacementRule returns the placement rule matched to the table or nil.

Types

type ClusterConfig

type ClusterConfig struct {
	// Enable PD schedulers before restore
	Schedulers []string `json:"schedulers"`
	// Original scheudle configuration
	ScheduleCfg map[string]any `json:"schedule_cfg"`
}

ClusterConfig represents a set of scheduler whose config have been modified along with their original config.

type KeyRangeRule

type KeyRangeRule struct {
	StartKeyHex string `json:"start_key"` // hex format start key, for marshal/unmarshal
	EndKeyHex   string `json:"end_key"`   // hex format end key, for marshal/unmarshal
}

KeyRangeRule contains the start key and end key of the LabelRule. This struct is partially copied from https://github.com/tikv/pd/blob/783d060861cef37c38cbdcab9777fe95c17907fe/server/schedule/labeler/rules.go#L62.

type LabelRule

type LabelRule struct {
	ID       string        `json:"id"`
	Labels   []RegionLabel `json:"labels"`
	RuleType string        `json:"rule_type"`
	Data     any           `json:"data"`
}

LabelRule is the rule to assign labels to a region. This struct is partially copied from https://github.com/tikv/pd/blob/783d060861cef37c38cbdcab9777fe95c17907fe/server/schedule/labeler/rules.go#L41.

type PdController

type PdController struct {

	// control the ttl of pausing schedulers
	SchedulerPauseTTL time.Duration
	// contains filtered or unexported fields
}

PdController manage get/update config from pd.

func NewPdController

func NewPdController(
	ctx context.Context,
	pdAddrs []string,
	tlsConf *tls.Config,
	securityOption pd.SecurityOption,
) (*PdController, error)

NewPdController creates a new PdController.

func NewPdControllerWithPDClient

func NewPdControllerWithPDClient(pdClient pd.Client, pdHTTPCli pdhttp.Client, v *semver.Version) *PdController

func (*PdController) CanPauseSchedulerByKeyRange

func (p *PdController) CanPauseSchedulerByKeyRange() bool

CanPauseSchedulerByKeyRange returns whether the scheduler can be paused by key range.

func (*PdController) Close

func (p *PdController) Close()

Close closes the connection to pd.

func (*PdController) GenRestoreSchedulerFunc

func (p *PdController) GenRestoreSchedulerFunc(config ClusterConfig,
	configsNeedRestore map[string]pauseConfigGenerator) UndoFunc

GenRestoreSchedulerFunc gen restore func

func (*PdController) GetClusterVersion

func (p *PdController) GetClusterVersion(ctx context.Context) (string, error)

GetClusterVersion returns the current cluster version.

func (*PdController) GetMinResolvedTS

func (p *PdController) GetMinResolvedTS(ctx context.Context) (uint64, error)

GetMinResolvedTS get min-resolved-ts from pd

func (*PdController) GetPDClient

func (p *PdController) GetPDClient() pd.Client

GetPDClient set pd addrs and cli for test.

func (*PdController) GetPDHTTPClient

func (p *PdController) GetPDHTTPClient() pdhttp.Client

GetPDHTTPClient returns the pd http client.

func (*PdController) GetPDScheduleConfig

func (p *PdController) GetPDScheduleConfig(ctx context.Context) (map[string]any, error)

GetPDScheduleConfig returns PD schedule config value associated with the key. It returns nil if there is no such config item.

func (*PdController) GetRegionCount

func (p *PdController) GetRegionCount(ctx context.Context, startKey, endKey []byte) (int, error)

GetRegionCount returns the region count in the specified range.

func (*PdController) GetStoreInfo

func (p *PdController) GetStoreInfo(ctx context.Context, storeID uint64) (*pdhttp.StoreInfo, error)

GetStoreInfo returns the info of store with the specified id.

func (*PdController) ListSchedulers

func (p *PdController) ListSchedulers(ctx context.Context) ([]string, error)

ListSchedulers list all pd scheduler.

func (*PdController) MakeUndoFunctionByConfig

func (p *PdController) MakeUndoFunctionByConfig(config ClusterConfig) UndoFunc

MakeUndoFunctionByConfig return an UndoFunc based on specified ClusterConfig

func (*PdController) MarkRecovering

func (p *PdController) MarkRecovering(ctx context.Context) error

MarkRecovering mark pd into recovering

func (*PdController) RecoverBaseAllocID

func (p *PdController) RecoverBaseAllocID(ctx context.Context, id uint64) error

RecoverBaseAllocID recover base alloc id

func (*PdController) RemoveAllPDSchedulers

func (p *PdController) RemoveAllPDSchedulers(ctx context.Context) (undo UndoFunc, err error)

RemoveAllPDSchedulers pause pd scheduler during the snapshot backup and restore

func (*PdController) RemoveSchedulers

func (p *PdController) RemoveSchedulers(ctx context.Context) (undo UndoFunc, err error)

RemoveSchedulers removes the schedulers that may slow down BR speed.

func (*PdController) RemoveSchedulersWithCfg

func (p *PdController) RemoveSchedulersWithCfg(ctx context.Context, removeCfg ClusterConfig) error

RemoveSchedulersWithCfg removes pd schedulers and configs with specified ClusterConfig

func (*PdController) RemoveSchedulersWithConfig

func (p *PdController) RemoveSchedulersWithConfig(
	ctx context.Context,
) (undo UndoFunc, config *ClusterConfig, err error)

RemoveSchedulersWithConfig removes the schedulers that may slow down BR speed.

func (*PdController) RemoveSchedulersWithConfigGenerator

func (p *PdController) RemoveSchedulersWithConfigGenerator(
	ctx context.Context,
	pdConfigGenerators map[string]pauseConfigGenerator,
) (origin ClusterConfig, modified ClusterConfig, err error)

RemoveSchedulersWithConfigGenerator pause scheduler with custom config generator

func (*PdController) RemoveSchedulersWithOrigin

func (p *PdController) RemoveSchedulersWithOrigin(ctx context.Context) (
	origin ClusterConfig,
	modified ClusterConfig,
	err error,
)

RemoveSchedulersWithOrigin pause and remove br related schedule configs and return the origin and modified configs

func (*PdController) ResetTS

func (p *PdController) ResetTS(ctx context.Context, ts uint64) error

ResetTS reset current ts of pd

func (*PdController) ResumeSchedulers

func (p *PdController) ResumeSchedulers(ctx context.Context, schedulers []string) error

ResumeSchedulers resume pd scheduler.

func (*PdController) SetPDClient

func (p *PdController) SetPDClient(pdClient pd.Client)

SetPDClient set pd addrs and cli for test.

func (*PdController) UnmarkRecovering

func (p *PdController) UnmarkRecovering(ctx context.Context) error

UnmarkRecovering unmark pd recovering

func (*PdController) UpdatePDScheduleConfig

func (p *PdController) UpdatePDScheduleConfig(ctx context.Context) error

UpdatePDScheduleConfig updates PD schedule config value associated with the key.

type RegionLabel

type RegionLabel struct {
	Key     string `json:"key"`
	Value   string `json:"value"`
	TTL     string `json:"ttl,omitempty"`
	StartAt string `json:"start_at,omitempty"`
}

RegionLabel is the label of a region. This struct is partially copied from https://github.com/tikv/pd/blob/783d060861cef37c38cbdcab9777fe95c17907fe/server/schedule/labeler/rules.go#L31.

type UndoFunc

type UndoFunc func(context.Context) error

UndoFunc is a 'undo' operation of some undoable command. (e.g. RemoveSchedulers).

var Nop UndoFunc = func(context.Context) error { return nil }

Nop is the 'zero value' of undo func.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL