Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schedulers: split transfer-witness-leader's limit from balance-leader #5873

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions server/schedule/operator/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,36 @@ const (
OpRegion
// Include leader transfer.
OpLeader
// Include witness leader transfer.
OpWitnessLeader
bufferflies marked this conversation as resolved.
Show resolved Hide resolved
bufferflies marked this conversation as resolved.
Show resolved Hide resolved
// Include witness transfer.
OpWitness
opMax
)

var flagToName = map[OpKind]string{
OpLeader: "leader",
OpRegion: "region",
OpSplit: "split",
OpAdmin: "admin",
OpHotRegion: "hot-region",
OpReplica: "replica",
OpMerge: "merge",
OpRange: "range",
OpWitness: "witness",
OpLeader: "leader",
OpRegion: "region",
OpSplit: "split",
OpAdmin: "admin",
OpHotRegion: "hot-region",
OpReplica: "replica",
OpMerge: "merge",
OpRange: "range",
OpWitness: "witness",
OpWitnessLeader: "witness-leader",
}

var nameToFlag = map[string]OpKind{
"leader": OpLeader,
"region": OpRegion,
"split": OpSplit,
"admin": OpAdmin,
"hot-region": OpHotRegion,
"replica": OpReplica,
"merge": OpMerge,
"range": OpRange,
"leader": OpLeader,
"region": OpRegion,
"split": OpSplit,
"admin": OpAdmin,
"hot-region": OpHotRegion,
"replica": OpReplica,
"merge": OpMerge,
"range": OpRange,
"witness-leader": OpWitnessLeader,
}

func (k OpKind) String() string {
Expand Down
11 changes: 3 additions & 8 deletions server/schedulers/transfer_witness_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
TransferWitnessLeaderType = "transfer-witness-leader"
// TransferWitnessLeaderBatchSize is the number of operators to to transfer
// leaders by one scheduling
transferWitnessLeaderBatchSize = 3
transferWitnessLeaderBatchSize = 10
// TransferWitnessLeaderRecvMaxRegionSize is the max number of region can receive
// TODO: make it a reasonable value
transferWitnessLeaderRecvMaxRegionSize = 1000
Expand Down Expand Up @@ -80,12 +80,7 @@ func (s *trasferWitnessLeaderScheduler) GetType() string {
}

func (s *trasferWitnessLeaderScheduler) IsScheduleAllowed(cluster schedule.Cluster) bool {
// TODO: make sure the restriction is reasonable
allowed := s.OpController.OperatorCount(operator.OpLeader) < cluster.GetOpts().GetLeaderScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(s.GetType(), operator.OpLeader.String()).Inc()
}
return allowed
return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no any limit?

Copy link
Member Author

@ethercflow ethercflow Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because when the witness becomes the leader, it cannot provide read and write requests, which will trigger the client to enter backoff to retry. If the transfer cannot be made in time, the client will time out. In addition, the strategy of witness raft log gc has been changed to ensure that there are enough logs, so no snapshots need (and can't) to be generated during the transfer leader process.

}

func (s *trasferWitnessLeaderScheduler) Schedule(cluster schedule.Cluster, dryRun bool) ([]*operator.Operator, []plan.Plan) {
Expand Down Expand Up @@ -138,7 +133,7 @@ func (s *trasferWitnessLeaderScheduler) scheduleTransferWitnessLeader(name, typ
for _, t := range targets {
targetIDs = append(targetIDs, t.GetID())
}
return operator.CreateTransferLeaderOperator(typ, cluster, region, region.GetLeader().GetStoreId(), target.GetID(), targetIDs, operator.OpLeader)
return operator.CreateTransferLeaderOperator(typ, cluster, region, region.GetLeader().GetStoreId(), target.GetID(), targetIDs, operator.OpWitnessLeader)
}

// RecvRegionInfo receives a checked region from coordinator
Expand Down