From ad5fe051b9a2e6a03a20408f5a294d5bab4797d6 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 4 Dec 2024 17:04:14 +0800 Subject: [PATCH] fix Signed-off-by: Ryan Leung --- pkg/schedule/core/prepare_checker.go | 3 +++ server/cluster/cluster_test.go | 20 +++++++++---------- .../mcs/scheduling/server_test.go | 3 +++ tests/scheduling_cluster.go | 2 +- tests/server/api/api_test.go | 3 ++- tests/server/api/region_test.go | 10 ++++------ 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/pkg/schedule/core/prepare_checker.go b/pkg/schedule/core/prepare_checker.go index d7d5ac2e233..3c5432a9812 100644 --- a/pkg/schedule/core/prepare_checker.go +++ b/pkg/schedule/core/prepare_checker.go @@ -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 diff --git a/server/cluster/cluster_test.go b/server/cluster/cluster_test.go index 6a8a87c1ed3..cbb4574ca7e 100644 --- a/server/cluster/cluster_test.go +++ b/server/cluster/cluster_test.go @@ -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()), ) @@ -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 @@ -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) @@ -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) diff --git a/tests/integrations/mcs/scheduling/server_test.go b/tests/integrations/mcs/scheduling/server_test.go index cb036e8b042..fc07436b92f 100644 --- a/tests/integrations/mcs/scheduling/server_test.go +++ b/tests/integrations/mcs/scheduling/server_test.go @@ -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() diff --git a/tests/scheduling_cluster.go b/tests/scheduling_cluster.go index 3f7c39eb81c..23a59d564b8 100644 --- a/tests/scheduling_cluster.go +++ b/tests/scheduling_cluster.go @@ -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 } diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index 37e727788dd..6d5fc1c0356 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -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 diff --git a/tests/server/api/region_test.go b/tests/server/api/region_test.go index 3a187629830..6467f39b0d7 100644 --- a/tests/server/api/region_test.go +++ b/tests/server/api/region_test.go @@ -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() } @@ -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) { @@ -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) {