Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcs: use a controller to manage scheduling jobs #7270

Merged
merged 11 commits into from
Nov 10, 2023
402 changes: 75 additions & 327 deletions server/cluster/cluster.go

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ func TestRegionLabelIsolationLevel(t *testing.T) {
re.NoError(cluster.putRegion(r))

cluster.UpdateRegionsLabelLevelStats([]*core.RegionInfo{r})
counter := cluster.labelLevelStats.GetLabelCounter()
counter := cluster.labelStats.GetLabelCounter()
re.Equal(0, counter["none"])
re.Equal(1, counter["zone"])
}
Expand Down Expand Up @@ -2130,14 +2130,15 @@ func newTestRaftCluster(
basicCluster *core.BasicCluster,
) *RaftCluster {
rc := &RaftCluster{serverCtx: ctx}
rc.InitCluster(id, opt, s, basicCluster, nil)
rc.InitCluster(id, opt, s, basicCluster, nil, nil)
rc.ruleManager = placement.NewRuleManager(storage.NewStorageWithMemoryBackend(), rc, opt)
if opt.IsPlacementRulesEnabled() {
err := rc.ruleManager.Initialize(opt.GetMaxReplicas(), opt.GetLocationLabels(), opt.GetIsolationLevel())
if err != nil {
panic(err)
}
}
rc.schedulingController.init(basicCluster, opt, nil, rc.ruleManager)
return rc
}

Expand Down Expand Up @@ -2502,11 +2503,11 @@ func TestCollectMetricsConcurrent(t *testing.T) {
for i := 0; i < 1000; i++ {
co.CollectHotSpotMetrics()
controller.CollectSchedulerMetrics()
co.GetCluster().(*RaftCluster).collectClusterMetrics()
co.GetCluster().(*RaftCluster).collectStatisticsMetrics()
}
co.ResetHotSpotMetrics()
controller.ResetSchedulerMetrics()
co.GetCluster().(*RaftCluster).resetClusterMetrics()
co.GetCluster().(*RaftCluster).resetStatisticsMetrics()
wg.Wait()
}

Expand Down Expand Up @@ -2537,7 +2538,7 @@ func TestCollectMetrics(t *testing.T) {
for i := 0; i < 1000; i++ {
co.CollectHotSpotMetrics()
controller.CollectSchedulerMetrics()
co.GetCluster().(*RaftCluster).collectClusterMetrics()
co.GetCluster().(*RaftCluster).collectStatisticsMetrics()
}
stores := co.GetCluster().GetStores()
regionStats := co.GetCluster().RegionWriteStats()
Expand All @@ -2552,7 +2553,7 @@ func TestCollectMetrics(t *testing.T) {
re.Equal(status1, status2)
co.ResetHotSpotMetrics()
controller.ResetSchedulerMetrics()
co.GetCluster().(*RaftCluster).resetClusterMetrics()
co.GetCluster().(*RaftCluster).resetStatisticsMetrics()
}

func prepare(setCfg func(*sc.ScheduleConfig), setTc func(*testCluster), run func(*schedule.Coordinator), re *require.Assertions) (*testCluster, *schedule.Coordinator, func()) {
Expand Down
3 changes: 2 additions & 1 deletion server/cluster/cluster_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/errs"
mcsutils "github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/schedule/operator"
"github.com/tikv/pd/pkg/statistics/buckets"
"github.com/tikv/pd/pkg/utils/logutil"
Expand Down Expand Up @@ -233,7 +234,7 @@ func (c *RaftCluster) HandleReportBuckets(b *metapb.Buckets) error {
if err := c.processReportBuckets(b); err != nil {
return err
}
if !c.isAPIServiceMode {
if !c.IsServiceIndependent(mcsutils.SchedulingServiceName) {
c.hotStat.CheckAsync(buckets.NewCheckPeerTask(b))
}
return nil
Expand Down
Loading