Skip to content

Commit

Permalink
do same change for playground
Browse files Browse the repository at this point in the history
Signed-off-by: qupeng <qupeng@pingcap.com>
  • Loading branch information
hicqu committed Apr 1, 2021
1 parent d65016d commit c8f2b81
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
34 changes: 23 additions & 11 deletions components/playground/instance/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instance

import (
"context"
"fmt"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -84,8 +85,8 @@ func (p *process) Cmd() *exec.Cmd {
return p.cmd
}

// NewComponentProcess create a Process instance.
func NewComponentProcess(ctx context.Context, dir, binPath, component string, version utils.Version, arg ...string) (Process, error) {
// NewComponentProcessWithEnvs create a Process instance with given environment variables.
func NewComponentProcessWithEnvs(ctx context.Context, dir, binPath, component string, version utils.Version, envs map[string]string, arg ...string) (Process, error) {
if dir == "" {
panic("dir must be set")
}
Expand All @@ -95,20 +96,31 @@ func NewComponentProcess(ctx context.Context, dir, binPath, component string, ve

env := environment.GlobalEnv()
params := &tiupexec.PrepareCommandParams{
Ctx: ctx,
Component: component,
Version: version,
BinPath: binPath,
InstanceDir: dir,
WD: dir,
Args: arg,
SysProcAttr: SysProcAttr,
Env: env,
Ctx: ctx,
Component: component,
Version: version,
BinPath: binPath,
InstanceDir: dir,
WD: dir,
Args: arg,
EnvVariables: make([]string, 0),
SysProcAttr: SysProcAttr,
Env: env,
}
for k, v := range envs {
pair := fmt.Sprintf("%s=%s", k, v)
params.EnvVariables = append(params.EnvVariables, pair)
}

cmd, err := tiupexec.PrepareCommand(params)
if err != nil {
return nil, err
}

return &process{cmd: cmd}, nil
}

// NewComponentProcess create a Process instance.
func NewComponentProcess(ctx context.Context, dir, binPath, component string, version utils.Version, arg ...string) (Process, error) {
return NewComponentProcessWithEnvs(ctx, dir, binPath, component, version, nil, arg...)
}
4 changes: 3 additions & 1 deletion components/playground/instance/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (inst *TiKVInstance) Start(ctx context.Context, version utils.Version) erro
}

var err error
if inst.Process, err = NewComponentProcess(ctx, inst.Dir, inst.BinPath, "tikv", version, args...); err != nil {
envs := make(map[string]string)
envs["MALLOC_CONF"] = "prof:true,prof_active:true,prof.active:false"
if inst.Process, err = NewComponentProcessWithEnvs(ctx, inst.Dir, inst.BinPath, "tikv", version, envs, args...); err != nil {
return err
}
logIfErr(inst.Process.SetOutputFile(inst.LogFile()))
Expand Down
24 changes: 13 additions & 11 deletions pkg/exec/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,18 @@ func base62Tag() string {

// PrepareCommandParams for PrepareCommand.
type PrepareCommandParams struct {
Ctx context.Context
Component string
Version utils.Version
BinPath string
Tag string
InstanceDir string
WD string
Args []string
SysProcAttr *syscall.SysProcAttr
Env *environment.Environment
CheckUpdate bool
Ctx context.Context
Component string
Version utils.Version
BinPath string
Tag string
InstanceDir string
WD string
Args []string
EnvVariables []string
SysProcAttr *syscall.SysProcAttr
Env *environment.Environment
CheckUpdate bool
}

// PrepareCommand will download necessary component and returns a *exec.Cmd
Expand Down Expand Up @@ -222,6 +223,7 @@ func PrepareCommand(p *PrepareCommandParams) (*exec.Cmd, error) {
fmt.Sprintf("%s=%s", localdata.EnvTag, p.Tag),
}
envs = append(envs, os.Environ()...)
envs = append(envs, p.EnvVariables...)

// init the command
c := exec.CommandContext(p.Ctx, binPath, p.Args...)
Expand Down

0 comments on commit c8f2b81

Please sign in to comment.