Skip to content

Commit

Permalink
cluster: refine IsFeatureSupported (tikv#2889)
Browse files Browse the repository at this point in the history
Signed-off-by: Zheng Xiangsheng <hundundm@gmail.com>
  • Loading branch information
HunDunDM committed Sep 3, 2020
1 parent 5893584 commit 11d9a60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 21 additions & 11 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,24 @@ 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
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{}),
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11d9a60

Please sign in to comment.