@@ -828,11 +828,6 @@ func (c *RaftCluster) GetUnsafeRecoveryController() *unsaferecovery.Controller {
828828 return c .unsafeRecoveryController
829829}
830830
831- // IsUnsafeRecovering returns if the cluster is in unsafe recovering.
832- func (c * RaftCluster ) IsUnsafeRecovering () bool {
833- return c .unsafeRecoveryController .IsRunning ()
834- }
835-
836831// AddSuspectKeyRange adds the key range with the its ruleID as the key
837832// The instance of each keyRange is like following format:
838833// [2][]byte: start key/end key
@@ -2713,3 +2708,25 @@ func (c *RaftCluster) GetPausedSchedulerDelayAt(name string) (int64, error) {
27132708func (c * RaftCluster ) GetPausedSchedulerDelayUntil (name string ) (int64 , error ) {
27142709 return c .coordinator .GetPausedSchedulerDelayUntil (name )
27152710}
2711+
2712+ var (
2713+ onlineUnsafeRecoveryStatus = schedulingAllowanceStatusGauge .WithLabelValues ("online-unsafe-recovery" )
2714+ haltSchedulingStatus = schedulingAllowanceStatusGauge .WithLabelValues ("halt-scheduling" )
2715+ )
2716+
2717+ // CheckSchedulingAllowance checks if the cluster allows scheduling currently.
2718+ func (c * RaftCluster ) CheckSchedulingAllowance () (bool , error ) {
2719+ // If the cluster is in the process of online unsafe recovery, it should not allow scheduling.
2720+ if c .GetUnsafeRecoveryController ().IsRunning () {
2721+ onlineUnsafeRecoveryStatus .Set (1 )
2722+ return false , errs .ErrUnsafeRecoveryIsRunning .FastGenByArgs ()
2723+ }
2724+ onlineUnsafeRecoveryStatus .Set (0 )
2725+ // If the halt-scheduling is set, it should not allow scheduling.
2726+ if c .opt .IsSchedulingHalted () {
2727+ haltSchedulingStatus .Set (1 )
2728+ return false , errs .ErrSchedulingIsHalted .FastGenByArgs ()
2729+ }
2730+ haltSchedulingStatus .Set (0 )
2731+ return true , nil
2732+ }
0 commit comments