Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[schedulers]: get stores only once #4003

Merged
merged 10 commits into from
Aug 19, 2021
5 changes: 4 additions & 1 deletion server/cluster/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"sync/atomic"
"time"

"github.com/tikv/pd/server/schedule/opt"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
Expand Down Expand Up @@ -821,8 +823,9 @@ func (s *scheduleController) Stop() {

func (s *scheduleController) Schedule() []*operator.Operator {
for i := 0; i < maxScheduleRetries; i++ {
cacheCluster := opt.NewCacheCluster(s.cluster)
// If we have schedule, reset interval to the minimal interval.
if op := s.Scheduler.Schedule(s.cluster); op != nil {
if op := s.Scheduler.Schedule(cacheCluster); op != nil {
s.nextInterval = s.Scheduler.GetMinInterval()
return op
}
Expand Down
19 changes: 19 additions & 0 deletions server/schedule/opt/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ type Cluster interface {
AddSuspectRegions(ids ...uint64)
}

// cacheCluster include cache info
type cacheCluster struct {
Cluster
stores []*core.StoreInfo
}

// GetStores returns store infos from cache
func (c *cacheCluster) GetStores() []*core.StoreInfo {
return c.stores
}

// NewCacheCluster constructor for cache
func NewCacheCluster(c Cluster) Cluster {
return &cacheCluster{
Cluster: c,
stores: c.GetStores(),
}
}

// HeartbeatStream is an interface.
type HeartbeatStream interface {
Send(*pdpb.RegionHeartbeatResponse) error
Expand Down