Skip to content

Commit

Permalink
avoid redudant scheduler
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Jun 5, 2024
1 parent 301fabb commit a312a07
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 a312a07

Please sign in to comment.