operator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSlowExecutorRate is the fast rate of the step executor.
	// default: 6 s/Mb
	DefaultSlowExecutorRate = 6
	// DefaultFastExecutorRate is the slow rate of the step executor.
	// default:  0.6 s/Mb
	DefaultFastExecutorRate = 0.6
	// FastStepWaitTime is the duration that the OpStep may take.
	// there are some steps that may take a short time, such as transfer leader, remove peer etc.
	// It should consider the latency of handling region heartbeat especially big cluster.
	// The update duration of region heartbeat should be less than the region heartbeat interval(default 60s).
	FastStepWaitTime = 60 * time.Second
	// SlowStepWaitTime is the duration that the OpStep may take.
	// there are some steps that may take a long time, such as add peer, merge region etc.
	SlowStepWaitTime = 10 * time.Minute
)
View Source
const OpDescLeaveJointState = "leave-joint-state"

OpDescLeaveJointState is the expected desc for LeaveJointStateOperator.

View Source
const (
	// OperatorExpireTime is the duration that when an operator is not started
	// after it, the operator will be considered expired.
	OperatorExpireTime = 3 * time.Second
)

Variables

View Source
var (

	// OperatorLimitCounter exposes the counter when meeting limit.
	OperatorLimitCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "pd",
			Subsystem: "schedule",
			Name:      "operator_limit",
			Help:      "Counter of operator meeting limit",
		}, []string{"type", "name"})

	// OperatorExceededStoreLimitCounter exposes the counter when operator meet exceeded store limit.
	OperatorExceededStoreLimitCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "pd",
			Subsystem: "schedule",
			Name:      "operator_exceeded_store_limit",
			Help:      "Counter of operator meeting store limit",
		}, []string{"desc"})
)

Functions

func IsEndStatus

func IsEndStatus(s OpStatus) bool

IsEndStatus checks whether s is an end status.

func OpStatusToPDPB

func OpStatusToPDPB(s OpStatus) pdpb.OperatorStatus

OpStatusToPDPB converts OpStatus to pdpb.OperatorStatus.

func OpStatusToString

func OpStatusToString(s OpStatus) string

OpStatusToString converts Status to string.

func SkipOriginJointStateCheck

func SkipOriginJointStateCheck(b *Builder)

SkipOriginJointStateCheck lets the builder skip the joint state check for origin peers.

func SkipPlacementRulesCheck

func SkipPlacementRulesCheck(b *Builder)

SkipPlacementRulesCheck lets the builder skip the placement rules check for origin and target peers.

Types

type AddLearner

type AddLearner struct {
	ToStore, PeerID, SendStore uint64
	IsLightWeight              bool
	IsWitness                  bool
}

AddLearner is an OpStep that adds a region learner peer.

func (AddLearner) CheckInProgress

