diff --git a/tools/pd-simulator/main.go b/tools/pd-simulator/main.go index e3dc43ca122..05763cc93b8 100644 --- a/tools/pd-simulator/main.go +++ b/tools/pd-simulator/main.go @@ -154,6 +154,8 @@ func simStart(pdAddr, statusAddress string, simCase string, simConfig *sc.SimCon tick := time.NewTicker(tickInterval) defer tick.Stop() sc := make(chan os.Signal, 1) + // halt scheduling + simulator.ChooseToHaltPDSchedule(true) signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, diff --git a/tools/pd-simulator/simulator/client.go b/tools/pd-simulator/simulator/client.go index 113eadab5e0..0bbbebe4602 100644 --- a/tools/pd-simulator/simulator/client.go +++ b/tools/pd-simulator/simulator/client.go @@ -16,6 +16,7 @@ package simulator import ( "context" + "strconv" "strings" "sync" "time" @@ -366,3 +367,9 @@ func (c *client) requestHeader() *pdpb.RequestHeader { ClusterId: c.clusterID, } } + +func ChooseToHaltPDSchedule(halt bool) { + PDHTTPClient.SetConfig(context.Background(), map[string]any{ + "schedule.halt-scheduling": strconv.FormatBool(halt), + }) +} diff --git a/tools/pd-simulator/simulator/node.go b/tools/pd-simulator/simulator/node.go index c51cdfd8a38..fe8dc74a944 100644 --- a/tools/pd-simulator/simulator/node.go +++ b/tools/pd-simulator/simulator/node.go @@ -172,6 +172,8 @@ func (n *Node) stepTask() { } } +var schedulerCheck sync.Once + func (n *Node) stepHeartBeat() { config := n.raftEngine.storeConfig @@ -182,6 +184,7 @@ func (n *Node) stepHeartBeat() { period = uint64(config.RaftStore.RegionHeartBeatInterval.Duration / config.SimTickInterval.Duration) if n.tick%period == 0 { n.regionHeartBeat() + schedulerCheck.Do(func() { ChooseToHaltPDSchedule(false) }) } }