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

Dump dns & port file at data dir #749

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 11 additions & 6 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@ Examples:
opt.version = args[0]
}

dataDir := os.Getenv(localdata.EnvNameInstanceDataDir)
if dataDir == "" {
return errors.Errorf("cannot read environment variable %s", localdata.EnvNameInstanceDataDir)
}

port, err := utils.GetFreePort("0.0.0.0", 9527)
if err != nil {
return errors.AddStack(err)
}
err = dumpPort(port)
p := NewPlayground(port)
err = dumpPort(filepath.Join(dataDir, "port"), port)
p := NewPlayground(dataDir, port)
if err != nil {
return errors.AddStack(err)
}
Expand Down Expand Up @@ -321,8 +326,8 @@ func getAbsolutePath(path string) (string, error) {
return absPath, nil
}

func dumpPort(port int) error {
return ioutil.WriteFile("port", []byte(strconv.Itoa(port)), 0644)
func dumpPort(fname string, port int) error {
return ioutil.WriteFile(fname, []byte(strconv.Itoa(port)), 0644)
}

func loadPort(dir string) (port int, err error) {
Expand All @@ -335,12 +340,12 @@ func loadPort(dir string) (port int, err error) {
return
}

func dumpDSN(dbs []*instance.TiDBInstance) {
func dumpDSN(fname string, dbs []*instance.TiDBInstance) {
var dsn []string
for _, db := range dbs {
dsn = append(dsn, fmt.Sprintf("mysql://root@%s", db.Addr()))
}
_ = ioutil.WriteFile("dsn", []byte(strings.Join(dsn, "\n")), 0644)
_ = ioutil.WriteFile(fname, []byte(strings.Join(dsn, "\n")), 0644)
}

func newEtcdClient(endpoint string) (*clientv3.Client, error) {
Expand Down
18 changes: 8 additions & 10 deletions components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/pingcap/tiup/pkg/cliutil/progress"
"github.com/pingcap/tiup/pkg/cluster/api"
"github.com/pingcap/tiup/pkg/environment"
"github.com/pingcap/tiup/pkg/localdata"
"github.com/pingcap/tiup/pkg/repository/v0manifest"
"github.com/pingcap/tiup/pkg/utils"
"golang.org/x/mod/semver"
Expand All @@ -50,7 +49,8 @@ const forceKillAfterDuration = time.Second * 10

// Playground represent the playground of a cluster.
type Playground struct {
booted bool
dataDir string
booted bool
// the latest receive signal
curSig int32
bootOptions *bootOptions
Expand Down Expand Up @@ -82,8 +82,9 @@ type MonitorInfo struct {
}

// NewPlayground create a Playground instance.
func NewPlayground(port int) *Playground {
func NewPlayground(dataDir string, port int) *Playground {
return &Playground{
dataDir: dataDir,
port: port,
idAlloc: make(map[string]int),
}
Expand Down Expand Up @@ -582,10 +583,7 @@ func (p *Playground) addInstance(componentID string, cfg instance.Config) (ins i
}
}

dataDir := os.Getenv(localdata.EnvNameInstanceDataDir)
if dataDir == "" {
return nil, fmt.Errorf("cannot read environment variable %s", localdata.EnvNameInstanceDataDir)
}
dataDir := p.dataDir

id := p.allocID(componentID)
dir := filepath.Join(dataDir, fmt.Sprintf("%s-%d", componentID, id))
Expand Down Expand Up @@ -873,7 +871,7 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme
}
}

dumpDSN(p.tidbs)
dumpDSN(filepath.Join(p.dataDir, "dsn"), p.tidbs)

go func() {
// fmt.Printf("serve at :%d\n", p.port)
Expand Down Expand Up @@ -980,7 +978,7 @@ func (p *Playground) bootMonitor(ctx context.Context, env *environment.Environme
options := p.bootOptions
monitorInfo := &MonitorInfo{}

dataDir := os.Getenv(localdata.EnvNameInstanceDataDir)
dataDir := p.dataDir
promDir := filepath.Join(dataDir, "prometheus")

monitor, err := newMonitor(ctx, options.version, options.host, promDir)
Expand Down Expand Up @@ -1021,7 +1019,7 @@ func (p *Playground) bootGrafana(ctx context.Context, env *environment.Environme
return nil, errors.AddStack(err)
}

dataDir := os.Getenv(localdata.EnvNameInstanceDataDir)
dataDir := p.dataDir
grafanaDir := filepath.Join(dataDir, "grafana")

cmd := exec.Command("cp", "-r", installPath, grafanaDir)
Expand Down
4 changes: 0 additions & 4 deletions tests/tiup-playground/test_playground.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ trap "kill_all > /dev/null 2>&1" EXIT

# wait start cluster successfully
timeout 300 grep -q "CLUSTER START SUCCESSFULLY" <(tail -f $outfile)
# playground dump this at the wd
sleep 3
mv ./dsn $TIUP_INSTANCE_DATA_DIR/
mv ./port $TIUP_INSTANCE_DATA_DIR/

tiup-playground display | grep -qv "exit"
tiup-playground scale-out --db 2
Expand Down