From 619a97e91ed9998e81bea18d0f10ea49cd5fe4a9 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 8 Aug 2023 18:03:01 +0800 Subject: [PATCH] remove GetPersistOptions for cluster Signed-off-by: Ryan Leung --- pkg/mcs/scheduling/server/cluster.go | 5 ----- pkg/mock/mockcluster/mockcluster.go | 5 ----- pkg/schedule/coordinator.go | 8 ++++---- pkg/schedule/core/cluster_informer.go | 1 - pkg/unsaferecovery/unsafe_recovery_controller.go | 4 ++-- server/cluster/cluster.go | 5 ----- server/cluster/cluster_test.go | 12 ++++++------ 7 files changed, 12 insertions(+), 28 deletions(-) diff --git a/pkg/mcs/scheduling/server/cluster.go b/pkg/mcs/scheduling/server/cluster.go index f48416c15d7a..1d56817068a0 100644 --- a/pkg/mcs/scheduling/server/cluster.go +++ b/pkg/mcs/scheduling/server/cluster.go @@ -102,11 +102,6 @@ func (c *Cluster) BucketsStats(degree int, regionIDs ...uint64) map[uint64][]*bu return c.hotStat.BucketsStats(degree, regionIDs...) } -// GetPersistOptions returns the persist options. -func (c *Cluster) GetPersistOptions() sc.ConfProvider { - return c.persistConfig -} - // TODO: implement the following methods // GetStorage returns the storage. diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index 5c213dc43bbe..19dc25f713ff 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -114,11 +114,6 @@ func (mc *Cluster) AllocID() (uint64, error) { return mc.IDAllocator.Alloc() } -// GetPersistOptions returns the persist options. -func (mc *Cluster) GetPersistOptions() sc.ConfProvider { - return mc.PersistOptions -} - // UpdateRegionsLabelLevelStats updates the label level stats for the regions. func (mc *Cluster) UpdateRegionsLabelLevelStats(regions []*core.RegionInfo) {} diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index 0ec98a069302..58fd3093299a 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -169,7 +169,7 @@ func (c *Coordinator) PatrolRegions() { } func (c *Coordinator) isSchedulingHalted() bool { - return c.cluster.GetPersistOptions().IsSchedulingHalted() + return c.cluster.GetSchedulerConfig().IsSchedulingHalted() } func (c *Coordinator) checkRegions(startKey []byte) (key []byte, regions []*core.RegionInfo) { @@ -376,7 +376,7 @@ func (c *Coordinator) initSchedulers() { log.Fatal("cannot load schedulers' config", errs.ZapError(err)) } - scheduleCfg := c.cluster.GetPersistOptions().GetScheduleConfig().Clone() + scheduleCfg := c.cluster.GetSchedulerConfig().GetScheduleConfig().Clone() // The new way to create scheduler with the independent configuration. for i, name := range scheduleNames { data := configs[i] @@ -435,8 +435,8 @@ func (c *Coordinator) initSchedulers() { // Removes the invalid scheduler config and persist. scheduleCfg.Schedulers = scheduleCfg.Schedulers[:k] - c.cluster.GetPersistOptions().SetScheduleConfig(scheduleCfg) - if err := c.cluster.GetPersistOptions().Persist(c.cluster.GetStorage()); err != nil { + c.cluster.GetSchedulerConfig().SetScheduleConfig(scheduleCfg) + if err := c.cluster.GetSchedulerConfig().Persist(c.cluster.GetStorage()); err != nil { log.Error("cannot persist schedule config", errs.ZapError(err)) } } diff --git a/pkg/schedule/core/cluster_informer.go b/pkg/schedule/core/cluster_informer.go index 3cdb992a4732..63dacd0c30dd 100644 --- a/pkg/schedule/core/cluster_informer.go +++ b/pkg/schedule/core/cluster_informer.go @@ -31,7 +31,6 @@ type ClusterInformer interface { GetStorage() storage.Storage UpdateRegionsLabelLevelStats(regions []*core.RegionInfo) - GetPersistOptions() sc.ConfProvider } // SchedulerCluster is an aggregate interface that wraps multiple interfaces diff --git a/pkg/unsaferecovery/unsafe_recovery_controller.go b/pkg/unsaferecovery/unsafe_recovery_controller.go index df4c8e170028..a0f6d997ac0a 100644 --- a/pkg/unsaferecovery/unsafe_recovery_controller.go +++ b/pkg/unsaferecovery/unsafe_recovery_controller.go @@ -109,7 +109,7 @@ type cluster interface { DropCacheAllRegion() AllocID() (uint64, error) BuryStore(storeID uint64, forceBury bool) error - GetPersistOptions() sc.ConfProvider + GetSchedulerConfig() sc.SchedulerConfigProvider } // Controller is used to control the unsafe recovery process. @@ -493,7 +493,7 @@ func (u *Controller) changeStage(stage stage) { u.stage = stage // Halt and resume the scheduling once the running state changed. running := isRunning(stage) - if opt := u.cluster.GetPersistOptions(); opt.IsSchedulingHalted() != running { + if opt := u.cluster.GetSchedulerConfig(); opt.IsSchedulingHalted() != running { opt.SetHaltScheduling(running, "online-unsafe-recovery") } diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index c6c3e648de0c..9dac7f90e264 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -758,11 +758,6 @@ func (c *RaftCluster) GetOpts() sc.ConfProvider { return c.opt } -// GetPersistOptions returns cluster's configuration. -func (c *RaftCluster) GetPersistOptions() sc.ConfProvider { - return c.opt -} - // GetScheduleConfig returns scheduling configurations. func (c *RaftCluster) GetScheduleConfig() *sc.ScheduleConfig { return c.opt.GetScheduleConfig() diff --git a/server/cluster/cluster_test.go b/server/cluster/cluster_test.go index def046735dff..e22c8aff5ee3 100644 --- a/server/cluster/cluster_test.go +++ b/server/cluster/cluster_test.go @@ -2999,7 +2999,7 @@ func TestPersistScheduler(t *testing.T) { re.NoError(controller.RemoveScheduler(schedulers.BalanceWitnessName)) re.NoError(controller.RemoveScheduler(schedulers.TransferWitnessLeaderName)) re.Len(controller.GetSchedulerNames(), defaultCount-3) - re.NoError(co.GetCluster().GetPersistOptions().Persist(storage)) + re.NoError(co.GetCluster().GetSchedulerConfig().Persist(storage)) co.Stop() co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() @@ -3052,12 +3052,12 @@ func TestPersistScheduler(t *testing.T) { // the scheduler option should contain 6 items // the `hot scheduler` are disabled - re.Len(co.GetCluster().GetPersistOptions().(*config.PersistOptions).GetSchedulers(), defaultCount+3) + re.Len(co.GetCluster().GetSchedulerConfig().(*config.PersistOptions).GetSchedulers(), defaultCount+3) re.NoError(controller.RemoveScheduler(schedulers.GrantLeaderName)) // the scheduler that is not enable by default will be completely deleted - re.Len(co.GetCluster().GetPersistOptions().(*config.PersistOptions).GetSchedulers(), defaultCount+2) + re.Len(co.GetCluster().GetSchedulerConfig().(*config.PersistOptions).GetSchedulers(), defaultCount+2) re.Len(controller.GetSchedulerNames(), 4) - re.NoError(co.GetCluster().GetPersistOptions().Persist(co.GetCluster().GetStorage())) + re.NoError(co.GetCluster().GetSchedulerConfig().Persist(co.GetCluster().GetStorage())) co.Stop() co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() @@ -3114,7 +3114,7 @@ func TestRemoveScheduler(t *testing.T) { re.NoError(err) re.Empty(sches) re.Empty(controller.GetSchedulerNames()) - re.NoError(co.GetCluster().GetPersistOptions().Persist(co.GetCluster().GetStorage())) + re.NoError(co.GetCluster().GetSchedulerConfig().Persist(co.GetCluster().GetStorage())) co.Stop() co.GetSchedulersController().Wait() co.GetWaitGroup().Wait() @@ -3128,7 +3128,7 @@ func TestRemoveScheduler(t *testing.T) { co.Run() re.Empty(controller.GetSchedulerNames()) // the option remains default scheduler - re.Len(co.GetCluster().GetPersistOptions().(*config.PersistOptions).GetSchedulers(), defaultCount) + re.Len(co.GetCluster().GetSchedulerConfig().(*config.PersistOptions).GetSchedulers(), defaultCount) co.Stop() co.GetSchedulersController().Wait() co.GetWaitGroup().Wait()