Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Jun 28, 2024
1 parent 905945f commit a53ebc0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
7 changes: 7 additions & 0 deletions pkg/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
const (
randomRegionMaxRetry = 10
scanRegionLimit = 1000
CollectFactor = 0.9
)

// errRegionIsStale is error info for region is stale.
Expand Down Expand Up @@ -1583,6 +1584,12 @@ func (r *RegionsInfo) GetNotFromStorageRegionsCntByStore(storeID uint64) int {
return r.getNotFromStorageRegionsCntByStoreLocked(storeID)
}

// IsStorePrepared checks if a store is prepared.
// For each store, the number of active regions should be more than total region of the store * CollectFactor
func (r *RegionsInfo) IsStorePrepared(storeID uint64) bool {
return float64(r.GetNotFromStorageRegionsCntByStore(storeID)) >= float64(r.GetStoreRegionCount(storeID))*CollectFactor
}

// getNotFromStorageRegionsCntByStoreLocked gets the `NotFromStorageRegionsCnt` count of a store's leader, follower and learner by storeID.
func (r *RegionsInfo) getNotFromStorageRegionsCntByStoreLocked(storeID uint64) int {
return r.leaders[storeID].notFromStorageRegionsCount() + r.followers[storeID].notFromStorageRegionsCount() + r.learners[storeID].notFromStorageRegionsCount()
Expand Down
1 change: 0 additions & 1 deletion pkg/schedule/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
const (
runSchedulerCheckInterval = 3 * time.Second
checkSuspectRangesInterval = 100 * time.Millisecond
CollectFactor = 0.9
collectTimeout = 5 * time.Minute
maxLoadConfigRetries = 10
// pushOperatorTickInterval is the interval try to push the operator.
Expand Down
9 changes: 4 additions & 5 deletions pkg/schedule/prepare_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (checker *prepareChecker) check(c *core.BasicCluster, collectWaitTime ...ti
}
notLoadedFromRegionsCnt := c.GetClusterNotFromStorageRegionsCnt()
totalRegionsCnt := c.GetTotalRegionCount()
// The number of active regions should be more than total region of all stores * CollectFactor
if float64(totalRegionsCnt)*CollectFactor > float64(notLoadedFromRegionsCnt) {
// The number of active regions should be more than total region of all stores * core.CollectFactor
if float64(totalRegionsCnt)*core.CollectFactor > float64(notLoadedFromRegionsCnt) {
return false
}
for _, store := range c.GetStores() {
Expand All @@ -61,11 +61,10 @@ func (checker *prepareChecker) check(c *core.BasicCluster, collectWaitTime ...ti
}
storeID := store.GetID()
// It is used to avoid sudden scheduling when scheduling service is just started.
if len(collectWaitTime) > 0 && (float64(store.GetStoreStats().GetRegionCount())*CollectFactor > float64(c.GetNotFromStorageRegionsCntByStore(storeID))) {
if len(collectWaitTime) > 0 && (float64(store.GetStoreStats().GetRegionCount())*core.CollectFactor > float64(c.GetNotFromStorageRegionsCntByStore(storeID))) {
return false
}
// For each store, the number of active regions should be more than total region of the store * CollectFactor
if float64(c.GetStoreRegionCount(storeID))*CollectFactor > float64(c.GetNotFromStorageRegionsCntByStore(storeID)) {
if !c.IsStorePrepared(storeID) {
return false
}
}
Expand Down
4 changes: 1 addition & 3 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/tikv/pd/pkg/progress"
"github.com/tikv/pd/pkg/ratelimit"
"github.com/tikv/pd/pkg/replication"
"github.com/tikv/pd/pkg/schedule"
sc "github.com/tikv/pd/pkg/schedule/config"
"github.com/tikv/pd/pkg/schedule/hbstream"
"github.com/tikv/pd/pkg/schedule/labeler"
Expand Down Expand Up @@ -1597,8 +1596,7 @@ func (c *RaftCluster) isStorePrepared() bool {
continue
}
storeID := store.GetID()
// For each store, the number of active regions should be more than total region of the store * CollectFactor
if float64(c.GetStoreRegionCount(storeID))*schedule.CollectFactor > float64(c.GetNotFromStorageRegionsCntByStore(storeID)) {
if !c.IsStorePrepared(storeID) {
return false
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/integrations/mcs/scheduling/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,7 @@ func (suite *serverTestSuite) TestStoreLimit() {

stream, err := grpcPDClient.RegionHeartbeat(suite.ctx)
re.NoError(err)
// set up to 2000 to avoid the case conflicts
for i := uint64(2000); i <= 10; i++ {
for i := uint64(2); i <= 10; i++ {
peers := []*metapb.Peer{{Id: i, StoreId: 1}}
regionReq := &pdpb.RegionHeartbeatRequest{
Header: testutil.NewRequestHeader(suite.pdLeader.GetClusterID()),
Expand Down Expand Up @@ -742,4 +741,6 @@ func (suite *serverTestSuite) TestOnlineProgress() {
re.NotEmpty(cs)
re.NotEmpty(ls)
re.NoError(err)
suite.TearDownSuite()
suite.SetupSuite()
}

0 comments on commit a53ebc0

Please sign in to comment.