Documentation ¶
Index ¶
- Constants
- Variables
- func IsEndStatus(s OpStatus) bool
- func OpStatusToPDPB(s OpStatus) metapb.OperatorStatus
- func OpStatusToString(s OpStatus) string
- func SetOperatorStatusReachTime(op *Operator, st OpStatus, t time.Time)
- func SkipOriginJointStateCheck(b *Builder)
- type AddLearner
- func (al AddLearner) CheckSafety(res *core.CachedResource) error
- func (al AddLearner) ConfVerChanged(res *core.CachedResource) uint64
- func (al AddLearner) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (al AddLearner) IsFinish(res *core.CachedResource) bool
- func (al AddLearner) String() string
- type AddLightLearner
- func (al AddLightLearner) CheckSafety(res *core.CachedResource) error
- func (al AddLightLearner) ConfVerChanged(res *core.CachedResource) uint64
- func (al AddLightLearner) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (al AddLightLearner) IsFinish(res *core.CachedResource) bool
- func (al AddLightLearner) String() string
- type AddLightPeer
- func (ap AddLightPeer) CheckSafety(res *core.CachedResource) error
- func (ap AddLightPeer) ConfVerChanged(res *core.CachedResource) uint64
- func (ap AddLightPeer) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (ap AddLightPeer) IsFinish(res *core.CachedResource) bool
- func (ap AddLightPeer) String() string
- type AddPeer
- type Builder
- func (b *Builder) AddPeer(peer metapb.Replica) *Builder
- func (b *Builder) Build(kind OpKind) (*Operator, error)
- func (b *Builder) DemoteVoter(containerID uint64) *Builder
- func (b *Builder) EnableForceTargetLeader() *Builder
- func (b *Builder) EnableLightWeight() *Builder
- func (b *Builder) PromoteLearner(containerID uint64) *Builder
- func (b *Builder) RemovePeer(containerID uint64) *Builder
- func (b *Builder) SetExpectedRoles(roles map[uint64]placement.ReplicaRoleType) *Builder
- func (b *Builder) SetLeader(containerID uint64) *Builder
- func (b *Builder) SetPeers(peers map[uint64]metapb.Replica) *Builder
- type BuilderOption
- type ChangePeerV2Enter
- func (cpe ChangePeerV2Enter) CheckSafety(res *core.CachedResource) error
- func (cpe ChangePeerV2Enter) ConfVerChanged(res *core.CachedResource) uint64
- func (cpe ChangePeerV2Enter) GetRequest() *rpcpb.ConfigChangeV2
- func (cpe ChangePeerV2Enter) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (cpe ChangePeerV2Enter) IsFinish(res *core.CachedResource) bool
- func (cpe ChangePeerV2Enter) String() string
- type ChangePeerV2Leave
- func (cpl ChangePeerV2Leave) CheckSafety(res *core.CachedResource) error
- func (cpl ChangePeerV2Leave) ConfVerChanged(res *core.CachedResource) uint64
- func (cpl ChangePeerV2Leave) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (cpl ChangePeerV2Leave) IsFinish(res *core.CachedResource) bool
- func (cpl ChangePeerV2Leave) String() string
- type ContainerInfluence
- type DemoteFollower
- func (df DemoteFollower) CheckSafety(res *core.CachedResource) error
- func (df DemoteFollower) ConfVerChanged(res *core.CachedResource) uint64
- func (df DemoteFollower) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (df DemoteFollower) IsFinish(res *core.CachedResource) bool
- func (df DemoteFollower) String() string
- type DemoteVoter
- type DestroyDirectly
- func (tl DestroyDirectly) CheckSafety(res *core.CachedResource) error
- func (tl DestroyDirectly) ConfVerChanged(res *core.CachedResource) uint64
- func (tl DestroyDirectly) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (tl DestroyDirectly) IsFinish(res *core.CachedResource) bool
- func (tl DestroyDirectly) String() string
- type InfluenceStats
- type MergeResource
- func (mr MergeResource) CheckSafety(res *core.CachedResource) error
- func (mr MergeResource) ConfVerChanged(res *core.CachedResource) uint64
- func (mr MergeResource) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (mr MergeResource) IsFinish(res *core.CachedResource) bool
- func (mr MergeResource) String() string
- type OpHistory
- type OpInfluence
- type OpKind
- type OpStatus
- type OpStatusTracker
- func (trk *OpStatusTracker) CheckExpired(exp time.Duration) bool
- func (trk *OpStatusTracker) CheckTimeout(wait time.Duration) bool
- func (trk *OpStatusTracker) IsEnd() bool
- func (trk *OpStatusTracker) ReachTime() time.Time
- func (trk *OpStatusTracker) ReachTimeOf(s OpStatus) time.Time
- func (trk *OpStatusTracker) Status() OpStatus
- func (trk *OpStatusTracker) String() string
- func (trk *OpStatusTracker) To(dst OpStatus) bool
- type OpStep
- type Operator
- func CreateAddPeerOperator(desc string, cluster opt.Cluster, res *core.CachedResource, ...) (*Operator, error)
- func CreateForceTransferLeaderOperator(desc string, cluster opt.Cluster, res *core.CachedResource, ...) (*Operator, error)
- func CreateLeaveJointStateOperator(desc string, cluster opt.Cluster, origin *core.CachedResource) (*Operator, error)
- func CreateMergeResourceOperator(desc string, cluster opt.Cluster, source *core.CachedResource, ...) ([]*Operator, error)
- func CreateMoveLeaderOperator(desc string, cluster opt.Cluster, res *core.CachedResource, kind OpKind, ...) (*Operator, error)
- func CreateMovePeerOperator(desc string, cluster opt.Cluster, res *core.CachedResource, kind OpKind, ...) (*Operator, error)
- func CreateMoveResourceOperator(desc string, cluster opt.Cluster, res *core.CachedResource, kind OpKind, ...) (*Operator, error)
- func CreatePromoteLearnerOperator(desc string, cluster opt.Cluster, res *core.CachedResource, ...) (*Operator, error)
- func CreateRemovePeerOperator(desc string, cluster opt.Cluster, kind OpKind, res *core.CachedResource, ...) (*Operator, error)
- func CreateScatterResourceOperator(desc string, cluster opt.Cluster, origin *core.CachedResource, ...) (*Operator, error)
- func CreateSplitResourceOperator(desc string, res *core.CachedResource, kind OpKind, policy metapb.CheckPolicy, ...) (*Operator, error)
- func CreateTransferLeaderOperator(desc string, cluster opt.Cluster, res *core.CachedResource, ...) (*Operator, error)
- func NewOperator(desc, brief string, resID uint64, resEpoch metapb.ResourceEpoch, kind OpKind, ...) *Operator
- func (o *Operator) AttachKind(kind OpKind)
- func (o *Operator) Cancel() bool
- func (o *Operator) Check(res *core.CachedResource) OpStep
- func (o *Operator) CheckExpired() bool
- func (o *Operator) CheckSuccess() bool
- func (o *Operator) CheckTimeout() bool
- func (o *Operator) ConfVerChanged(res *core.CachedResource) (total uint64)
- func (o *Operator) Desc() string
- func (o *Operator) ElapsedTime() time.Duration
- func (o *Operator) GetAdditionalInfo() string
- func (o *Operator) GetCreateTime() time.Time
- func (o *Operator) GetPriorityLevel() core.PriorityLevel
- func (o *Operator) GetReachTimeOf(st OpStatus) time.Time
- func (o *Operator) GetStartTime() time.Time
- func (o *Operator) HasStarted() bool
- func (o *Operator) History() []OpHistory
- func (o *Operator) IsEnd() bool
- func (o *Operator) Kind() OpKind
- func (o *Operator) Len() int
- func (o *Operator) MarshalJSON() ([]byte, error)
- func (o *Operator) Replace() bool
- func (o *Operator) ResourceEpoch() metapb.ResourceEpoch
- func (o *Operator) ResourceID() uint64
- func (o *Operator) RunningTime() time.Duration
- func (o *Operator) SetDesc(desc string)
- func (o *Operator) SetPriorityLevel(level core.PriorityLevel)
- func (o *Operator) Start() bool
- func (o *Operator) Status() OpStatus
- func (o *Operator) Step(i int) OpStep
- func (o *Operator) String() string
- func (o *Operator) TotalInfluence(opInfluence OpInfluence, res *core.CachedResource)
- func (o *Operator) UnfinishedInfluence(opInfluence OpInfluence, res *core.CachedResource)
- type PromoteLearner
- func (pl PromoteLearner) CheckSafety(res *core.CachedResource) error
- func (pl PromoteLearner) ConfVerChanged(res *core.CachedResource) uint64
- func (pl PromoteLearner) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (pl PromoteLearner) IsFinish(res *core.CachedResource) bool
- func (pl PromoteLearner) String() string
- type RemovePeer
- func (rp RemovePeer) CheckSafety(res *core.CachedResource) error
- func (rp RemovePeer) ConfVerChanged(res *core.CachedResource) uint64
- func (rp RemovePeer) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (rp RemovePeer) IsFinish(res *core.CachedResource) bool
- func (rp RemovePeer) String() string
- type SplitResource
- func (sr SplitResource) CheckSafety(res *core.CachedResource) error
- func (sr SplitResource) ConfVerChanged(res *core.CachedResource) uint64
- func (sr SplitResource) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (sr SplitResource) IsFinish(res *core.CachedResource) bool
- func (sr SplitResource) String() string
- type TransferLeader
- func (tl TransferLeader) CheckSafety(res *core.CachedResource) error
- func (tl TransferLeader) ConfVerChanged(res *core.CachedResource) uint64
- func (tl TransferLeader) Influence(opInfluence OpInfluence, res *core.CachedResource)
- func (tl TransferLeader) IsFinish(res *core.CachedResource) bool
- func (tl TransferLeader) String() string
Constants ¶
const ( // OperatorExpireTime is the duration that when an operator is not started // after it, the operator will be considered expired. OperatorExpireTime = 3 * time.Second // FastOperatorWaitTime is the duration that when an operator that is not marked // `OpResource` runs longer than it, the operator will be considered timeout. FastOperatorWaitTime = 10 * time.Second // SlowOperatorWaitTime is the duration that when an operator marked `OpResource` // runs longer than it, the operator will be considered timeout. SlowOperatorWaitTime = 10 * time.Minute )
Variables ¶
var ( // OperatorLimitCounter exposes the counter when meeting limit. OperatorLimitCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "prophet", Subsystem: "schedule", Name: "operator_limit", Help: "Counter of operator meeting limit", }, []string{"type", "name"}) )
Functions ¶
func OpStatusToPDPB ¶
func OpStatusToPDPB(s OpStatus) metapb.OperatorStatus
OpStatusToPDPB converts OpStatus to metapb.OperatorStatus.
func OpStatusToString ¶
OpStatusToString converts Status to string.
func SetOperatorStatusReachTime ¶
SetOperatorStatusReachTime sets the reach time of the operator. NOTE: Should only use in test.
func SkipOriginJointStateCheck ¶
func SkipOriginJointStateCheck(b *Builder)
SkipOriginJointStateCheck lets the builder skip the joint state check for origin peers.
Types ¶
type AddLearner ¶
type AddLearner struct {
ToContainer, PeerID uint64
}
AddLearner is an OpStep that adds a resource learner peer.
func (AddLearner) CheckSafety ¶
func (al AddLearner) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (AddLearner) ConfVerChanged ¶
func (al AddLearner) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (AddLearner) Influence ¶
func (al AddLearner) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (AddLearner) IsFinish ¶
func (al AddLearner) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (AddLearner) String ¶
func (al AddLearner) String() string
type AddLightLearner ¶
type AddLightLearner struct {
ToContainer, PeerID uint64
}
AddLightLearner is an OpStep that adds a resource learner peer without considering the influence.
func (AddLightLearner) CheckSafety ¶
func (al AddLightLearner) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (AddLightLearner) ConfVerChanged ¶
func (al AddLightLearner) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (AddLightLearner) Influence ¶
func (al AddLightLearner) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (AddLightLearner) IsFinish ¶
func (al AddLightLearner) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (AddLightLearner) String ¶
func (al AddLightLearner) String() string
type AddLightPeer ¶
type AddLightPeer struct {
ToContainer, PeerID uint64
}
AddLightPeer is an OpStep that adds a resource peer without considering the influence.
func (AddLightPeer) CheckSafety ¶
func (ap AddLightPeer) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (AddLightPeer) ConfVerChanged ¶
func (ap AddLightPeer) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (AddLightPeer) Influence ¶
func (ap AddLightPeer) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (AddLightPeer) IsFinish ¶
func (ap AddLightPeer) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (AddLightPeer) String ¶
func (ap AddLightPeer) String() string
type AddPeer ¶
type AddPeer struct {
ToContainer, PeerID uint64
}
AddPeer is an OpStep that adds a resource peer.
func (AddPeer) CheckSafety ¶
func (ap AddPeer) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (AddPeer) ConfVerChanged ¶
func (ap AddPeer) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (AddPeer) Influence ¶
func (ap AddPeer) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is used to create operators. Usage:
op, err := NewBuilder(desc, cluster, resource). RemovePeer(container1). AddPeer(peer1). SetLeader(container2). Build(kind)
The generated Operator will choose the most appropriate execution order according to various constraints.
func NewBuilder ¶
func NewBuilder(desc string, cluster opt.Cluster, res *core.CachedResource, opts ...BuilderOption) *Builder
NewBuilder creates a Builder.
func (*Builder) AddPeer ¶
AddPeer records an add Peer operation in Builder. If peer.Id is 0, the builder will allocate a new peer ID later.
func (*Builder) DemoteVoter ¶
DemoteVoter records a demote voter operation in Builder.
func (*Builder) EnableForceTargetLeader ¶
EnableForceTargetLeader marks the step of transferring leader to target is forcible. It is used for grant leader.
func (*Builder) EnableLightWeight ¶
EnableLightWeight marks the resource as light weight. It is used for scatter resources.
func (*Builder) PromoteLearner ¶
PromoteLearner records a promote learner operation in Builder.
func (*Builder) RemovePeer ¶
RemovePeer records a remove peer operation in Builder.
func (*Builder) SetExpectedRoles ¶
func (b *Builder) SetExpectedRoles(roles map[uint64]placement.ReplicaRoleType) *Builder
SetExpectedRoles records expected roles of target peers. It may update `targetLeaderContainerID` if there is a peer has role `leader` or `follower`.
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) CheckSafety ¶
func (cpe ChangePeerV2Enter) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (ChangePeerV2Enter) ConfVerChanged ¶
func (cpe ChangePeerV2Enter) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (ChangePeerV2Enter) GetRequest ¶
func (cpe ChangePeerV2Enter) GetRequest() *rpcpb.ConfigChangeV2
GetRequest get the ChangePeerV2 request
func (ChangePeerV2Enter) Influence ¶
func (cpe ChangePeerV2Enter) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (ChangePeerV2Enter) IsFinish ¶
func (cpe ChangePeerV2Enter) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (ChangePeerV2Enter) String ¶
func (cpe ChangePeerV2Enter) String() string
type ChangePeerV2Leave ¶
type ChangePeerV2Leave struct { PromoteLearners []PromoteLearner DemoteVoters []DemoteVoter }
ChangePeerV2Leave is an OpStep that leaves the joint state.
func (ChangePeerV2Leave) CheckSafety ¶
func (cpl ChangePeerV2Leave) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (ChangePeerV2Leave) ConfVerChanged ¶
func (cpl ChangePeerV2Leave) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (ChangePeerV2Leave) Influence ¶
func (cpl ChangePeerV2Leave) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (ChangePeerV2Leave) IsFinish ¶
func (cpl ChangePeerV2Leave) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (ChangePeerV2Leave) String ¶
func (cpl ChangePeerV2Leave) String() string
type ContainerInfluence ¶
type ContainerInfluence struct { InfluenceStats map[string]InfluenceStats StepCost map[limit.Type]int64 }
ContainerInfluence records influences that pending operators will make.
func (*ContainerInfluence) AdjustStepCost ¶
func (s *ContainerInfluence) AdjustStepCost(limitType limit.Type, resourceSize int64)
AdjustStepCost adjusts the step cost of specific type container limit according to resource size
func (ContainerInfluence) GetStepCost ¶
func (s ContainerInfluence) GetStepCost(limitType limit.Type) int64
GetStepCost returns the specific type step cost
func (ContainerInfluence) ResourceProperty ¶
func (s ContainerInfluence) ResourceProperty(kind core.ScheduleKind, groupKey string) int64
ResourceProperty returns delta size of leader/resource by influence.
type DemoteFollower ¶
type DemoteFollower struct {
ToContainer, PeerID uint64
}
DemoteFollower is an OpStep that demotes a resource follower peer to learner.
func (DemoteFollower) CheckSafety ¶
func (df DemoteFollower) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (DemoteFollower) ConfVerChanged ¶
func (df DemoteFollower) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (DemoteFollower) Influence ¶
func (df DemoteFollower) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (DemoteFollower) IsFinish ¶
func (df DemoteFollower) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (DemoteFollower) String ¶
func (df DemoteFollower) String() string
type DemoteVoter ¶
type DemoteVoter struct {
ToContainer, PeerID uint64
}
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(res *core.CachedResource) bool
ConfVerChanged returns the delta value for version increased by this step.
func (DemoteVoter) IsFinish ¶
func (dv DemoteVoter) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (DemoteVoter) String ¶
func (dv DemoteVoter) String() string
type DestroyDirectly ¶ added in v0.2.0
type DestroyDirectly struct { }
DestroyDirectly is an OpStep that destroy current peer directly without raft.
func (DestroyDirectly) CheckSafety ¶ added in v0.2.0
func (tl DestroyDirectly) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (DestroyDirectly) ConfVerChanged ¶ added in v0.2.0
func (tl DestroyDirectly) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (DestroyDirectly) Influence ¶ added in v0.2.0
func (tl DestroyDirectly) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (DestroyDirectly) IsFinish ¶ added in v0.2.0
func (tl DestroyDirectly) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (DestroyDirectly) String ¶ added in v0.2.0
func (tl DestroyDirectly) String() string
type InfluenceStats ¶ added in v0.2.0
type MergeResource ¶
type MergeResource struct { FromResource metadata.Resource ToResource metadata.Resource // there are two resources involved in merge process, // so to keep them from other scheduler, // both of them should add Merresource operatorStep. // But actually, your storage application just needs the resource want to be merged to get the merge request, // thus use a IsPassive mark to indicate that // this resource doesn't need to send merge request to your storage application. IsPassive bool }
MergeResource is an OpStep that merge two resources.
func (MergeResource) CheckSafety ¶
func (mr MergeResource) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (MergeResource) ConfVerChanged ¶
func (mr MergeResource) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (MergeResource) Influence ¶
func (mr MergeResource) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (MergeResource) IsFinish ¶
func (mr MergeResource) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (MergeResource) String ¶
func (mr MergeResource) String() string
type OpHistory ¶
type OpHistory struct { FinishTime time.Time From, To uint64 Kind metapb.ResourceKind }
OpHistory is used to log and visualize completed operators.
type OpInfluence ¶
type OpInfluence struct {
ContainersInfluence map[uint64]*ContainerInfluence
}
OpInfluence records the influence of the cluster.
func (OpInfluence) GetContainerInfluence ¶
func (m OpInfluence) GetContainerInfluence(id uint64) *ContainerInfluence
GetContainerInfluence get containerInfluence of specific container.
type OpKind ¶
type OpKind uint32
OpKind is a bit field to identify operator types.
const ( // Include leader transfer. OpLeader OpKind = 1 << iota // Include peer addition or removal. This means that this operator may take a long time. OpResource // Include resource split. Initiated by rule checker if `kind & OpAdmin == 0`. OpSplit // Initiated by admin. OpAdmin // Initiated by hot resource scheduler. OpHotResource // Initiated by replica checker. OpReplica // Initiated by merge checker or merge scheduler. Note that it may not include resource merge. OpMerge // Initiated by range scheduler. OpRange )
Flags for operators.
func ParseOperatorKind ¶
ParseOperatorKind converts string (flag name list concat by ',') to OpKind.
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(wait time.Duration) bool
CheckTimeout checks 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(res *core.CachedResource) uint64 IsFinish(res *core.CachedResource) bool CheckSafety(res *core.CachedResource) error Influence(opInfluence OpInfluence, res *core.CachedResource) }
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 // contains filtered or unexported fields }
Operator contains execution steps generated by scheduler.
func CreateAddPeerOperator ¶
func CreateAddPeerOperator(desc string, cluster opt.Cluster, res *core.CachedResource, peer metapb.Replica, kind OpKind) (*Operator, error)
CreateAddPeerOperator creates an operator that adds a new peer.
func CreateForceTransferLeaderOperator ¶
func CreateForceTransferLeaderOperator(desc string, cluster opt.Cluster, res *core.CachedResource, sourceContainerID uint64, targetContainerID uint64, kind OpKind) (*Operator, error)
CreateForceTransferLeaderOperator creates an operator that transfers the leader from a source container to a target container forcible.
func CreateLeaveJointStateOperator ¶
func CreateLeaveJointStateOperator(desc string, cluster opt.Cluster, origin *core.CachedResource) (*Operator, error)
CreateLeaveJointStateOperator creates an operator that let resource leave joint state.
func CreateMergeResourceOperator ¶
func CreateMergeResourceOperator(desc string, cluster opt.Cluster, source *core.CachedResource, target *core.CachedResource, kind OpKind) ([]*Operator, error)
CreateMergeResourceOperator creates an operator that merge two resource into one.
func CreateMoveLeaderOperator ¶
func CreateMoveLeaderOperator(desc string, cluster opt.Cluster, res *core.CachedResource, kind OpKind, oldContainer uint64, peer metapb.Replica) (*Operator, error)
CreateMoveLeaderOperator creates an operator that replaces an old leader with a new leader.
func CreateMovePeerOperator ¶
func CreateMovePeerOperator(desc string, cluster opt.Cluster, res *core.CachedResource, kind OpKind, oldContainer uint64, peer metapb.Replica) (*Operator, error)
CreateMovePeerOperator creates an operator that replaces an old peer with a new peer.
func CreateMoveResourceOperator ¶
func CreateMoveResourceOperator(desc string, cluster opt.Cluster, res *core.CachedResource, kind OpKind, roles map[uint64]placement.ReplicaRoleType) (*Operator, error)
CreateMoveResourceOperator creates an operator that moves a resource to specified containers.
func CreatePromoteLearnerOperator ¶
func CreatePromoteLearnerOperator(desc string, cluster opt.Cluster, res *core.CachedResource, peer metapb.Replica) (*Operator, error)
CreatePromoteLearnerOperator creates an operator that promotes a learner.
func CreateRemovePeerOperator ¶
func CreateRemovePeerOperator(desc string, cluster opt.Cluster, kind OpKind, res *core.CachedResource, containerID uint64) (*Operator, error)
CreateRemovePeerOperator creates an operator that removes a peer from resource.
func CreateScatterResourceOperator ¶
func CreateScatterResourceOperator(desc string, cluster opt.Cluster, origin *core.CachedResource, targetPeers map[uint64]metapb.Replica, targetLeader uint64) (*Operator, error)
CreateScatterResourceOperator creates an operator that scatters the specified resource.
func CreateSplitResourceOperator ¶
func CreateSplitResourceOperator(desc string, res *core.CachedResource, kind OpKind, policy metapb.CheckPolicy, keys [][]byte) (*Operator, error)
CreateSplitResourceOperator creates an operator that splits a resource.
func CreateTransferLeaderOperator ¶
func CreateTransferLeaderOperator(desc string, cluster opt.Cluster, res *core.CachedResource, sourceContainerID uint64, targetContainerID uint64, kind OpKind) (*Operator, error)
CreateTransferLeaderOperator creates an operator that transfers the leader from a source container to a target container.
func NewOperator ¶
func NewOperator(desc, brief string, resID uint64, resEpoch metapb.ResourceEpoch, kind OpKind, steps ...OpStep) *Operator
NewOperator creates a new operator.
func (*Operator) AttachKind ¶
AttachKind attaches an operator kind for the operator.
func (*Operator) Check ¶
func (o *Operator) Check(res *core.CachedResource) 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) CheckExpired ¶
CheckExpired checks if the operator is expired, and update the status.
func (*Operator) CheckSuccess ¶
CheckSuccess checks if all steps are finished, and update the status.
func (*Operator) CheckTimeout ¶
CheckTimeout checks if the operator is timeout, and update the status.
func (*Operator) ConfVerChanged ¶
func (o *Operator) ConfVerChanged(res *core.CachedResource) (total uint64)
ConfVerChanged returns the number of confver has consumed by steps
func (*Operator) ElapsedTime ¶
ElapsedTime returns duration since it was created.
func (*Operator) GetAdditionalInfo ¶
GetAdditionalInfo returns additional info with string
func (*Operator) GetCreateTime ¶
GetCreateTime gets the create time of operator.
func (*Operator) GetPriorityLevel ¶
func (o *Operator) GetPriorityLevel() core.PriorityLevel
GetPriorityLevel gets the priority level.
func (*Operator) GetReachTimeOf ¶
GetReachTimeOf returns the time when operator reaches the given status.
func (*Operator) GetStartTime ¶
GetStartTime gets the start time of operator.
func (*Operator) HasStarted ¶
HasStarted returns whether operator has started.
func (*Operator) MarshalJSON ¶
MarshalJSON serializes custom types to JSON.
func (*Operator) ResourceEpoch ¶
func (o *Operator) ResourceEpoch() metapb.ResourceEpoch
ResourceEpoch returns the resource's epoch that is attached to the operator.
func (*Operator) ResourceID ¶
ResourceID returns the resource that operator is targeted.
func (*Operator) RunningTime ¶
RunningTime returns duration since it started.
func (*Operator) SetPriorityLevel ¶
func (o *Operator) SetPriorityLevel(level core.PriorityLevel)
SetPriorityLevel sets the priority level for operator.
func (*Operator) TotalInfluence ¶
func (o *Operator) TotalInfluence(opInfluence OpInfluence, res *core.CachedResource)
TotalInfluence calculates the container difference which whole operator steps make.
func (*Operator) UnfinishedInfluence ¶
func (o *Operator) UnfinishedInfluence(opInfluence OpInfluence, res *core.CachedResource)
UnfinishedInfluence calculates the container difference which unfinished operator steps make.
type PromoteLearner ¶
type PromoteLearner struct {
ToContainer, PeerID uint64
}
PromoteLearner is an OpStep that promotes a resource learner peer to normal voter.
func (PromoteLearner) CheckSafety ¶
func (pl PromoteLearner) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (PromoteLearner) ConfVerChanged ¶
func (pl PromoteLearner) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (PromoteLearner) Influence ¶
func (pl PromoteLearner) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (PromoteLearner) IsFinish ¶
func (pl PromoteLearner) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (PromoteLearner) String ¶
func (pl PromoteLearner) String() string
type RemovePeer ¶
type RemovePeer struct {
FromContainer, PeerID uint64
}
RemovePeer is an OpStep that removes a resource peer.
func (RemovePeer) CheckSafety ¶
func (rp RemovePeer) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (RemovePeer) ConfVerChanged ¶
func (rp RemovePeer) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (RemovePeer) Influence ¶
func (rp RemovePeer) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (RemovePeer) IsFinish ¶
func (rp RemovePeer) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (RemovePeer) String ¶
func (rp RemovePeer) String() string
type SplitResource ¶
type SplitResource struct {
StartKey, EndKey []byte
Policy metapb.CheckPolicy
SplitKeys [][]byte
}
SplitResource is an OpStep that splits a resource.
func (SplitResource) CheckSafety ¶
func (sr SplitResource) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (SplitResource) ConfVerChanged ¶
func (sr SplitResource) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (SplitResource) Influence ¶
func (sr SplitResource) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (SplitResource) IsFinish ¶
func (sr SplitResource) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (SplitResource) String ¶
func (sr SplitResource) String() string
type TransferLeader ¶
type TransferLeader struct {
FromContainer, ToContainer uint64
}
TransferLeader is an OpStep that transfers a resource's leader.
func (TransferLeader) CheckSafety ¶
func (tl TransferLeader) CheckSafety(res *core.CachedResource) error
CheckSafety checks if the step meets the safety properties.
func (TransferLeader) ConfVerChanged ¶
func (tl TransferLeader) ConfVerChanged(res *core.CachedResource) uint64
ConfVerChanged returns the delta value for version increased by this step.
func (TransferLeader) Influence ¶
func (tl TransferLeader) Influence(opInfluence OpInfluence, res *core.CachedResource)
Influence calculates the container difference that current step makes.
func (TransferLeader) IsFinish ¶
func (tl TransferLeader) IsFinish(res *core.CachedResource) bool
IsFinish checks if current step is finished.
func (TransferLeader) String ¶
func (tl TransferLeader) String() string