From 5d04a6abd7a2bb59e6f2a40fab72c25b3c6f37c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B7=E6=B2=8CDM?= Date: Tue, 15 Sep 2020 14:29:04 +0800 Subject: [PATCH] schedule: add enable-joint-consensus config (#2955) Signed-off-by: Zheng Xiangsheng --- server/config/config.go | 7 +++++++ server/config/persist_options.go | 7 ++++++- server/schedule/operator/builder.go | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index e68f46ac458..a16ea564cf8 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -669,6 +669,8 @@ type ScheduleConfig struct { EnableLocationReplacement bool `toml:"enable-location-replacement" json:"enable-location-replacement,string"` // EnableDebugMetrics is the option to enable debug metrics. EnableDebugMetrics bool `toml:"enable-debug-metrics" json:"enable-debug-metrics,string"` + // EnableJointConsensus is the option to enable using joint consensus as a operator step. + EnableJointConsensus bool `toml:"enable-joint-consensus" json:"enable-joint-consensus,string"` // Schedulers support for loading customized schedulers Schedulers SchedulerConfigs `toml:"schedulers" json:"schedulers-v2"` // json v2 is for the sake of compatible upgrade @@ -727,6 +729,7 @@ func (c *ScheduleConfig) Clone() *ScheduleConfig { EnableRemoveExtraReplica: c.EnableRemoveExtraReplica, EnableLocationReplacement: c.EnableLocationReplacement, EnableDebugMetrics: c.EnableDebugMetrics, + EnableJointConsensus: c.EnableJointConsensus, StoreLimitMode: c.StoreLimitMode, Schedulers: schedulers, } @@ -755,6 +758,7 @@ const ( defaultSchedulerMaxWaitingOperator = 5 defaultLeaderSchedulePolicy = "count" defaultStoreLimitMode = "manual" + defaultEnableJointConsensus = true ) func (c *ScheduleConfig) adjust(meta *configMetaData) error { @@ -803,6 +807,9 @@ func (c *ScheduleConfig) adjust(meta *configMetaData) error { if !meta.IsDefined("store-limit-mode") { adjustString(&c.StoreLimitMode, defaultStoreLimitMode) } + if !meta.IsDefined("enable-joint-consensus") { + c.EnableJointConsensus = defaultEnableJointConsensus + } adjustFloat64(&c.LowSpaceRatio, defaultLowSpaceRatio) adjustFloat64(&c.HighSpaceRatio, defaultHighSpaceRatio) diff --git a/server/config/persist_options.go b/server/config/persist_options.go index f2dc63e4a90..80a003cd86f 100644 --- a/server/config/persist_options.go +++ b/server/config/persist_options.go @@ -378,11 +378,16 @@ func (o *PersistOptions) IsLocationReplacementEnabled() bool { return o.GetScheduleConfig().EnableLocationReplacement } -// IsDebugMetricsEnabled mocks method +// IsDebugMetricsEnabled returns if debug metrics is enabled. func (o *PersistOptions) IsDebugMetricsEnabled() bool { return o.GetScheduleConfig().EnableDebugMetrics } +// IsUseJointConsensus returns if using joint consensus as a operator step is enabled. +func (o *PersistOptions) IsUseJointConsensus() bool { + return o.GetScheduleConfig().EnableJointConsensus +} + // GetHotRegionCacheHitsThreshold is a threshold to decide if a region is hot. func (o *PersistOptions) GetHotRegionCacheHitsThreshold() int { return int(o.GetScheduleConfig().HotRegionCacheHitsThreshold) diff --git a/server/schedule/operator/builder.go b/server/schedule/operator/builder.go index f8cb37972f5..58779402ee5 100644 --- a/server/schedule/operator/builder.go +++ b/server/schedule/operator/builder.go @@ -135,7 +135,7 @@ func NewBuilder(desc string, cluster opt.Cluster, region *core.RegionInfo, opts b.originLeaderStoreID = originLeaderStoreID b.targetPeers = originPeers.Copy() b.allowDemote = supportJointConsensus - b.useJointConsensus = supportJointConsensus + b.useJointConsensus = supportJointConsensus && cluster.GetOpts().IsUseJointConsensus() b.err = err return b }