From d6a7c77ab19535bb5046199305567af019974638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B7=E6=B2=8CDM?= Date: Thu, 3 Sep 2020 17:08:53 +0800 Subject: [PATCH] cluster: refine IsFeatureSupported (#2889) Signed-off-by: Zheng Xiangsheng --- pkg/mock/mockcluster/mockcluster.go | 32 +++++++++++++++++++---------- server/cluster/cluster.go | 2 -- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index 46cad5aa089..97e8c68a8a1 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -40,8 +40,9 @@ type Cluster struct { *placement.RuleManager *statistics.HotCache *statistics.StoresStats - ID uint64 - suspectRegions map[uint64]struct{} + ID uint64 + suspectRegions map[uint64]struct{} + disabledFeatures map[versioninfo.Feature]struct{} } // NewCluster creates a new Cluster @@ -49,13 +50,14 @@ func NewCluster(opt *mockoption.ScheduleOptions) *Cluster { ruleManager := placement.NewRuleManager(core.NewStorage(kv.NewMemoryKV())) ruleManager.Initialize(opt.MaxReplicas, opt.GetLocationLabels()) return &Cluster{ - BasicCluster: core.NewBasicCluster(), - IDAllocator: mockid.NewIDAllocator(), - ScheduleOptions: opt, - RuleManager: ruleManager, - HotCache: statistics.NewHotCache(), - StoresStats: statistics.NewStoresStats(), - suspectRegions: map[uint64]struct{}{}, + BasicCluster: core.NewBasicCluster(), + IDAllocator: mockid.NewIDAllocator(), + ScheduleOptions: opt, + RuleManager: ruleManager, + HotCache: statistics.NewHotCache(), + StoresStats: statistics.NewStoresStats(), + suspectRegions: make(map[uint64]struct{}), + disabledFeatures: make(map[versioninfo.Feature]struct{}), } } @@ -637,9 +639,17 @@ func (mc *Cluster) SetStoreLabel(storeID uint64, labels map[string]string) { mc.PutStore(newStore) } +// DisableFeature marks that these features are not supported in the cluster. +func (mc *Cluster) DisableFeature(fs ...versioninfo.Feature) { + for _, f := range fs { + mc.disabledFeatures[f] = struct{}{} + } +} + // IsFeatureSupported checks if the feature is supported by current cluster. -func (mc *Cluster) IsFeatureSupported(versioninfo.Feature) bool { - return true +func (mc *Cluster) IsFeatureSupported(f versioninfo.Feature) bool { + _, ok := mc.disabledFeatures[f] + return !ok } // AddSuspectRegions mock method diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index a4a7e788622..919cc6ce853 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -1334,8 +1334,6 @@ func (c *RaftCluster) changedRegionNotifier() <-chan *core.RegionInfo { // IsFeatureSupported checks if the feature is supported by current cluster. func (c *RaftCluster) IsFeatureSupported(f versioninfo.Feature) bool { - c.RLock() - defer c.RUnlock() clusterVersion := *c.opt.GetClusterVersion() minSupportVersion := *versioninfo.MinSupportedVersion(f) // For features before version 5.0 (such as BatchSplit), strict version checks are performed according to the