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

playground: fix panic if failed to start tiflash #543

Merged
merged 5 commits into from
Jun 30, 2020
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: 2 additions & 0 deletions components/playground/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ type Instance interface {
LogFile() string
// Uptime show uptime.
Uptime() string
// StatusAddrs return the address to pull metrics.
StatusAddrs() []string
// Wait Should only call this if the instance is started successfully.
Wait() error
}

Expand Down
40 changes: 18 additions & 22 deletions components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,26 @@ func (p *Playground) sanitizeComponentConfig(cid string, cfg *instance.Config) {
func (p *Playground) startInstance(ctx context.Context, inst instance.Instance) error {
fmt.Printf("Start %s instance...\n", inst.Component())
err := inst.Start(context.Background(), v0manifest.Version(p.bootOptions.version))
p.addWaitInstance(inst)
return errors.AddStack(err)
}

func (p *Playground) addWaitInstance(inst instance.Instance) {
p.instanceWaiter.Go(func() error {
err := inst.Wait()
if err != nil {
fmt.Print(color.RedString("%s quit: %s\n", inst.Component(), err.Error()))
if lines, _ := utils.TailN(inst.LogFile(), 10); len(lines) > 0 {
for _, line := range lines {
fmt.Println(line)
}
fmt.Print(color.YellowString("...\ncheck detail log from: %s\n", inst.LogFile()))
}
}
return err
})
}

func (p *Playground) handleScaleOut(w io.Writer, cmd *Command) error {
// Ignore Config.Num, alway one command as scale out one instance.
p.sanitizeComponentConfig(cmd.ComponentID, &cmd.Config)
Expand All @@ -398,10 +415,6 @@ func (p *Playground) handleScaleOut(w io.Writer, cmd *Command) error {
return errors.AddStack(err)
}

p.instanceWaiter.Go(func() error {
return inst.Wait()
})

logIfErr(p.renderSDFile())

return nil
Expand Down Expand Up @@ -810,7 +823,7 @@ func (p *Playground) bootCluster(options *bootOptions) error {

if lastErr == nil {
for _, flash := range p.tiflashs {
if err := flash.Start(ctx, v0manifest.Version(options.version)); err != nil {
if err := p.startInstance(ctx, flash); err != nil {
lastErr = err
break
}
Expand Down Expand Up @@ -922,23 +935,6 @@ func (p *Playground) bootCluster(options *bootOptions) error {
}
}()

_ = p.WalkInstances(func(_ string, inst instance.Instance) error {
p.instanceWaiter.Go(func() error {
err := inst.Wait()
if err != nil {
fmt.Print(color.RedString("%s quit: \n", inst.Component()))
if lines, _ := utils.TailN(inst.LogFile(), 10); len(lines) > 0 {
for _, line := range lines {
fmt.Println(line)
}
fmt.Print(color.YellowString("...\ncheck detail log from: %s\n", inst.LogFile()))
}
}
return err
})
return nil
})

logIfErr(p.renderSDFile())

if grafana != nil {
Expand Down