From 494c0e956b622a9b3cec8b98180b942cbbe5a0f3 Mon Sep 17 00:00:00 2001 From: Hu# Date: Thu, 6 Jun 2024 10:41:55 +0800 Subject: [PATCH] tools/simulator: avoid redundant schedule (#8257) close tikv/pd#5290, ref tikv/pd#8135 Signed-off-by: husharp Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- tools/pd-simulator/main.go | 2 ++ tools/pd-simulator/simulator/client.go | 7 +++++++ tools/pd-simulator/simulator/node.go | 3 +++ 3 files changed, 12 insertions(+) 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) }) } }