Skip to content

Commit

Permalink
Use absolute path of DataDir/DeployDir/LogDir (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucklove authored Sep 29, 2020
1 parent da151c5 commit b4c0a9f
Show file tree
Hide file tree
Showing 20 changed files with 967 additions and 286 deletions.
6 changes: 3 additions & 3 deletions components/cluster/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/joomcode/errorx"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/executor"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/cluster/spec"
Expand Down Expand Up @@ -82,9 +81,10 @@ conflict checks with other clusters`,

topo = *metadata.Topology
} else { // check before cluster is deployed
if err := clusterutil.ParseTopologyYaml(args[0], &topo); err != nil {
if err := spec.ParseTopologyYaml(args[0], &topo); err != nil {
return err
}
spec.ExpandRelativeDir(&topo)

clusterList, err := tidbSpec.GetAllClusters()
if err != nil {
Expand Down Expand Up @@ -266,7 +266,7 @@ func checkSystemInfo(s *cliutil.SSHConnectionProps, topo *spec.Specification, op
// if the data dir set in topology is relative, and the home dir of deploy user
// and the user run the check command is on different partitions, the disk detection
// may be using incorrect partition for validations.
for _, dataDir := range clusterutil.MultiDirAbs(opt.user, inst.DataDir()) {
for _, dataDir := range spec.MultiDirAbs(opt.user, inst.DataDir()) {
// build checking tasks
t2 = t2.
CheckSys(
Expand Down
17 changes: 8 additions & 9 deletions components/dm/spec/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/meta"

"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/executor"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/cluster/template/scripts"
Expand Down Expand Up @@ -365,25 +364,25 @@ func (topo *Topology) IterHost(fn func(instance Instance)) {
// Endpoints returns the PD endpoints configurations
func (topo *Topology) Endpoints(user string) []*scripts.DMMasterScript {
var ends []*scripts.DMMasterScript
for _, spec := range topo.Masters {
deployDir := clusterutil.Abs(user, spec.DeployDir)
for _, s := range topo.Masters {
deployDir := spec.Abs(user, s.DeployDir)
// data dir would be empty for components which don't need it
dataDir := spec.DataDir
dataDir := s.DataDir
// the default data_dir is relative to deploy_dir
if dataDir != "" && !strings.HasPrefix(dataDir, "/") {
dataDir = filepath.Join(deployDir, dataDir)
}
// log dir will always be with values, but might not used by the component
logDir := clusterutil.Abs(user, spec.LogDir)
logDir := spec.Abs(user, s.LogDir)

script := scripts.NewDMMasterScript(
spec.Name,
spec.Host,
s.Name,
s.Host,
deployDir,
dataDir,
logDir).
WithPort(spec.Port).
WithPeerPort(spec.PeerPort)
WithPort(s.Port).
WithPeerPort(s.PeerPort)
ends = append(ends, script)
}
return ends
Expand Down
6 changes: 3 additions & 3 deletions components/dm/spec/topology_dm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/creasty/defaults"
"github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cluster/api"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/set"
Expand Down Expand Up @@ -479,7 +478,7 @@ func (topo *Topology) CountDir(targetHost, dirPrefix string) int {
dirStats := make(map[string]int)
count := 0
topoSpec := reflect.ValueOf(topo).Elem()
dirPrefix = clusterutil.Abs(topo.GlobalOptions.User, dirPrefix)
dirPrefix = spec.Abs(topo.GlobalOptions.User, dirPrefix)

for i := 0; i < topoSpec.NumField(); i++ {
if isSkipField(topoSpec.Field(i)) {
Expand Down Expand Up @@ -516,7 +515,7 @@ func (topo *Topology) CountDir(targetHost, dirPrefix string) int {
dir = filepath.Join(deployDir, dir)
}
}
dir = clusterutil.Abs(topo.GlobalOptions.User, dir)
dir = spec.Abs(topo.GlobalOptions.User, dir)
dirStats[host+dir]++
}
}
Expand Down Expand Up @@ -682,6 +681,7 @@ func setDMCustomDefaults(globalOptions *GlobalOptions, field reflect.Value) erro
)))
continue
}

// If the data dir in global options is empty or a relative path, keep it be relative
// Our run_*.sh start scripts are run inside deploy_path, so the final location
// will be deploy_path/global.data_dir
Expand Down
Loading

0 comments on commit b4c0a9f

Please sign in to comment.