From 668ca97baa1aa10626f8f691a816c73f5616d3a9 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 24 May 2024 16:56:25 +0800 Subject: [PATCH] fix Signed-off-by: Ryan Leung --- pkg/mock/mockcluster/mockcluster.go | 12 +++++++++--- pkg/statistics/hot_peer_cache_test.go | 4 +++- tools/pd-ctl/tests/hot/hot_test.go | 3 +-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index aed8c8fd3ba4..8b8539a610a0 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -894,7 +894,9 @@ func (mc *Cluster) CheckRegionRead(region *core.RegionInfo) []*statistics.HotPee items := make([]*statistics.HotPeerStat, 0) expiredItems := mc.HotCache.ExpiredReadItems(region) items = append(items, expiredItems...) - return append(items, mc.HotCache.CheckReadPeerSync(region, nil, region.GetInterval().GetEndTimestamp()-region.GetInterval().GetStartTimestamp())...) + reportInterval := region.GetInterval() + interval := reportInterval.GetEndTimestamp() - reportInterval.GetStartTimestamp() + return append(items, mc.HotCache.CheckReadPeerSync(region, nil, interval)...) } // CheckRegionWrite checks region write info with all peers @@ -902,7 +904,9 @@ func (mc *Cluster) CheckRegionWrite(region *core.RegionInfo) []*statistics.HotPe items := make([]*statistics.HotPeerStat, 0) expiredItems := mc.HotCache.ExpiredWriteItems(region) items = append(items, expiredItems...) - return append(items, mc.HotCache.CheckWritePeerSync(region, nil, region.GetInterval().GetEndTimestamp()-region.GetInterval().GetStartTimestamp())...) + reportInterval := region.GetInterval() + interval := reportInterval.GetEndTimestamp() - reportInterval.GetStartTimestamp() + return append(items, mc.HotCache.CheckWritePeerSync(region, nil, interval)...) } // CheckRegionLeaderRead checks region read info with leader peer @@ -910,7 +914,9 @@ func (mc *Cluster) CheckRegionLeaderRead(region *core.RegionInfo) []*statistics. items := make([]*statistics.HotPeerStat, 0) expiredItems := mc.HotCache.ExpiredReadItems(region) items = append(items, expiredItems...) - return append(items, mc.HotCache.CheckReadPeerSync(region, nil, region.GetInterval().GetEndTimestamp()-region.GetInterval().GetStartTimestamp())...) + reportInterval := region.GetInterval() + interval := reportInterval.GetEndTimestamp() - reportInterval.GetStartTimestamp() + return append(items, mc.HotCache.CheckReadPeerSync(region, nil, interval)...) } // ObserveRegionsStats records the current stores stats from region stats. diff --git a/pkg/statistics/hot_peer_cache_test.go b/pkg/statistics/hot_peer_cache_test.go index 2a9dcc44df7a..151d7a631e82 100644 --- a/pkg/statistics/hot_peer_cache_test.go +++ b/pkg/statistics/hot_peer_cache_test.go @@ -106,8 +106,10 @@ func orderingPeers(cache *hotPeerCache, region *core.RegionInfo) []*metapb.Peer } func checkFlow(cache *hotPeerCache, region *core.RegionInfo, peers []*metapb.Peer) (res []*HotPeerStat) { + reportInterval := region.GetInterval() + interval := reportInterval.GetEndTimestamp() - reportInterval.GetStartTimestamp() res = append(res, cache.collectExpiredItems(region)...) - return append(res, cache.checkPeerFlow(region, peers, region.GetLoads(), region.GetInterval().GetEndTimestamp()-region.GetInterval().GetStartTimestamp())...) + return append(res, cache.checkPeerFlow(region, peers, region.GetLoads(), interval)...) } func updateFlow(cache *hotPeerCache, res []*HotPeerStat) []*HotPeerStat { diff --git a/tools/pd-ctl/tests/hot/hot_test.go b/tools/pd-ctl/tests/hot/hot_test.go index 27efa1c5a77a..2909612f822b 100644 --- a/tools/pd-ctl/tests/hot/hot_test.go +++ b/tools/pd-ctl/tests/hot/hot_test.go @@ -191,8 +191,7 @@ func (suite *hotTestSuite) checkHot(cluster *pdTests.TestCluster) { region := core.NewRegionInfo(&metapb.Region{ Id: hotRegionID, }, leader) - interval := region.GetInterval() - hotStat.CheckReadAsync(statistics.NewCheckPeerTask(region, loads, interval.GetEndTimestamp()-interval.GetStartTimestamp())) + hotStat.CheckReadAsync(statistics.NewCheckPeerTask(region, loads, reportInterval)) testutil.Eventually(re, func() bool { hotPeerStat := getHotPeerStat(utils.Read, hotRegionID, hotStoreID) return hotPeerStat != nil