Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Dec 5, 2024
1 parent 0bc6e36 commit ad5fe05
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
3 changes: 3 additions & 0 deletions pkg/schedule/core/prepare_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (checker *PrepareChecker) Check(c *core.BasicCluster) bool {
}
notLoadedFromRegionsCnt := c.GetClusterNotFromStorageRegionsCnt()
totalRegionsCnt := c.GetTotalRegionCount()
if totalRegionsCnt == 0 {
return false
}
// 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
Expand Down
20 changes: 10 additions & 10 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2389,12 +2389,12 @@ func (c *testCluster) updateLeaderCount(storeID uint64, leaderCount int) error {
return c.setStore(newStore)
}

func (c *testCluster) addLeaderStore(storeID uint64, leaderCount int) error {
func (c *testCluster) addLeaderStore(storeID uint64) error {
stats := &pdpb.StoreStats{}
newStore := core.NewStoreInfo(&metapb.Store{Id: storeID},
core.SetStoreStats(stats),
core.SetLeaderCount(leaderCount),
core.SetLeaderSize(int64(leaderCount)*10),
core.SetLeaderCount(1),
core.SetLeaderSize(10),
core.SetLastHeartbeatTS(time.Now()),
)

Expand Down Expand Up @@ -3083,9 +3083,9 @@ func TestAddScheduler(t *testing.T) {
stream := mockhbstream.NewHeartbeatStream()

// Add stores 1,2,3
re.NoError(tc.addLeaderStore(1, 1))
re.NoError(tc.addLeaderStore(2, 1))
re.NoError(tc.addLeaderStore(3, 1))
re.NoError(tc.addLeaderStore(1))
re.NoError(tc.addLeaderStore(2))
re.NoError(tc.addLeaderStore(3))
// Add regions 1 with leader in store 1 and followers in stores 2,3
re.NoError(tc.addLeaderRegion(1, 1, 2, 3))
// Add regions 2 with leader in store 2 and followers in stores 1,3
Expand Down Expand Up @@ -3149,8 +3149,8 @@ func TestPersistScheduler(t *testing.T) {
defer cleanup()
defaultCount := len(sc.DefaultSchedulers)
// Add stores 1,2
re.NoError(tc.addLeaderStore(1, 1))
re.NoError(tc.addLeaderStore(2, 1))
re.NoError(tc.addLeaderStore(1))
re.NoError(tc.addLeaderStore(2))

controller := co.GetSchedulersController()
re.Len(controller.GetSchedulerNames(), defaultCount)
Expand Down Expand Up @@ -3265,8 +3265,8 @@ func TestRemoveScheduler(t *testing.T) {
defer cleanup()

// Add stores 1,2
re.NoError(tc.addLeaderStore(1, 1))
re.NoError(tc.addLeaderStore(2, 1))
re.NoError(tc.addLeaderStore(1))
re.NoError(tc.addLeaderStore(2))
defaultCount := len(sc.DefaultSchedulers)
controller := co.GetSchedulersController()
re.Len(controller.GetSchedulerNames(), defaultCount)
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/mcs/scheduling/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ func (suite *serverTestSuite) TestStoreLimit() {
defer tc.Destroy()
leaderServer := suite.pdLeader.GetServer()
tc.WaitForPrimaryServing(re)
testutil.Eventually(re, func() bool {
return leaderServer.GetRaftCluster().IsServiceIndependent(constant.SchedulingServiceName)
})
oc := tc.GetPrimaryServer().GetCluster().GetCoordinator().GetOperatorController()

conf := leaderServer.GetReplicationConfig().Clone()
Expand Down
2 changes: 1 addition & 1 deletion tests/scheduling_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (tc *TestSchedulingCluster) WaitForPrimaryServing(re *require.Assertions) *
var primary *scheduling.Server
testutil.Eventually(re, func() bool {
for _, server := range tc.servers {
if server.IsServing() {
if server.IsServing() && server.GetCoordinator().AreSchedulersInitialized() {
primary = server
return true
}
Expand Down
3 changes: 2 additions & 1 deletion tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,11 +1159,12 @@ func TestDeleteAllRegionCacheScheduling(t *testing.T) {
count := rc.GetOperatorController().OperatorCount(operator.OpSplit)
return count > 0
})
rc.GetOperatorController().RemoveOperators()

// Call the delete API and verify
addr := leaderServer.GetAddr() + "/pd/api/v1/admin/cache/regions"
output := sendRequest(re, addr, http.MethodDelete, http.StatusOK)
re.Contains(string(output), "All regions are removed from server cache")
rc.GetOperatorController().RemoveOperators()
re.Equal(0, int(rc.GetOperatorController().OperatorCount(operator.OpSplit)))

// Simulate continuous heartbeat and verify scheduling recovery
Expand Down
10 changes: 4 additions & 6 deletions tests/server/api/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ func TestRegionTestSuite(t *testing.T) {
}

func (suite *regionTestSuite) SetupSuite() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/checker/skipCheckSuspectRanges", "return(true)"))
suite.env = tests.NewSchedulingTestEnvironment(suite.T())
}

func (suite *regionTestSuite) TearDownSuite() {
re := suite.Require()
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/checker/skipCheckSuspectRanges"))
suite.env.Cleanup()
}

Expand Down Expand Up @@ -138,10 +142,7 @@ func (suite *regionTestSuite) checkSplitRegions(cluster *tests.TestCluster) {
}

func (suite *regionTestSuite) TestAccelerateRegionsScheduleInRange() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/checker/skipCheckSuspectRanges", "return(true)"))
suite.env.RunTestBasedOnMode(suite.checkAccelerateRegionsScheduleInRange)
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/checker/skipCheckSuspectRanges"))
}

func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRange(cluster *tests.TestCluster) {
Expand Down Expand Up @@ -176,10 +177,7 @@ func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRange(cluster *tes
}

func (suite *regionTestSuite) TestAccelerateRegionsScheduleInRanges() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/schedule/checker/skipCheckSuspectRanges", "return(true)"))
suite.env.RunTestBasedOnMode(suite.checkAccelerateRegionsScheduleInRanges)
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/schedule/checker/skipCheckSuspectRanges"))
}

func (suite *regionTestSuite) checkAccelerateRegionsScheduleInRanges(cluster *tests.TestCluster) {
Expand Down

0 comments on commit ad5fe05

Please sign in to comment.