func (al AddLearner) CheckInProgress(ci ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (AddLearner) ConfVerChanged

func (al AddLearner) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (AddLearner) GetCmd

func (al AddLearner) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (AddLearner) Influence

func (al AddLearner) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (AddLearner) IsFinish

func (al AddLearner) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (AddLearner) String

func (al AddLearner) String() string

func (AddLearner) Timeout

func (al AddLearner) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type AddPeer

type AddPeer struct {
	ToStore, PeerID uint64
	IsLightWeight   bool
	IsWitness       bool
}

AddPeer is an OpStep that adds a region peer.

func (AddPeer) CheckInProgress

func (ap AddPeer) CheckInProgress(ci ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (AddPeer) ConfVerChanged

func (ap AddPeer) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (AddPeer) GetCmd

func (ap AddPeer) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (AddPeer) Influence

func (ap AddPeer) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (AddPeer) IsFinish

func (ap AddPeer) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (AddPeer) String

func (ap AddPeer) String() string

func (AddPeer) Timeout

func (ap AddPeer) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type BatchSwitchWitness

type BatchSwitchWitness struct {
	ToWitnesses    []BecomeWitness
	ToNonWitnesses []BecomeNonWitness
}

BatchSwitchWitness is an OpStep that batch switch witness.

func (BatchSwitchWitness) CheckInProgress

func (bsw BatchSwitchWitness) CheckInProgress(ci ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (BatchSwitchWitness) ConfVerChanged

func (bsw BatchSwitchWitness) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (BatchSwitchWitness) GetCmd

func (bsw BatchSwitchWitness) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (BatchSwitchWitness) Influence

func (bsw BatchSwitchWitness) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (BatchSwitchWitness) IsFinish

func (bsw BatchSwitchWitness) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (BatchSwitchWitness) String

func (bsw BatchSwitchWitness) String() string

func (BatchSwitchWitness) Timeout

func (bsw BatchSwitchWitness) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type BecomeNonWitness

type BecomeNonWitness struct {
	PeerID, StoreID, SendStore uint64
}

BecomeNonWitness is an OpStep that makes a peer become a non-witness.

func (BecomeNonWitness) CheckInProgress

func (bn BecomeNonWitness) CheckInProgress(ci ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (BecomeNonWitness) ConfVerChanged

func (bn BecomeNonWitness) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (BecomeNonWitness) GetCmd

func (bn BecomeNonWitness) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (BecomeNonWitness) Influence

func (bn BecomeNonWitness) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (BecomeNonWitness) IsFinish

func (bn BecomeNonWitness) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (BecomeNonWitness) String

func (bn BecomeNonWitness) String() string

func (BecomeNonWitness) Timeout

func (bn BecomeNonWitness) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type BecomeWitness

type BecomeWitness struct {
	PeerID, StoreID uint64
}

BecomeWitness is an OpStep that makes a peer become a witness.

func (BecomeWitness) CheckInProgress

func (bw BecomeWitness) CheckInProgress(ci ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (BecomeWitness) ConfVerChanged

func (bw BecomeWitness) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (BecomeWitness) GetCmd

GetCmd returns the schedule command for heartbeat response.

func (BecomeWitness) Influence

func (bw BecomeWitness) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (BecomeWitness) IsFinish

func (bw BecomeWitness) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (BecomeWitness) String

func (bw BecomeWitness) String() string

func (BecomeWitness) Timeout

func (bw BecomeWitness) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type Builder

type Builder struct {
	// basic info
	ClusterInformer
	// contains filtered or unexported fields
}

Builder is used to create operators. Usage:

op, err := NewBuilder(desc, cluster, region).
            RemovePeer(store1).
            AddPeer(peer1).
            SetLeader(store2).
            Build(kind)

The generated Operator will choose the most appropriate execution order according to various constraints.

func NewBuilder

func NewBuilder(desc string, ci ClusterInformer, region *core.RegionInfo, opts ...BuilderOption) *Builder

NewBuilder creates a Builder.

func (*Builder) AddPeer

func (b *Builder) AddPeer(peer *metapb.Peer) *Builder

AddPeer records an add Peer operation in Builder. If peer.Id is 0, the builder will allocate a new peer ID later.

func (*Builder) BecomeNonWitness

func (b *Builder) BecomeNonWitness(storeID uint64) *Builder

BecomeNonWitness records a switch to non-witness operation in Builder.

func (*Builder) BecomeWitness

func (b *Builder) BecomeWitness(storeID uint64) *Builder

BecomeWitness records a switch to witness operation in Builder.

func (*Builder) Build

func (b *Builder) Build(kind OpKind) (*Operator, error)

Build creates the Operator.

func (*Builder) DemoteVoter

func (b *Builder) DemoteVoter(storeID uint64) *Builder

DemoteVoter records a demote voter operation in Builder.

func (*Builder) EnableForceTargetLeader

func (b *Builder) EnableForceTargetLeader() *Builder

EnableForceTargetLeader marks the step of transferring leader to target is forcible.

func (*Builder) EnableLightWeight

func (b *Builder) EnableLightWeight() *Builder

EnableLightWeight marks the region as light weight. It is used for scatter regions.

func (*Builder) PromoteLearner

func (b *Builder) PromoteLearner(storeID uint64) *Builder

PromoteLearner records a promote learner operation in Builder.

func (*Builder) RemovePeer

func (b *Builder) RemovePeer(storeID uint64) *Builder

RemovePeer records a remove peer operation in Builder.

func (*Builder) SetExpectedRoles

func (b *Builder) SetExpectedRoles(roles map[uint64]placement.PeerRoleType) *Builder

SetExpectedRoles records expected roles of target peers. It may update `targetLeaderStoreID` if there is a peer has role `leader` or `follower`.

func (*Builder) SetLeader

func (b *Builder) SetLeader(storeID uint64) *Builder

SetLeader records the target leader in Builder.

func (*Builder) SetLeaders

func (b *Builder) SetLeaders(storeIDs []uint64) *Builder

SetLeaders records all valid target leaders in Builder.

func (*Builder) SetPeers

func (b *Builder) SetPeers(peers map[uint64]*metapb.Peer) *Builder

SetPeers resets the target peer list.

If peer's ID is 0, the builder will allocate a new ID later. If current target leader does not exist in peers, it will be reset.

type BuilderOption

type BuilderOption func(*Builder)

BuilderOption is used to create operator builder.

type ChangePeerV2Enter

type ChangePeerV2Enter struct {
	PromoteLearners []PromoteLearner
	DemoteVoters    []DemoteVoter
}

ChangePeerV2Enter is an OpStep that uses joint consensus to request all PromoteLearner and DemoteVoter.

func (ChangePeerV2Enter) CheckInProgress

func (cpe ChangePeerV2Enter) CheckInProgress(_ ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (ChangePeerV2Enter) ConfVerChanged

func (cpe ChangePeerV2Enter) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (ChangePeerV2Enter) GetCmd

func (cpe ChangePeerV2Enter) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (ChangePeerV2Enter) Influence

func (cpe ChangePeerV2Enter) Influence(_ OpInfluence, _ *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (ChangePeerV2Enter) IsFinish

func (cpe ChangePeerV2Enter) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (ChangePeerV2Enter) String

func (cpe ChangePeerV2Enter) String() string

func (ChangePeerV2Enter) Timeout

func (cpe ChangePeerV2Enter) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type ChangePeerV2Leave

type ChangePeerV2Leave struct {
	PromoteLearners []PromoteLearner
	DemoteVoters    []DemoteVoter
}

ChangePeerV2Leave is an OpStep that leaves the joint state.

func (ChangePeerV2Leave) CheckInProgress

func (cpl ChangePeerV2Leave) CheckInProgress(_ ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (ChangePeerV2Leave) ConfVerChanged

func (cpl ChangePeerV2Leave) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (ChangePeerV2Leave) GetCmd

func (cpl ChangePeerV2Leave) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (ChangePeerV2Leave) Influence

func (cpl ChangePeerV2Leave) Influence(_ OpInfluence, _ *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (ChangePeerV2Leave) IsFinish

func (cpl ChangePeerV2Leave) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (ChangePeerV2Leave) String

func (cpl ChangePeerV2Leave) String() string

func (ChangePeerV2Leave) Timeout

func (cpl ChangePeerV2Leave) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type ClusterInformer

type ClusterInformer interface {
	GetBasicCluster() *core.BasicCluster
	GetOpts() config.Config
	GetStoreConfig() config.StoreConfig
	GetRuleManager() *placement.RuleManager
	GetAllocator() id.Allocator
}

ClusterInformer provides the necessary information for building operator.

type DemoteVoter

type DemoteVoter struct {
	ToStore, PeerID uint64
	IsWitness       bool
}

DemoteVoter is very similar to DemoteFollower. But it allows Demote Leader. Note: It is not an OpStep, only a sub step in ChangePeerV2Enter and ChangePeerV2Leave.

func (DemoteVoter) ConfVerChanged

func (dv DemoteVoter) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (DemoteVoter) GetCmd

func (dv DemoteVoter) GetCmd(_ *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (DemoteVoter) IsFinish

func (dv DemoteVoter) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (DemoteVoter) String

func (dv DemoteVoter) String() string

func (DemoteVoter) Timeout

func (dv DemoteVoter) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type MergeRegion

type MergeRegion struct {
	FromRegion *metapb.Region
	ToRegion   *metapb.Region
	// there are two regions involved in merge process,
	// so to keep them from other scheduler,
	// both of them should add MerRegion operatorStep.
	// But actually, TiKV just needs the region want to be merged to get the merge request,
	// thus use a IsPassive mark to indicate that
	// this region doesn't need to send merge request to TiKV.
	IsPassive bool
}

MergeRegion is an OpStep that merge two regions.

func (MergeRegion) CheckInProgress

func (mr MergeRegion) CheckInProgress(_ ClusterInformer, _ *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (MergeRegion) ConfVerChanged

func (mr MergeRegion) ConfVerChanged(_ *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (MergeRegion) GetCmd

func (mr MergeRegion) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (MergeRegion) Influence

func (mr MergeRegion) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (MergeRegion) IsFinish

func (mr MergeRegion) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (MergeRegion) String

func (mr MergeRegion) String() string

func (MergeRegion) Timeout

func (mr MergeRegion) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take. The merge step need more time to finish but less than slow step.

type OpHistory

type OpHistory struct {
	FinishTime time.Time
	From, To   uint64
	Kind       constant.ResourceKind
}

OpHistory is used to log and visualize completed operators.

type OpInfluence

type OpInfluence struct {
	StoresInfluence map[uint64]*StoreInfluence
}

OpInfluence records the influence of the cluster.

func NewOpInfluence

func NewOpInfluence() *OpInfluence

NewOpInfluence creates a OpInfluence.

func (*OpInfluence) Add

func (m *OpInfluence) Add(other *OpInfluence)

Add adds another influence.

func (OpInfluence) GetStoreInfluence

func (m OpInfluence) GetStoreInfluence(id uint64) *StoreInfluence

GetStoreInfluence get storeInfluence of specific store.

type OpKind

type OpKind uint32

OpKind is a bit field to identify operator types.

const (
	// Initiated by admin.
	OpAdmin OpKind = 1 << iota
	// Initiated by merge checker or merge scheduler. Note that it may not include region merge.
	// the order describe the operator's producer and is very helpful to decouple scheduler or checker limit
	OpMerge
	// Initiated by range scheduler.
	OpRange
	// Initiated by replica checker.
	OpReplica
	// Include region split. Initiated by rule checker if `kind & OpAdmin == 0`.
	OpSplit
	// Initiated by hot region scheduler.
	OpHotRegion
	// Include peer addition or removal or switch witness. This means that this operator may take a long time.
	OpRegion
	// Include leader transfer.
	OpLeader
	// Include witness leader transfer.
	OpWitnessLeader
	// Include witness transfer.
	OpWitness
)

Flags for operators.

func ParseOperatorKind

func ParseOperatorKind(str string) (OpKind, error)

ParseOperatorKind converts string (flag name list concat by ',') to OpKind.

func (OpKind) String

func (k OpKind) String() string

type OpRecord

type OpRecord struct {
	*Operator
	FinishTime time.Time
	// contains filtered or unexported fields
}

OpRecord is used to log and visualize completed operators. NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.

func (*OpRecord) MarshalJSON

func (o *OpRecord) MarshalJSON() ([]byte, error)

MarshalJSON returns the status of operator as a JSON string

func (*OpRecord) String

func (o *OpRecord) String() string

type OpStatus

type OpStatus = uint32

OpStatus represents the status of an Operator.

const (
	// Status list
	// Just created. Next status: {RUNNING, CANCELED, EXPIRED}.
	CREATED OpStatus = iota
	// Started and not finished. Next status: {SUCCESS, CANCELED, REPLACED, TIMEOUT}.
	STARTED
	// Followings are end status, i.e. no next status.
	SUCCESS  // Finished successfully
	CANCELED // Canceled due to some reason
	REPLACED // Replaced by an higher priority operator
	EXPIRED  // Didn't start to run for too long
	TIMEOUT  // Running for too long

)

Status list

type OpStatusTracker

type OpStatusTracker struct {
	// contains filtered or unexported fields
}

OpStatusTracker represents the status of an operator.

func NewOpStatusTracker

func NewOpStatusTracker() OpStatusTracker

NewOpStatusTracker creates an OpStatus.

func (*OpStatusTracker) CheckExpired

func (trk *OpStatusTracker) CheckExpired(exp time.Duration) bool

CheckExpired checks if expired, and update the current status.

func (*OpStatusTracker) CheckTimeout

func (trk *OpStatusTracker) CheckTimeout(duration time.Duration) bool

CheckTimeout returns true if timeout, and update the current status.

func (*OpStatusTracker) IsEnd

func (trk *OpStatusTracker) IsEnd() bool

IsEnd checks whether the current status is an end status.

func (*OpStatusTracker) ReachTime

func (trk *OpStatusTracker) ReachTime() time.Time

ReachTime returns the reach time of current status.

func (*OpStatusTracker) ReachTimeOf

func (trk *OpStatusTracker) ReachTimeOf(s OpStatus) time.Time

ReachTimeOf returns the time when reached given status. If didn't reached the given status, return zero.

func (*OpStatusTracker) Status

func (trk *OpStatusTracker) Status() OpStatus

Status returns current status.

func (*OpStatusTracker) String

func (trk *OpStatusTracker) String() string

String implements fmt.Stringer.

func (*OpStatusTracker) To

func (trk *OpStatusTracker) To(dst OpStatus) bool

To transfer the current status to dst if this transition is valid, returns whether transferred.

type OpStep

type OpStep interface {
	fmt.Stringer
	ConfVerChanged(region *core.RegionInfo) uint64
	IsFinish(region *core.RegionInfo) bool
	CheckInProgress(ci ClusterInformer, region *core.RegionInfo) error
	Influence(opInfluence OpInfluence, region *core.RegionInfo)
	Timeout(regionSize int64) time.Duration
	GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse
}

OpStep describes the basic scheduling steps that can not be subdivided.

type Operator

type Operator struct {
	Counters         []prometheus.Counter
	FinishedCounters []prometheus.Counter
	AdditionalInfos  map[string]string
	ApproximateSize  int64
	// contains filtered or unexported fields
}

Operator contains execution steps generated by scheduler. NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.

func CreateAddPeerOperator

func CreateAddPeerOperator(desc string, ci ClusterInformer, region *core.RegionInfo, peer *metapb.Peer, kind OpKind) (*Operator, error)

CreateAddPeerOperator creates an operator that adds a new peer.

func CreateDemoteVoterOperator

func CreateDemoteVoterOperator(desc string, ci ClusterInformer, region *core.RegionInfo, peer *metapb.Peer) (*Operator, error)

CreateDemoteVoterOperator creates an operator that demotes a voter

func CreateForceTransferLeaderOperator

func CreateForceTransferLeaderOperator(desc string, ci ClusterInformer, region *core.RegionInfo, sourceStoreID uint64, targetStoreID uint64, kind OpKind) (*Operator, error)

CreateForceTransferLeaderOperator creates an operator that transfers the leader from a source store to a target store forcible.

func CreateLeaveJointStateOperator

func CreateLeaveJointStateOperator(desc string, ci ClusterInformer, origin *core.RegionInfo) (*Operator, error)

CreateLeaveJointStateOperator creates an operator that let region leave joint state.

func CreateMergeRegionOperator

func CreateMergeRegionOperator(desc string, ci ClusterInformer, source *core.RegionInfo, target *core.RegionInfo, kind OpKind) ([]*Operator, error)

CreateMergeRegionOperator creates an operator that merge two region into one.

func CreateMoveLeaderOperator

func CreateMoveLeaderOperator(desc string, ci ClusterInformer, region *core.RegionInfo, kind OpKind, oldStore uint64, peer *metapb.Peer) (*Operator, error)

CreateMoveLeaderOperator creates an operator that replaces an old leader with a new leader.

func CreateMovePeerOperator

func CreateMovePeerOperator(desc string, ci ClusterInformer, region *core.RegionInfo, kind OpKind, oldStore uint64, peer *metapb.Peer) (*Operator, error)

CreateMovePeerOperator creates an operator that replaces an old peer with a new peer.

func CreateMoveRegionOperator

func CreateMoveRegionOperator(desc string, ci ClusterInformer, region *core.RegionInfo, kind OpKind, roles map[uint64]placement.PeerRoleType) (*Operator, error)

CreateMoveRegionOperator creates an operator that moves a region to specified stores.

func CreateMoveWitnessOperator

func CreateMoveWitnessOperator(desc string, ci ClusterInformer, region *core.RegionInfo, sourceStoreID uint64, targetStoreID uint64) (*Operator, error)

CreateMoveWitnessOperator creates an operator that replaces an old witness with a new witness.

func CreateNonWitnessPeerOperator

func CreateNonWitnessPeerOperator(desc string, ci ClusterInformer, region *core.RegionInfo, peer *metapb.Peer) (*Operator, error)

CreateNonWitnessPeerOperator creates an operator that set a peer with non-witness

func CreatePromoteLearnerOperator

func CreatePromoteLearnerOperator(desc string, ci ClusterInformer, region *core.RegionInfo, peer *metapb.Peer) (*Operator, error)

CreatePromoteLearnerOperator creates an operator that promotes a learner.

func CreateRemovePeerOperator

func CreateRemovePeerOperator(desc string, ci ClusterInformer, kind OpKind, region *core.RegionInfo, storeID uint64) (*Operator, error)

CreateRemovePeerOperator creates an operator that removes a peer from region.

func CreateReplaceLeaderPeerOperator

func CreateReplaceLeaderPeerOperator(desc string, ci ClusterInformer, region *core.RegionInfo, kind OpKind, oldStore uint64, peer *metapb.Peer, leader *metapb.Peer) (*Operator, error)

CreateReplaceLeaderPeerOperator creates an operator that replaces an old peer with a new peer, and move leader from old store firstly.

func CreateScatterRegionOperator

func CreateScatterRegionOperator(desc string, ci ClusterInformer, origin *core.RegionInfo, targetPeers map[uint64]*metapb.Peer, targetLeader uint64) (*Operator, error)

CreateScatterRegionOperator creates an operator that scatters the specified region.

func CreateSplitRegionOperator

func CreateSplitRegionOperator(desc string, region *core.RegionInfo, kind OpKind, policy pdpb.CheckPolicy, keys [][]byte) (*Operator, error)

CreateSplitRegionOperator creates an operator that splits a region.

func CreateTransferLeaderOperator

func CreateTransferLeaderOperator(desc string, ci ClusterInformer, region *core.RegionInfo, sourceStoreID uint64, targetStoreID uint64, targetStoreIDs []uint64, kind OpKind) (*Operator, error)

CreateTransferLeaderOperator creates an operator that transfers the leader from a source store to a target store.

func CreateWitnessPeerOperator

func CreateWitnessPeerOperator(desc string, ci ClusterInformer, region *core.RegionInfo, peer *metapb.Peer) (*Operator, error)

CreateWitnessPeerOperator creates an operator that set a follower or learner peer with witness

func NewOperator

func NewOperator(desc, brief string, regionID uint64, regionEpoch *metapb.RegionEpoch, kind OpKind, approximateSize int64, steps ...OpStep) *Operator

NewOperator creates a new operator.

func NewTestOperator

func NewTestOperator(regionID uint64, regionEpoch *metapb.RegionEpoch, kind OpKind, steps ...OpStep) *Operator

NewTestOperator creates a test operator, only used for unit test.

func (*Operator) AttachKind

func (o *Operator) AttachKind(kind OpKind)

AttachKind attaches an operator kind for the operator.

func (*Operator) Brief

func (o *Operator) Brief() string

Brief returns the operator's short brief.

func (*Operator) Cancel

func (o *Operator) Cancel() bool

Cancel marks the operator canceled.

func (*Operator) Check

func (o *Operator) Check(region *core.RegionInfo) OpStep

Check checks if current step is finished, returns next step to take action. If operator is at an end status, check returns nil. It's safe to be called by multiple goroutine concurrently.

func (*Operator) CheckAndGetStatus

func (o *Operator) CheckAndGetStatus() OpStatus

CheckAndGetStatus returns operator status after `CheckExpired` and `CheckTimeout`.

func (*Operator) CheckExpired

func (o *Operator) CheckExpired() bool

CheckExpired checks if the operator is expired, and update the status.

func (*Operator) CheckSuccess

func (o *Operator) CheckSuccess() bool

CheckSuccess checks if all steps are finished, and update the status.

func (*Operator) CheckTimeout

func (o *Operator) CheckTimeout() bool

CheckTimeout returns true if the operator is timeout, and update the status.

func (*Operator) ConfVerChanged

func (o *Operator) ConfVerChanged(region *core.RegionInfo) (total uint64)

ConfVerChanged returns the number of confver has consumed by steps

func (*Operator) ContainNonWitnessStep

func (o *Operator) ContainNonWitnessStep() bool

ContainNonWitnessStep returns true if it contains the target OpStep

func (*Operator) Desc

func (o *Operator) Desc() string

Desc returns the operator's short description.

func (*Operator) ElapsedTime

func (o *Operator) ElapsedTime() time.Duration

ElapsedTime returns duration since it was created.

func (*Operator) GetAdditionalInfo

func (o *Operator) GetAdditionalInfo() string

GetAdditionalInfo returns additional info with string

func (*Operator) GetCreateTime

func (o *Operator) GetCreateTime() time.Time

GetCreateTime gets the create time of operator.

func (*Operator) GetPriorityLevel

func (o *Operator) GetPriorityLevel() constant.PriorityLevel

GetPriorityLevel gets the priority level.

func (*Operator) GetReachTimeOf

func (o *Operator) GetReachTimeOf(st OpStatus) time.Time

GetReachTimeOf returns the time when operator reaches the given status.

func (*Operator) GetStartTime

func (o *Operator) GetStartTime() time.Time

GetStartTime gets the start time of operator.

func (*Operator) HasStarted

func (o *Operator) HasStarted() bool

HasStarted returns whether operator has started.

func (*Operator) History

func (o *Operator) History() []OpHistory

History transfers the operator's steps to operator histories.

func (*Operator) IsEnd

func (o *Operator) IsEnd() bool

IsEnd checks if the operator is at and end status.

func (*Operator) IsLeaveJointStateOperator

func (o *Operator) IsLeaveJointStateOperator() bool

IsLeaveJointStateOperator returns true if the desc is OpDescLeaveJointState.

func (*Operator) Kind

func (o *Operator) Kind() OpKind

Kind returns operator's kind.

func (*Operator) Len

func (o *Operator) Len() int

Len returns the operator's steps count.

func (*Operator) MarshalJSON

func (o *Operator) MarshalJSON() ([]byte, error)

MarshalJSON serializes custom types to JSON.

func (*Operator) Record

func (o *Operator) Record(finishTime time.Time) *OpRecord

Record transfers the operator to OpRecord.

func (*Operator) RegionEpoch

func (o *Operator) RegionEpoch() *metapb.RegionEpoch

RegionEpoch returns the region's epoch that is attached to the operator.

func (*Operator) RegionID

func (o *Operator) RegionID() uint64

RegionID returns the region that operator is targeted.

func (*Operator) Replace

func (o *Operator) Replace() bool

Replace marks the operator replaced.

func (*Operator) RunningTime

func (o *Operator) RunningTime() time.Duration

RunningTime returns duration since it started.

func (*Operator) SchedulerKind

func (o *Operator) SchedulerKind() OpKind

SchedulerKind return the highest OpKind even if the operator has many OpKind fix #3778

func (*Operator) SetDesc

func (o *Operator) SetDesc(desc string)

SetDesc sets the description for the operator.

func (*Operator) SetPriorityLevel

func (o *Operator) SetPriorityLevel(level constant.PriorityLevel)

SetPriorityLevel sets the priority level for operator.

func (*Operator) SetStatusReachTime

func (o *Operator) SetStatusReachTime(st OpStatus, t time.Time)

SetStatusReachTime sets the reach time of the operator, only for test purpose.

func (*Operator) Start

func (o *Operator) Start() bool

Start sets the operator to STARTED status, returns whether succeeded.

func (*Operator) Status

func (o *Operator) Status() OpStatus

Status returns operator status.

func (*Operator) Step

func (o *Operator) Step(i int) OpStep

Step returns the i-th step.

func (*Operator) String

func (o *Operator) String() string

func (*Operator) Sync

func (o *Operator) Sync(other *Operator)

Sync some attribute with the given timeout.

func (*Operator) TotalInfluence

func (o *Operator) TotalInfluence(opInfluence OpInfluence, region *core.RegionInfo)

TotalInfluence calculates the store difference which whole operator steps make.

func (*Operator) UnfinishedInfluence

func (o *Operator) UnfinishedInfluence(opInfluence OpInfluence, region *core.RegionInfo)

UnfinishedInfluence calculates the store difference which unfinished operator steps make.

type PromoteLearner

type PromoteLearner struct {
	ToStore, PeerID uint64
	IsWitness       bool
}

PromoteLearner is an OpStep that promotes a region learner peer to normal voter.

func (PromoteLearner) CheckInProgress

func (pl PromoteLearner) CheckInProgress(_ ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (PromoteLearner) ConfVerChanged

func (pl PromoteLearner) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step. It is also used by ChangePeerV2Leave. Since there are currently four roles, we need to confirm whether it is a Voter, not a DemotingVoter, etc.

func (PromoteLearner) GetCmd

func (pl PromoteLearner) GetCmd(_ *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (PromoteLearner) Influence

func (pl PromoteLearner) Influence(_ OpInfluence, _ *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (PromoteLearner) IsFinish

func (pl PromoteLearner) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished. It is also used by ChangePeerV2Leave.

func (PromoteLearner) String

func (pl PromoteLearner) String() string

func (PromoteLearner) Timeout

func (pl PromoteLearner) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type RemovePeer

type RemovePeer struct {
	FromStore, PeerID uint64
	IsDownStore       bool
}

RemovePeer is an OpStep that removes a region peer.

func (RemovePeer) CheckInProgress

func (rp RemovePeer) CheckInProgress(_ ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (RemovePeer) ConfVerChanged

func (rp RemovePeer) ConfVerChanged(region *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (RemovePeer) GetCmd

func (rp RemovePeer) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (RemovePeer) Influence

func (rp RemovePeer) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (RemovePeer) IsFinish

func (rp RemovePeer) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (RemovePeer) String

func (rp RemovePeer) String() string

func (RemovePeer) Timeout

func (rp RemovePeer) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type SplitRegion

type SplitRegion struct {
	StartKey, EndKey []byte
	Policy           pdpb.CheckPolicy
	SplitKeys        [][]byte
}

SplitRegion is an OpStep that splits a region.

func (SplitRegion) CheckInProgress

func (sr SplitRegion) CheckInProgress(_ ClusterInformer, _ *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (SplitRegion) ConfVerChanged

func (sr SplitRegion) ConfVerChanged(_ *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (SplitRegion) GetCmd

func (sr SplitRegion) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (SplitRegion) Influence

func (sr SplitRegion) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (SplitRegion) IsFinish

func (sr SplitRegion) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (SplitRegion) String

func (sr SplitRegion) String() string

func (SplitRegion) Timeout

func (sr SplitRegion) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

type StoreInfluence

type StoreInfluence struct {
	RegionSize   int64
	RegionCount  int64
	LeaderSize   int64
	LeaderCount  int64
	WitnessCount int64
	StepCost     map[storelimit.Type]int64
}

StoreInfluence records influences that pending operators will make.

func (*StoreInfluence) AddStepCost

func (s *StoreInfluence) AddStepCost(limitType storelimit.Type, cost int64)

AddStepCost add cost to the influence.

func (*StoreInfluence) AdjustStepCost

func (s *StoreInfluence) AdjustStepCost(limitType storelimit.Type, regionSize int64)

AdjustStepCost adjusts the step cost of specific type store limit according to region size

func (*StoreInfluence) GetStepCost

func (s *StoreInfluence) GetStepCost(limitType storelimit.Type) int64

GetStepCost returns the specific type step cost

func (*StoreInfluence) ResourceProperty

func (s *StoreInfluence) ResourceProperty(kind constant.ScheduleKind) int64

ResourceProperty returns delta size of leader/region by influence.

type TransferLeader

type TransferLeader struct {
	// Compatible with old TiKV's TransferLeader.
	FromStore, ToStore uint64
	// Multi-target transfer leader.
	ToStores []uint64
}

TransferLeader is an OpStep that transfers a region's leader.

func (TransferLeader) CheckInProgress

func (tl TransferLeader) CheckInProgress(ci ClusterInformer, region *core.RegionInfo) error

CheckInProgress checks if the step is in the progress of advancing.

func (TransferLeader) ConfVerChanged

func (tl TransferLeader) ConfVerChanged(_ *core.RegionInfo) uint64

ConfVerChanged returns the delta value for version increased by this step.

func (TransferLeader) GetCmd

func (tl TransferLeader) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse

GetCmd returns the schedule command for heartbeat response.

func (TransferLeader) Influence

func (tl TransferLeader) Influence(opInfluence OpInfluence, region *core.RegionInfo)

Influence calculates the store difference that current step makes.

func (TransferLeader) IsFinish

func (tl TransferLeader) IsFinish(region *core.RegionInfo) bool

IsFinish checks if current step is finished.

func (TransferLeader) String

func (tl TransferLeader) String() string

func (TransferLeader) Timeout

func (tl TransferLeader) Timeout(regionSize int64) time.Duration

Timeout returns duration that current step may take.

Jump to

Keyboard shortcuts

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