Skip to content

Commit

Permalink
schedule: add option to disable namespace checker (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanne007 authored and disksing committed Aug 16, 2018
1 parent 9b0763f commit a2cf96b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions server/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ func (c *clusterInfo) IsLocationReplacementEnabled() bool {
return c.opt.IsLocationReplacementEnabled()
}

func (c *clusterInfo) IsNamespaceRelocationEnabled() bool {
return c.opt.IsNamespaceRelocationEnabled()
}

func (c *clusterInfo) CheckLabelProperty(typ string, labels []*metapb.StoreLabel) bool {
return c.opt.CheckLabelProperty(typ, labels)
}
Expand Down
3 changes: 3 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ type ScheduleConfig struct {
// DisableLocationReplacement is the option to prevent replica checker from
// moving replica to a better location.
DisableLocationReplacement bool `toml:"disable-location-replacement" json:"disable-location-replacement,string"`
// DisableNamespaceRelocation is the option to prevent namespace checker
// from moving replica to the target namespace.
DisableNamespaceRelocation bool `toml:"disable-namespace-relocation" json:"disable-namespace-relocation,string"`

// Schedulers support for loding customized schedulers
Schedulers SchedulerConfigs `toml:"schedulers,omitempty" json:"schedulers-v2"` // json v2 is for the sake of compatible upgrade
Expand Down
14 changes: 10 additions & 4 deletions server/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import (
var _ = Suite(&testNamespaceSuite{})

type testNamespaceSuite struct {
classifier *mapClassifer
tc *testClusterInfo
opt *scheduleOption
classifier *mapClassifer
tc *testClusterInfo
opt *scheduleOption
scheduleConfig *ScheduleConfig
}

func (s *testNamespaceSuite) SetUpTest(c *C) {
s.classifier = newMapClassifer()
_, s.opt = newTestScheduleConfig()
s.scheduleConfig, s.opt = newTestScheduleConfig()
s.tc = newTestClusterInfo(s.opt)
}

Expand Down Expand Up @@ -103,6 +104,11 @@ func (s *testNamespaceSuite) TestNamespaceChecker(c *C) {
// Move the peer with questions to the right store if the region has multiple peers.
s.classifier.setRegion(5, "ns1")
s.tc.addLeaderRegion(5, 1, 1, 3)

s.scheduleConfig.DisableNamespaceRelocation = true
c.Assert(checker.Check(s.tc.GetRegion(5)), IsNil)
s.scheduleConfig.DisableNamespaceRelocation = false

op = checker.Check(s.tc.GetRegion(5))
testutil.CheckTransferPeer(c, op, schedule.OpReplica, 3, 2)
}
Expand Down
4 changes: 4 additions & 0 deletions server/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func (o *scheduleOption) IsLocationReplacementEnabled() bool {
return !o.load().DisableLocationReplacement
}

func (o *scheduleOption) IsNamespaceRelocationEnabled() bool {
return !o.load().DisableNamespaceRelocation
}

func (o *scheduleOption) GetSchedulers() SchedulerConfigs {
return o.load().Schedulers
}
Expand Down
6 changes: 6 additions & 0 deletions server/schedule/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ type MockSchedulerOptions struct {
DisableMakeUpReplica bool
DisableRemoveExtraReplica bool
DisableLocationReplacement bool
DisableNamespaceRelocation bool
LabelProperties map[string][]*metapb.StoreLabel
}

Expand Down Expand Up @@ -592,3 +593,8 @@ func (mso *MockSchedulerOptions) IsRemoveExtraReplicaEnabled() bool {
func (mso *MockSchedulerOptions) IsLocationReplacementEnabled() bool {
return !mso.DisableLocationReplacement
}

// IsNamespaceRelocationEnabled mock method.
func (mso *MockSchedulerOptions) IsNamespaceRelocationEnabled() bool {
return !mso.DisableNamespaceRelocation
}
4 changes: 4 additions & 0 deletions server/schedule/namespace_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func NewNamespaceChecker(cluster Cluster, classifier namespace.Classifier) *Name

// Check verifies a region's namespace, creating an Operator if need.
func (n *NamespaceChecker) Check(region *core.RegionInfo) *Operator {
if !n.cluster.IsNamespaceRelocationEnabled() {
return nil
}

checkerCounter.WithLabelValues("namespace_checker", "check").Inc()

// fail-fast if there is only ONE namespace
Expand Down
1 change: 1 addition & 0 deletions server/schedule/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Options interface {
IsMakeUpReplicaEnabled() bool
IsRemoveExtraReplicaEnabled() bool
IsLocationReplacementEnabled() bool
IsNamespaceRelocationEnabled() bool

CheckLabelProperty(typ string, labels []*metapb.StoreLabel) bool
}
Expand Down

0 comments on commit a2cf96b

Please sign in to comment.