Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: scale-out topology cannot inherit the global configuration #1701

Merged
merged 7 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cluster/manager/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (m *Manager) CheckCluster(clusterOrTopoName, scaleoutTopo string, opt Check
topo.MonitoredOptions = currTopo.MonitoredOptions
topo.ServerConfigs = currTopo.ServerConfigs

if err := spec.ParseTopologyYaml(scaleoutTopo, &topo); err != nil {
if err := spec.ParseTopologyYaml(scaleoutTopo, &topo, true); err != nil {
return err
}
spec.ExpandRelativeDir(&topo)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/manager/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (m *Manager) ScaleOut(
// The no tispark master error is ignored, as if the tispark master is removed from the topology
// file for some reason (manual edit, for example), it is still possible to scale-out it to make
// the whole topology back to normal state.
if err := spec.ParseTopologyYaml(topoFile, newPart); err != nil &&
if err := spec.ParseTopologyYaml(topoFile, newPart, true); err != nil &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}
Expand Down
20 changes: 19 additions & 1 deletion pkg/cluster/spec/parse_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ To generate a sample topology file:
}

// ParseTopologyYaml read yaml content from `file` and unmarshal it to `out`
func ParseTopologyYaml(file string, out Topology) error {
// ignoreGlobal ignore global variables in file, only ignoreGlobal with a index of 0 is effective
func ParseTopologyYaml(file string, out Topology, ignoreGlobal ...bool) error {
suggestionProps := map[string]string{
"File": file,
}
Expand All @@ -68,6 +69,23 @@ func ParseTopologyYaml(file string, out Topology) error {
return err
}

// keep the global config in out
if len(ignoreGlobal) > 0 && ignoreGlobal[0] {
var newTopo map[string]interface{}
if err := yaml.Unmarshal(yamlFile, &newTopo); err != nil {
return err
}
for k := range newTopo {
switch k {
case "global",
"monitored",
"server_configs":
delete(newTopo, k)
}
}
yamlFile, _ = yaml.Marshal(newTopo)
}

if err = yaml.UnmarshalStrict(yamlFile, out); err != nil {
return ErrTopologyParseFailed.
Wrap(err, "Failed to parse topology file %s", file).
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/spec/parse_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func (s *topoSuite) TestParseTopologyYaml(c *check.C) {
c.Assert(err, check.IsNil)
}

func (s *topoSuite) TestParseTopologyYamlIgnoreGlobal(c *check.C) {
file := filepath.Join("testdata", "topology_err.yaml")
topo := Specification{}
err := ParseTopologyYaml(file, &topo, true)
if topo.GlobalOptions.DeployDir == "/tidb/deploy" {
c.Error("Can not ignore global variables")
}
c.Assert(err, check.IsNil)
}

func (s *topoSuite) TestRelativePath(c *check.C) {
// test relative path
withTempFile(`
Expand Down