Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Sep 22, 2023
1 parent e2d33e0 commit 444a4db
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 607 deletions.
466 changes: 0 additions & 466 deletions pkg/mcs/scheduling/server/cluster.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,8 @@ func (mc *Cluster) AllocPeer(storeID uint64) (*metapb.Peer, error) {

func (mc *Cluster) initRuleManager() {
if mc.RuleManager == nil {
<<<<<<< HEAD
mc.RuleManager = placement.NewRuleManager(storage.NewStorageWithMemoryBackend(), mc, mc.GetOpts())
mc.RuleManager.Initialize(int(mc.GetReplicationConfig().MaxReplicas), mc.GetReplicationConfig().LocationLabels)
=======
mc.RuleManager = placement.NewRuleManager(mc.GetStorage(), mc, mc.GetSharedConfig())
mc.RuleManager.Initialize(int(mc.GetReplicationConfig().MaxReplicas), mc.GetReplicationConfig().LocationLabels, mc.GetReplicationConfig().IsolationLevel)
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122))
}
}

Expand Down
17 changes: 3 additions & 14 deletions server/api/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,27 +358,16 @@ func (s *testTransferRegionOperatorSuite) TestTransferRegionWithPlacementRule(c
}, ", "),
},
}
<<<<<<< HEAD
for _, tc := range tt {
c.Log(tc.name)
s.svr.GetRaftCluster().GetOpts().SetPlacementRuleEnabled(tc.placementRuleEnable)
if tc.placementRuleEnable {
err := s.svr.GetRaftCluster().GetRuleManager().Initialize(
s.svr.GetRaftCluster().GetOpts().GetMaxReplicas(),
s.svr.GetRaftCluster().GetOpts().GetLocationLabels())
c.Assert(err, IsNil)
=======
for _, testCase := range testCases {
suite.T().Log(testCase.name)
suite.svr.GetRaftCluster().GetOpts().SetPlacementRuleEnabled(testCase.placementRuleEnable)
if testCase.placementRuleEnable {
err := suite.svr.GetRaftCluster().GetRuleManager().Initialize(
suite.svr.GetRaftCluster().GetOpts().GetMaxReplicas(),
suite.svr.GetRaftCluster().GetOpts().GetLocationLabels(),
suite.svr.GetRaftCluster().GetOpts().GetIsolationLevel(),
s.svr.GetRaftCluster().GetOpts().GetLocationLabels(),
s.svr.GetRaftCluster().GetOpts().GetIsolationLevel(),
)
suite.NoError(err)
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122))
c.Assert(err, IsNil)
}
if len(tc.rules) > 0 {
// add customized rule first and then remove default rule
Expand Down
32 changes: 0 additions & 32 deletions server/config/persist_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,45 +260,13 @@ func (o *PersistOptions) SetSplitMergeInterval(splitMergeInterval time.Duration)
o.SetScheduleConfig(v)
}

<<<<<<< HEAD
=======
// GetSwitchWitnessInterval returns the interval between promote to non-witness and starting to switch to witness.
func (o *PersistOptions) GetSwitchWitnessInterval() time.Duration {
return o.GetScheduleConfig().SwitchWitnessInterval.Duration
}

// IsDiagnosticAllowed returns whether is enable to use diagnostic.
func (o *PersistOptions) IsDiagnosticAllowed() bool {
return o.GetScheduleConfig().EnableDiagnostic
}

// SetEnableDiagnostic to set the option for diagnose. It's only used to test.
func (o *PersistOptions) SetEnableDiagnostic(enable bool) {
v := o.GetScheduleConfig().Clone()
v.EnableDiagnostic = enable
o.SetScheduleConfig(v)
}

// IsWitnessAllowed returns whether is enable to use witness.
func (o *PersistOptions) IsWitnessAllowed() bool {
return o.GetScheduleConfig().EnableWitness
}

// SetEnableWitness to set the option for witness. It's only used to test.
func (o *PersistOptions) SetEnableWitness(enable bool) {
v := o.GetScheduleConfig().Clone()
v.EnableWitness = enable
o.SetScheduleConfig(v)
}

// SetMaxStoreDownTime to set the max store down time. It's only used to test.
func (o *PersistOptions) SetMaxStoreDownTime(time time.Duration) {
v := o.GetScheduleConfig().Clone()
v.MaxStoreDownTime = typeutil.NewDuration(time)
o.SetScheduleConfig(v)
}

>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122))
// SetMaxMergeRegionSize sets the max merge region size.
func (o *PersistOptions) SetMaxMergeRegionSize(maxMergeRegionSize uint64) {
v := o.GetScheduleConfig().Clone()
Expand Down
38 changes: 1 addition & 37 deletions server/schedule/placement/rule_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,49 +78,13 @@ func (m *RuleManager) Initialize(maxReplica int, locationLabels []string, isolat
}
if len(m.ruleConfig.rules) == 0 {
// migrate from old config.
<<<<<<< HEAD:server/schedule/placement/rule_manager.go
defaultRule := &Rule{
GroupID: "pd",
ID: "default",
Role: Voter,
Count: maxReplica,
LocationLabels: locationLabels,
=======
var defaultRules []*Rule
if m.conf != nil && m.conf.IsWitnessAllowed() && maxReplica >= 3 {
// Because maxReplica is actually always an odd number, so directly divided by 2
witnessCount := maxReplica / 2
defaultRules = append(defaultRules,
[]*Rule{
{
GroupID: "pd",
ID: "default",
Role: Voter,
Count: maxReplica - witnessCount,
LocationLabels: locationLabels,
IsolationLevel: isolationLevel,
},
{
GroupID: "pd",
ID: "witness",
Role: Voter,
Count: witnessCount,
IsWitness: true,
LocationLabels: locationLabels,
IsolationLevel: isolationLevel,
},
}...,
)
} else {
defaultRules = append(defaultRules, &Rule{
GroupID: "pd",
ID: "default",
Role: Voter,
Count: maxReplica,
LocationLabels: locationLabels,
IsolationLevel: isolationLevel,
})
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122)):pkg/schedule/placement/rule_manager.go
IsolationLevel: isolationLevel,
}
if err := m.storage.SaveRule(defaultRule.StoreKey(), defaultRule); err != nil {
return err
Expand Down
12 changes: 2 additions & 10 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,22 +925,14 @@ func (s *Server) SetReplicationConfig(cfg config.ReplicationConfig) error {
len(defaultRule.StartKey) == 0 && len(defaultRule.EndKey) == 0) {
return errors.New("cannot update MaxReplicas, LocationLabels or IsolationLevel when placement rules feature is enabled and not only default rule exists, please update rule instead")
}
<<<<<<< HEAD
if !(defaultRule.Count == int(old.MaxReplicas) && typeutil.StringsEqual(defaultRule.LocationLabels, []string(old.LocationLabels))) {
=======
if !(defaultRule.Count == int(old.MaxReplicas) && typeutil.AreStringSlicesEqual(defaultRule.LocationLabels, []string(old.LocationLabels)) && defaultRule.IsolationLevel == old.IsolationLevel) {
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122))
if !(defaultRule.Count == int(old.MaxReplicas) && typeutil.StringsEqual(defaultRule.LocationLabels, []string(old.LocationLabels)) && defaultRule.IsolationLevel == old.IsolationLevel) {
return errors.New("cannot to update replication config, the default rules do not consistent with replication config, please update rule instead")
}

return nil
}

<<<<<<< HEAD
if !(cfg.MaxReplicas == old.MaxReplicas && typeutil.StringsEqual(cfg.LocationLabels, old.LocationLabels)) {
=======
if !(cfg.MaxReplicas == old.MaxReplicas && typeutil.AreStringSlicesEqual(cfg.LocationLabels, old.LocationLabels) && cfg.IsolationLevel == old.IsolationLevel) {
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122))
if !(cfg.MaxReplicas == old.MaxReplicas && typeutil.StringsEqual(cfg.LocationLabels, old.LocationLabels) && cfg.IsolationLevel == old.IsolationLevel) {
if err := CheckInDefaultRule(); err != nil {
return err
}
Expand Down
20 changes: 0 additions & 20 deletions server/statistics/region_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/tikv/pd/server/storage/endpoint"
)

<<<<<<< HEAD:server/statistics/region_collection_test.go
func TestStatistics(t *testing.T) {
TestingT(t)
}
Expand All @@ -49,15 +48,6 @@ func (t *testRegionStatisticsSuite) SetUpTest(c *C) {

func (t *testRegionStatisticsSuite) TestRegionStatistics(c *C) {
opt := config.NewTestOptions()
=======
func TestRegionStatistics(t *testing.T) {
re := require.New(t)
store := storage.NewStorageWithMemoryBackend()
manager := placement.NewRuleManager(store, nil, nil)
err := manager.Initialize(3, []string{"zone", "rack", "host"}, "")
re.NoError(err)
opt := mockconfig.NewTestOptions()
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122)):pkg/statistics/region_collection_test.go
opt.SetPlacementRuleEnabled(false)
peers := []*metapb.Peer{
{Id: 5, StoreId: 1},
Expand Down Expand Up @@ -156,18 +146,8 @@ func TestRegionStatistics(t *testing.T) {
c.Assert(regionStats.stats[OfflinePeer], HasLen, 0)
}

<<<<<<< HEAD:server/statistics/region_collection_test.go
func (t *testRegionStatisticsSuite) TestRegionStatisticsWithPlacementRule(c *C) {
opt := config.NewTestOptions()
=======
func TestRegionStatisticsWithPlacementRule(t *testing.T) {
re := require.New(t)
store := storage.NewStorageWithMemoryBackend()
manager := placement.NewRuleManager(store, nil, nil)
err := manager.Initialize(3, []string{"zone", "rack", "host"}, "")
re.NoError(err)
opt := mockconfig.NewTestOptions()
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122)):pkg/statistics/region_collection_test.go
opt.SetPlacementRuleEnabled(true)
peers := []*metapb.Peer{
{Id: 5, StoreId: 1},
Expand Down
34 changes: 11 additions & 23 deletions tests/pdctl/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,10 @@ func (s *configTestSuite) TestUpdateDefaultReplicaConfig(c *C) {
checkIsolationLevel := func(expect string) {
args := []string{"-u", pdAddr, "config", "show", "replication"}
output, err := pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
replicationCfg := sc.ReplicationConfig{}
re.NoError(json.Unmarshal(output, &replicationCfg))
re.Equal(replicationCfg.IsolationLevel, expect)
c.Assert(err, IsNil)
replicationCfg := config.ReplicationConfig{}
c.Assert(json.Unmarshal(output, &replicationCfg), IsNil)
c.Assert(replicationCfg.IsolationLevel, Equals, expect)
}

checkRuleCount := func(expect int) {
Expand All @@ -676,10 +676,10 @@ func (s *configTestSuite) TestUpdateDefaultReplicaConfig(c *C) {
checkRuleIsolationLevel := func(expect string) {
args := []string{"-u", pdAddr, "config", "placement-rules", "show", "--group", "pd", "--id", "default"}
output, err := pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
c.Assert(err, IsNil)
rule := placement.Rule{}
re.NoError(json.Unmarshal(output, &rule))
re.Equal(rule.IsolationLevel, expect)
c.Assert(json.Unmarshal(output, &rule), IsNil)
c.Assert(rule.IsolationLevel, Equals, expect)
}

// update successfully when placement rules is not enabled.
Expand All @@ -688,18 +688,12 @@ func (s *configTestSuite) TestUpdateDefaultReplicaConfig(c *C) {
c.Assert(strings.Contains(string(output), "Success!"), IsTrue)
checkMaxReplicas(2)
output, err = pdctl.ExecuteCommand(cmd, "-u", pdAddr, "config", "set", "location-labels", "zone,host")
<<<<<<< HEAD
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "Success!"), IsTrue)
checkLocaltionLabels(2)
=======
re.NoError(err)
re.Contains(string(output), "Success!")
output, err = pdctl.ExecuteCommand(cmd, "-u", pdAddr, "config", "set", "isolation-level", "zone")
re.NoError(err)
re.Contains(string(output), "Success!")
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "Success!"), IsTrue)
checkLocationLabels(2)
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122))
checkRuleLocationLabels(2)
checkIsolationLevel("zone")
checkRuleIsolationLevel("zone")
Expand All @@ -718,18 +712,12 @@ func (s *configTestSuite) TestUpdateDefaultReplicaConfig(c *C) {
// We need to change isolation first because we will validate
// if the location label contains the isolation level when setting location labels.
output, err = pdctl.ExecuteCommand(cmd, "-u", pdAddr, "config", "set", "isolation-level", "host")
re.NoError(err)
re.Contains(string(output), "Success!")
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "Success!"), IsTrue)
output, err = pdctl.ExecuteCommand(cmd, "-u", pdAddr, "config", "set", "location-labels", "host")
<<<<<<< HEAD
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "Success!"), IsTrue)
checkLocaltionLabels(1)
=======
re.NoError(err)
re.Contains(string(output), "Success!")
checkLocationLabels(1)
>>>>>>> 5b3d0172b (*: fix sync isolation level to default placement rule (#7122))
checkRuleLocationLabels(1)
checkIsolationLevel("host")
checkRuleIsolationLevel("host")
Expand Down

0 comments on commit 444a4db

Please sign in to comment.