Skip to content

Commit

Permalink
Merge branch 'master' into fix-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Apr 2, 2021
2 parents ffb209c + cf55cab commit 48b3a37
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 42 deletions.
2 changes: 1 addition & 1 deletion components/cluster/command/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newPatchCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode)
return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func newReloadCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return cm.Reload(clusterName, gOpt, skipRestart)
return cm.Reload(clusterName, gOpt, skipRestart, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newRenameCmd() *cobra.Command {
newClusterName := args[1]
teleCommand = append(teleCommand, scrubClusterName(oldClusterName))

return cm.Rename(oldClusterName, gOpt, newClusterName)
return cm.Rename(oldClusterName, gOpt, newClusterName, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newRestartCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return cm.RestartCluster(clusterName, gOpt)
return cm.RestartCluster(clusterName, gOpt, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newStopCmd() *cobra.Command {
clusterName := args[0]
teleCommand = append(teleCommand, scrubClusterName(clusterName))

return cm.StopCluster(clusterName, gOpt)
return cm.StopCluster(clusterName, gOpt, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/dm/command/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func newPatchCmd() *cobra.Command {

clusterName := args[0]

return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode)
return cm.Patch(clusterName, args[1], gOpt, overwrite, offlineMode, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/dm/command/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newReloadCmd() *cobra.Command {

clusterName := args[0]

return cm.Reload(clusterName, gOpt, skipRestart)
return cm.Reload(clusterName, gOpt, skipRestart, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/dm/command/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newRestartCmd() *cobra.Command {

clusterName := args[0]

return cm.RestartCluster(clusterName, gOpt)
return cm.RestartCluster(clusterName, gOpt, skipConfirm)
},
}

Expand Down
2 changes: 1 addition & 1 deletion components/dm/command/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newStopCmd() *cobra.Command {

clusterName := args[0]

return cm.StopCluster(clusterName, gOpt)
return cm.StopCluster(clusterName, gOpt, skipConfirm)
},
}

Expand Down
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
2 changes: 2 additions & 0 deletions embed/templates/scripts/run_tikv.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ echo $stat
{{- end}}
{{- end}}

export MALLOC_CONF="prof:true,prof_active:true,prof.active:false"

{{- if .NumaNode}}
exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} bin/tikv-server \
{{- else}}
Expand Down
32 changes: 30 additions & 2 deletions pkg/cluster/manager/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ package manager
import (
"context"
"errors"
"fmt"
"strings"

"github.com/fatih/color"
"github.com/joomcode/errorx"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/ctxt"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
"github.com/pingcap/tiup/pkg/cluster/spec"
Expand Down Expand Up @@ -115,7 +119,7 @@ func (m *Manager) StartCluster(name string, options operator.Options, fn ...func
}

// StopCluster stop the cluster.
func (m *Manager) StopCluster(name string, options operator.Options) error {
func (m *Manager) StopCluster(name string, options operator.Options, skipConfirm bool) error {
metadata, err := m.meta(name)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
return err
Expand All @@ -129,6 +133,18 @@ func (m *Manager) StopCluster(name string, options operator.Options) error {
return err
}

if !skipConfirm {
if err := cliutil.PromptForConfirmOrAbortError(
fmt.Sprintf("Will stop the cluster %s with nodes: %s, roles: %s.\nDo you want to continue? [y/N]:",
color.HiYellowString(name),
color.HiRedString(strings.Join(options.Nodes, ",")),
color.HiRedString(strings.Join(options.Roles, ",")),
),
); err != nil {
return err
}
}

t := m.sshTaskBuilder(name, topo, base.User, options).
Func("StopCluster", func(ctx context.Context) error {
return operator.Stop(ctx, topo, options, tlsCfg)
Expand All @@ -148,7 +164,7 @@ func (m *Manager) StopCluster(name string, options operator.Options) error {
}

// RestartCluster restart the cluster.
func (m *Manager) RestartCluster(name string, options operator.Options) error {
func (m *Manager) RestartCluster(name string, options operator.Options, skipConfirm bool) error {
metadata, err := m.meta(name)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
return err
Expand All @@ -162,6 +178,18 @@ func (m *Manager) RestartCluster(name string, options operator.Options) error {
return err
}

if !skipConfirm {
if err := cliutil.PromptForConfirmOrAbortError(
fmt.Sprintf("Will restart the cluster %s with nodes: %s roles: %s.\nDo you want to continue? [y/N]:",
color.HiYellowString(name),
color.HiYellowString(strings.Join(options.Nodes, ",")),
color.HiYellowString(strings.Join(options.Roles, ",")),
),
); err != nil {
return err
}
}

t := m.sshTaskBuilder(name, topo, base.User, options).
Func("RestartCluster", func(ctx context.Context) error {
return operator.Restart(ctx, topo, options, tlsCfg)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/manager/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func buildScaleOutTask(
return m.specManager.SaveMeta(name, metadata)
}).
Func("StartCluster", func(ctx context.Context) error {
return operator.Start(ctx, newPart, operator.Options{OptTimeout: gOpt.OptTimeout}, tlsCfg)
return operator.Start(ctx, newPart, operator.Options{OptTimeout: gOpt.OptTimeout, Operation: operator.ScaleOutOperation}, tlsCfg)
}).
Parallel(false, refreshConfigTasks...).
Parallel(false, buildReloadPromTasks(metadata.GetTopology())...)
Expand Down
18 changes: 17 additions & 1 deletion pkg/cluster/manager/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import (
"os"
"os/exec"
"path"
"strings"

"github.com/fatih/color"
"github.com/joomcode/errorx"
"github.com/pingcap/errors"
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/ctxt"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
Expand All @@ -33,7 +36,7 @@ import (
)

// Patch the cluster.
func (m *Manager) Patch(name string, packagePath string, opt operator.Options, overwrite, offline bool) error {
func (m *Manager) Patch(name string, packagePath string, opt operator.Options, overwrite, offline, skipConfirm bool) error {
if err := clusterutil.ValidateClusterNameOrError(name); err != nil {
return err
}
Expand All @@ -50,6 +53,19 @@ func (m *Manager) Patch(name string, packagePath string, opt operator.Options, o
return perrs.New("specified package not exists")
}

if !skipConfirm {
if err := cliutil.PromptForConfirmOrAbortError(
fmt.Sprintf("Will patch the cluster %s with package path is %s, nodes: %s, roles: %s.\nDo you want to continue? [y/N]:",
color.HiYellowString(name),
color.HiYellowString(packagePath),
color.HiRedString(strings.Join(opt.Nodes, ",")),
color.HiRedString(strings.Join(opt.Roles, ",")),
),
); err != nil {
return err
}
}

insts, err := instancesToPatch(topo, opt)
if err != nil {
return err
Expand Down
19 changes: 18 additions & 1 deletion pkg/cluster/manager/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ package manager

import (
"context"
"fmt"
"strings"

"github.com/fatih/color"
"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/ctxt"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
Expand All @@ -26,7 +30,7 @@ import (
)

// Reload the cluster.
func (m *Manager) Reload(name string, opt operator.Options, skipRestart bool) error {
func (m *Manager) Reload(name string, opt operator.Options, skipRestart, skipConfirm bool) error {
if err := clusterutil.ValidateClusterNameOrError(name); err != nil {
return err
}
Expand All @@ -38,6 +42,19 @@ func (m *Manager) Reload(name string, opt operator.Options, skipRestart bool) er
return err
}

if !skipConfirm {
if err := cliutil.PromptForConfirmOrAbortError(
fmt.Sprintf("Will reload the cluster %s with restart policy is %s, nodes: %s, roles: %s.\nDo you want to continue? [y/N]:",
color.HiYellowString(name),
color.HiRedString(fmt.Sprintf("%v", !skipRestart)),
color.HiRedString(strings.Join(opt.Nodes, ",")),
color.HiRedString(strings.Join(opt.Roles, ",")),
),
); err != nil {
return err
}
}

topo := metadata.GetTopology()
base := metadata.GetBaseMeta()

Expand Down
14 changes: 12 additions & 2 deletions pkg/cluster/manager/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
package manager

import (
"fmt"
"os"

"github.com/fatih/color"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
operator "github.com/pingcap/tiup/pkg/cluster/operation"
Expand All @@ -25,7 +27,7 @@ import (
)

// Rename the cluster
func (m *Manager) Rename(name string, opt operator.Options, newName string) error {
func (m *Manager) Rename(name string, opt operator.Options, newName string, skipConfirm bool) error {
if err := clusterutil.ValidateClusterNameOrError(name); err != nil {
return err
}
Expand All @@ -44,6 +46,14 @@ func (m *Manager) Rename(name string, opt operator.Options, newName string) erro
WithProperty(cliutil.SuggestionFromFormat("Please specify another cluster name"))
}

if !skipConfirm {
if err := cliutil.PromptForConfirmOrAbortError(
fmt.Sprintf("Will rename the cluster name from %s to %s.\nDo you confirm this action? [y/N]:", color.HiYellowString(name), color.HiYellowString(newName)),
); err != nil {
return err
}
}

_, err := m.meta(name)
if err != nil { // refuse renaming if current cluster topology is not valid
return err
Expand All @@ -56,5 +66,5 @@ func (m *Manager) Rename(name string, opt operator.Options, newName string) erro
log.Infof("Rename cluster `%s` -> `%s` successfully", name, newName)

opt.Roles = []string{spec.ComponentGrafana, spec.ComponentPrometheus}
return m.Reload(newName, opt, false)
return m.Reload(newName, opt, false, skipConfirm)
}
Loading

0 comments on commit 48b3a37

Please sign in to comment.