Skip to content

Commit

Permalink
cluster: don't collect region stats in API mode (#7817)
Browse files Browse the repository at this point in the history
close #7816

Signed-off-by: Cabinfever_B <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
CabinfeverB and ti-chi-bot[bot] authored Feb 18, 2024
1 parent 5a37b80 commit e264a61
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
// Save to storage if meta is updated, except for flashback.
// Save to cache if meta or leader is updated, or contains any down/pending peer.
saveKV, saveCache, needSync := regionGuide(region, origin)
if !saveKV && !saveCache {
if !c.IsServiceIndependent(mcsutils.SchedulingServiceName) && !saveKV && !saveCache {
// Due to some config changes need to update the region stats as well,
// so we do some extra checks here.
if hasRegionStats && c.regionStats.RegionStatsNeedUpdate(region) {
Expand Down Expand Up @@ -1035,8 +1035,9 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
}
regionUpdateCacheEventCounter.Inc()
}

cluster.Collect(c, region, c.GetRegionStores(region), hasRegionStats)
if !c.IsServiceIndependent(mcsutils.SchedulingServiceName) {
cluster.Collect(c, region, c.GetRegionStores(region), hasRegionStats)
}

if c.storage != nil {
// If there are concurrent heartbeats from the same region, the last write will win even if
Expand Down
27 changes: 27 additions & 0 deletions tests/server/api/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/schedule/placement"
"github.com/tikv/pd/pkg/statistics"
tu "github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/tests"
)
Expand Down Expand Up @@ -172,6 +173,32 @@ func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRange(cluster *tes
re.Len(idList, 2, len(idList))
}

func (suite *regionTestSuite) TestRegionStats() {
env := tests.NewSchedulingTestEnvironment(suite.T())
env.RunTestInAPIMode(suite.checkRegionStats)
env.Cleanup()
}

func (suite *regionTestSuite) checkRegionStats(cluster *tests.TestCluster) {
re := suite.Require()
leader := cluster.GetLeaderServer()
rc := leader.GetRaftCluster()
re.NotNil(rc)
for i := 13; i <= 16; i++ {
s1 := &metapb.Store{
Id: uint64(i),
State: metapb.StoreState_Up,
NodeState: metapb.NodeState_Serving,
}
tests.MustPutStore(re, cluster, s1)
}
r := core.NewTestRegionInfo(1001, 13, []byte("b1"), []byte("b2"), core.SetApproximateSize(0))
r.GetMeta().Peers = append(r.GetMeta().Peers, &metapb.Peer{Id: 5, StoreId: 14}, &metapb.Peer{Id: 6, StoreId: 15})
tests.MustPutRegionInfo(re, cluster, r)
suite.checkRegionCount(re, cluster, 1)
re.False(rc.GetRegionStats().IsRegionStatsType(1001, statistics.EmptyRegion))
}

func (suite *regionTestSuite) TestAccelerateRegionsScheduleInRanges() {
suite.env.RunTestInTwoModes(suite.checkAccelerateRegionsScheduleInRanges)
}
Expand Down

0 comments on commit e264a61

Please sign in to comment.