func (p *PriorityInspector) GetPriorityRegions() (ids []uint64) {
	entries := p.queue.Elems()
	for _, e := range entries {
		re := e.Value.(*RegionPriorityEntry)
		if t := re.Last.Add(time.Duration(re.Attempt*10) * p.opts.GetPatrolRegionInterval()); t.Before(time.Now()) {
			ids = append(ids, re.regionID)
		}
	}
	return
}
GetPriorityRegions returns all regions in priority queue that needs rerun
package checker
import (
	"time"
	"github.com/tikv/pd/pkg/cache"
	"github.com/tikv/pd/server/config"
	"github.com/tikv/pd/server/core"
	"github.com/tikv/pd/server/schedule/opt"
	"github.com/tikv/pd/server/schedule/placement"
)
const defaultPriorityQueueSize = 1280
type PriorityInspector struct {
	cluster opt.Cluster
	opts    *config.PersistOptions
	queue   *cache.PriorityQueue
}
func NewPriorityInspector(cluster opt.Cluster) *PriorityInspector {
	return &PriorityInspector{
		cluster: cluster,
		opts:    cluster.GetOpts(),
		queue:   cache.NewPriorityQueue(defaultPriorityQueueSize),
	}
}
type RegionPriorityEntry struct {
	Attempt  int
	Last     time.Time
	regionID uint64
}
func (r RegionPriorityEntry) ID() uint64 {
	return r.regionID
}
func NewRegionEntry(regionID uint64) *RegionPriorityEntry {
	return &RegionPriorityEntry{regionID: regionID, Last: time.Now(), Attempt: 1}
}
func (p *PriorityInspector) Inspect(region *core.RegionInfo) (fit *placement.RegionFit) {
	var makeupCount int
	if p.opts.IsPlacementRulesEnabled() {
		makeupCount, fit = p.inspectRegionInPlacementRule(region)
	} else {
		makeupCount = p.inspectRegionInReplica(region)
	}
	priority := 0 - makeupCount
	p.addOrRemoveRegion(priority, region.GetID())
	return
}
func (p *PriorityInspector) inspectRegionInPlacementRule(region *core.RegionInfo) (makeupCount int, fit *placement.RegionFit) {
	fit = opt.FitRegion(p.cluster, region)
	if len(fit.RuleFits) == 0 {
		return
	}
	for _, rf := range fit.RuleFits {
		if rf.Rule.Role == placement.Learner {
			continue
		}
		makeupCount = makeupCount + rf.Rule.Count - len(rf.Peers)
	}
	return
}
func (p *PriorityInspector) inspectRegionInReplica(region *core.RegionInfo) (makeupCount int) {
	return p.opts.GetMaxReplicas() - len(region.GetPeers())
}
func (p *PriorityInspector) addOrRemoveRegion(priority int, regionID uint64) {
	if priority < 0 {
		if entry := p.queue.Get(regionID); entry != nil && entry.Priority == priority {
			e := entry.Value.(*RegionPriorityEntry)
			e.Attempt = e.Attempt + 1
			e.Last = time.Now()
		}
		entry := NewRegionEntry(regionID)
		p.queue.Put(priority, entry)
	} else {
		p.queue.Remove(regionID)
	}
}