diff --git a/pkg/cluster/spec/validate.go b/pkg/cluster/spec/validate.go index c2b2cf0339..2f423df854 100644 --- a/pkg/cluster/spec/validate.go +++ b/pkg/cluster/spec/validate.go @@ -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 @@ -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)) } } } diff --git a/pkg/cluster/spec/validate_test.go b/pkg/cluster/spec/validate_test.go index 97aca02d9a..717d0a5ef9 100644 --- a/pkg/cluster/spec/validate_test.go +++ b/pkg/cluster/spec/validate_test.go @@ -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") @@ -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"