Skip to content

Commit

Permalink
tools/simulator: avoid redundant schedule (#8257)
Browse files Browse the repository at this point in the history
close #5290, ref #8135

Signed-off-by: husharp <jinhao.hu@pingcap.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
HuSharp and ti-chi-bot[bot] committed Jun 6, 2024
1 parent 0bf9e90 commit 494c0e9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/pd-simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions tools/pd-simulator/simulator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package simulator

import (
"context"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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),
})
}
3 changes: 3 additions & 0 deletions tools/pd-simulator/simulator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func (n *Node) stepTask() {
}
}

var schedulerCheck sync.Once

func (n *Node) stepHeartBeat() {
config := n.raftEngine.storeConfig

Expand All @@ -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) })
}
}

Expand Down

0 comments on commit 494c0e9

Please sign in to comment.