@@ -35,7 +35,6 @@ import (
35
35
"github.com/tikv/pd/server/schedule/checker"
36
36
"github.com/tikv/pd/server/schedule/hbstream"
37
37
"github.com/tikv/pd/server/schedule/operator"
38
- "github.com/tikv/pd/server/schedulers"
39
38
"github.com/tikv/pd/server/statistics"
40
39
"github.com/tikv/pd/server/storage"
41
40
"go.uber.org/zap"
@@ -470,35 +469,18 @@ func (c *coordinator) stop() {
470
469
c .cancel ()
471
470
}
472
471
473
- // Hack to retrieve info from scheduler.
474
- // TODO: remove it.
475
- type hasHotStatus interface {
476
- GetHotStatus (statistics.RWType ) * statistics.StoreHotPeersInfos
477
- GetPendingInfluence () map [uint64 ]* statistics.Influence
478
- }
479
-
480
- func (c * coordinator ) getHotWriteRegions () * statistics.StoreHotPeersInfos {
481
- c .RLock ()
482
- defer c .RUnlock ()
483
- s , ok := c .schedulers [schedulers .HotRegionName ]
484
- if ! ok {
485
- return nil
486
- }
487
- if h , ok := s .Scheduler .(hasHotStatus ); ok {
488
- return h .GetHotStatus (statistics .Write )
489
- }
490
- return nil
491
- }
492
-
493
- func (c * coordinator ) getHotReadRegions () * statistics.StoreHotPeersInfos {
494
- c .RLock ()
495
- defer c .RUnlock ()
496
- s , ok := c .schedulers [schedulers .HotRegionName ]
497
- if ! ok {
498
- return nil
499
- }
500
- if h , ok := s .Scheduler .(hasHotStatus ); ok {
501
- return h .GetHotStatus (statistics .Read )
472
+ func (c * coordinator ) getHotRegionsByType (typ statistics.RWType ) * statistics.StoreHotPeersInfos {
473
+ isTraceFlow := c .cluster .GetOpts ().IsTraceRegionFlow ()
474
+ storeLoads := c .cluster .GetStoresLoads ()
475
+ stores := c .cluster .GetStores ()
476
+ switch typ {
477
+ case statistics .Write :
478
+ regionStats := c .cluster .RegionWriteStats ()
479
+ return statistics .GetHotStatus (stores , storeLoads , regionStats , statistics .Write , isTraceFlow )
480
+ case statistics .Read :
481
+ regionStats := c .cluster .RegionReadStats ()
482
+ return statistics .GetHotStatus (stores , storeLoads , regionStats , statistics .Read , isTraceFlow )
483
+ default :
502
484
}
503
485
return nil
504
486
}
@@ -542,36 +524,32 @@ func (c *coordinator) resetSchedulerMetrics() {
542
524
}
543
525
544
526
func (c * coordinator ) collectHotSpotMetrics () {
545
- c .RLock ()
546
- // Collects hot write region metrics.
547
- s , ok := c .schedulers [schedulers .HotRegionName ]
548
- if ! ok {
549
- c .RUnlock ()
550
- return
551
- }
552
- c .RUnlock ()
553
527
stores := c .cluster .GetStores ()
554
528
// Collects hot write region metrics.
555
- collectHotMetrics (s , stores , statistics .Write )
529
+ collectHotMetrics (c . cluster , stores , statistics .Write )
556
530
// Collects hot read region metrics.
557
- collectHotMetrics (s , stores , statistics .Read )
531
+ collectHotMetrics (c . cluster , stores , statistics .Read )
558
532
// Collects pending influence.
559
- collectPendingInfluence (s , stores )
533
+ collectPendingInfluence (stores )
560
534
}
561
535
562
- func collectHotMetrics (s * scheduleController , stores []* core.StoreInfo , typ statistics.RWType ) {
563
- status := s .Scheduler .(hasHotStatus ).GetHotStatus (typ )
536
+ func collectHotMetrics (cluster * RaftCluster , stores []* core.StoreInfo , typ statistics.RWType ) {
564
537
var (
565
538
kind string
566
539
byteTyp , keyTyp , queryTyp statistics.RegionStatKind
540
+ regionStats map [uint64 ][]* statistics.HotPeerStat
567
541
)
568
542
569
543
switch typ {
570
544
case statistics .Read :
545
+ regionStats = cluster .RegionReadStats ()
571
546
kind , byteTyp , keyTyp , queryTyp = statistics .Read .String (), statistics .RegionReadBytes , statistics .RegionReadKeys , statistics .RegionReadQuery
572
547
case statistics .Write :
548
+ regionStats = cluster .RegionWriteStats ()
573
549
kind , byteTyp , keyTyp , queryTyp = statistics .Write .String (), statistics .RegionWriteBytes , statistics .RegionWriteKeys , statistics .RegionWriteQuery
574
550
}
551
+ status := statistics .GetHotStatus (stores , cluster .GetStoresLoads (), regionStats , typ , cluster .GetOpts ().IsTraceRegionFlow ())
552
+
575
553
for _ , s := range stores {
576
554
storeAddress := s .GetAddress ()
577
555
storeID := s .GetID ()
@@ -604,8 +582,8 @@ func collectHotMetrics(s *scheduleController, stores []*core.StoreInfo, typ stat
604
582
}
605
583
}
606
584
607
- func collectPendingInfluence (s * scheduleController , stores []* core.StoreInfo ) {
608
- pendings := s . Scheduler .( hasHotStatus ). GetPendingInfluence ()
585
+ func collectPendingInfluence (stores []* core.StoreInfo ) {
586
+ pendings := statistics . GetPendingInfluence (stores )
609
587
for _ , s := range stores {
610
588
storeAddress := s .GetAddress ()
611
589
storeID := s .GetID ()
0 commit comments