Skip to content

Commit

Permalink
Merge branch 'master' into fix/regen-ignore-check
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Apr 3, 2021
2 parents faf241f + 9049356 commit 049098b
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 43 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
34 changes: 33 additions & 1 deletion pkg/cluster/api/pdapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import (
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/utils"
"golang.org/x/mod/semver"
)

// PDClient is an HTTP client of the PD server
type PDClient struct {
version string
addrs []string
tlsEnabled bool
httpClient *utils.HTTPClient
Expand All @@ -46,11 +48,30 @@ func NewPDClient(addrs []string, timeout time.Duration, tlsConfig *tls.Config) *
enableTLS = true
}

return &PDClient{
cli := &PDClient{
addrs: addrs,
tlsEnabled: enableTLS,
httpClient: utils.NewHTTPClient(timeout, tlsConfig),
}

cli.tryIdentifyVersion()
return cli
}

func (pc *PDClient) tryIdentifyVersion() {
endpoints := pc.getEndpoints(pdVersionURI)
response := map[string]string{}
_, err := tryURLs(endpoints, func(endpoint string) ([]byte, error) {
body, err := pc.httpClient.Get(endpoint)
if err != nil {
return body, err
}

return body, json.Unmarshal(body, &response)
})
if err == nil {
pc.version = response["version"]
}
}

// GetURL builds the the client URL of PDClient
Expand All @@ -70,6 +91,7 @@ const (
// nolint (some is unused now)
var (
pdPingURI = "pd/ping"
pdVersionURI = "pd/api/v1/version"
pdConfigURI = "pd/api/v1/config"
pdClusterIDURI = "pd/api/v1/cluster"
pdConfigReplicate = "pd/api/v1/config/replicate"
Expand Down Expand Up @@ -735,6 +757,11 @@ func (pc *PDClient) CheckRegion(state string) (*RegionsInfo, error) {
// SetReplicationConfig sets a config key value of PD replication, it has the
// same effect as `pd-ctl config set key value`
func (pc *PDClient) SetReplicationConfig(key string, value int) error {
// Only support for pd version >= v4.0.0
if pc.version == "" || semver.Compare(pc.version, "v4.0.0") < 0 {
return nil
}

data := map[string]interface{}{"set": map[string]interface{}{key: value}}
body, err := json.Marshal(data)
if err != nil {
Expand All @@ -747,6 +774,11 @@ func (pc *PDClient) SetReplicationConfig(key string, value int) error {
// SetAllStoreLimits sets store for all stores and types, it has the same effect
// as `pd-ctl store limit all value`
func (pc *PDClient) SetAllStoreLimits(value int) error {
// Only support for pd version >= v4.0.0
if pc.version == "" || semver.Compare(pc.version, "v4.0.0") < 0 {
return nil
}

data := map[string]interface{}{"rate": value}
body, err := json.Marshal(data)
if err != nil {
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
Loading

0 comments on commit 049098b

Please sign in to comment.