Skip to content

Commit

Permalink
use NewPart
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 committed Aug 13, 2024
1 parent 3e3a227 commit 1decd01
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
6 changes: 0 additions & 6 deletions pkg/cluster/manager/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ func (m *Manager) ScaleOut(
}
}
}

// newPart needs ComponentVersions but the original ComponentVersions is not passed to newPart.
// Copy the merged ComponentVersions to newPart.
if newSpec, ok := newPart.(*spec.Specification); ok {
newSpec.ComponentVersions = topo.ComponentVersions
}
}

if err := checkConflict(m, name, mergedTopo); err != nil {
Expand Down
31 changes: 31 additions & 0 deletions pkg/cluster/spec/parse_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,37 @@ tiflash_servers:
})
}

func (s *topoSuite) TestMergeComponentVersions(c *check.C) {
// test component version overwrite
with2TempFile(`
component_versions:
tidb: v8.0.0
tikv: v8.0.0
tidb_servers:
- host: 172.16.5.139
`, `
component_versions:
tikv: v8.1.0
pd: v8.0.0
tidb_servers:
- host: 172.16.5.134
`, func(base, scale string) {
baseTopo := Specification{}
c.Assert(ParseTopologyYaml(base, &baseTopo), check.IsNil)

scaleTopo := baseTopo.NewPart()
c.Assert(ParseTopologyYaml(scale, scaleTopo), check.IsNil)

mergedTopo := baseTopo.MergeTopo(scaleTopo)
c.Assert(mergedTopo.Validate(), check.IsNil)

c.Assert(scaleTopo.(*Specification).ComponentVersions, check.Equals, mergedTopo.(*Specification).ComponentVersions)
c.Assert(scaleTopo.(*Specification).ComponentVersions.TiDB, check.Equals, "v8.0.0")
c.Assert(scaleTopo.(*Specification).ComponentVersions.TiKV, check.Equals, "v8.1.0")
c.Assert(scaleTopo.(*Specification).ComponentVersions.PD, check.Equals, "v8.0.0")
})
}

func (s *topoSuite) TestFixRelativePath(c *check.C) {
// base test
topo := Specification{
Expand Down
7 changes: 4 additions & 3 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ type UpgradableMetadata interface {
// NewPart implements ScaleOutTopology interface.
func (s *Specification) NewPart() Topology {
return &Specification{
GlobalOptions: s.GlobalOptions,
MonitoredOptions: s.MonitoredOptions,
ServerConfigs: s.ServerConfigs,
GlobalOptions: s.GlobalOptions,
MonitoredOptions: s.MonitoredOptions,
ServerConfigs: s.ServerConfigs,
ComponentVersions: s.ComponentVersions,
}
}

Expand Down

0 comments on commit 1decd01

Please sign in to comment.