diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index d603756446e..d0caf938088 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -375,14 +375,6 @@ func (c *Coordinator) initSchedulers() { if err != nil { log.Fatal("cannot load schedulers' config", errs.ZapError(err)) } - - // If the cluster was set up with `raft-kv2` engine, this cluster should - // open `evict-slow-trend` scheduler as default. - if c.GetCluster().GetStoreConfig().IsRaftKV2() { - scheduleNames = append(scheduleNames, schedulers.EvictSlowTrendType) - configs = append(configs, "") - } - scheduleCfg := c.cluster.GetSchedulerConfig().GetScheduleConfig().Clone() // The new way to create scheduler with the independent configuration. for i, name := range scheduleNames { @@ -446,6 +438,20 @@ func (c *Coordinator) initSchedulers() { if err := c.cluster.GetSchedulerConfig().Persist(c.cluster.GetStorage()); err != nil { log.Error("cannot persist schedule config", errs.ZapError(err)) } + + // If the cluster was set up with `raft-kv2` engine, this cluster should + // enable `evict-slow-trend` scheduler as default. + if c.GetCluster().GetStoreConfig().IsRaftKV2() { + name := schedulers.EvictSlowTrendType + args := []string{} + + s, err := schedulers.CreateScheduler(name, c.opController, c.cluster.GetStorage(), schedulers.ConfigSliceDecoder(name, args), c.schedulers.RemoveScheduler) + if err != nil { + log.Warn("initializing evict-slow-trend scheduler failed", errs.ZapError(err)) + } else if err = c.schedulers.AddScheduler(s, args...); err != nil { + log.Error("can not add scheduler", zap.String("scheduler-name", s.GetName()), zap.Strings("scheduler-args", args), errs.ZapError(err)) + } + } } // LoadPlugin load user plugin