Skip to content

Commit

Permalink
cluster/spec: trim dataDir's space before count
Browse files Browse the repository at this point in the history
  • Loading branch information
9547 committed Nov 2, 2020
1 parent e032ead commit 55e4589
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
59 changes: 32 additions & 27 deletions pkg/cluster/spec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,11 @@ func (s *Specification) dirConflictsDetect() error {

// `yaml:"data_dir,omitempty"`
tp := strings.Split(compSpec.Type().Field(j).Tag.Get("yaml"), ",")[0]
for _, part := range strings.Split(compSpec.Field(j).String(), ",") {
for _, dir := range strings.Split(compSpec.Field(j).String(), ",") {
dir = strings.TrimSpace(dir)
item := usedDir{
host: host,
dir: part,
dir: dir,
}
// data_dir is relative to deploy_dir by default, so they can be with
// same (sub) paths as long as the deploy_dirs are different
Expand Down Expand Up @@ -688,34 +689,38 @@ func (s *Specification) CountDir(targetHost, dirPrefix string) int {
host := compSpec.FieldByName("Host").String()

for _, dirType := range dirTypes {
if j, found := findField(compSpec, dirType); found {
dir := compSpec.Field(j).String()

switch dirType { // the same as in instance.go for (*instance)
case "DeployDir":
addHostDir(host, deployDir, "")
case "DataDir":
// the default data_dir is relative to deploy_dir
if dir == "" {
addHostDir(host, deployDir, dir)
continue
}
for _, dataDir := range strings.Split(dir, ",") {
if dataDir != "" {
addHostDir(host, deployDir, dataDir)
}
}
case "LogDir":
field := compSpec.FieldByName("LogDir")
if field.IsValid() {
dir = field.Interface().(string)
}
j, found := findField(compSpec, dirType)
if !found {
continue
}

if dir == "" {
dir = "log"
}
dir := compSpec.Field(j).String()

switch dirType { // the same as in instance.go for (*instance)
case "DeployDir":
addHostDir(host, deployDir, "")
case "DataDir":
// the default data_dir is relative to deploy_dir
if dir == "" {
addHostDir(host, deployDir, dir)
continue
}
for _, dataDir := range strings.Split(dir, ",") {
dataDir = strings.TrimSpace(dataDir)
if dataDir != "" {
addHostDir(host, deployDir, dataDir)
}
}
case "LogDir":
field := compSpec.FieldByName("LogDir")
if field.IsValid() {
dir = field.Interface().(string)
}

if dir == "" {
dir = "log"
}
addHostDir(host, deployDir, strings.TrimSpace(dir))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/spec/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ global:
deploy_dir: "test-deploy"
tiflash_servers:
- host: 172.19.0.104
data_dir: "/home/tidb/birdstorm/data1,/home/tidb/birdstorm/data3"
data_dir: "/home/tidb/birdstorm/data1, /home/tidb/birdstorm/data3"
`), &topo)
c.Assert(err, IsNil)
cnt := topo.CountDir("172.19.0.104", "/home/tidb/birdstorm/data1")
Expand Down Expand Up @@ -758,7 +758,7 @@ global:
data_dir: "test-data"
tiflash_servers:
- host: 172.16.5.138
data_dir: "/test-1,/test-2"
data_dir: " /test-1, /test-2"
pd_servers:
- host: 172.16.5.138
data_dir: "/test-2"
Expand Down

0 comments on commit 55e4589

Please sign in to comment.