Skip to content

Commit

Permalink
playgroud: support kv-only mode to start TiKV cluster only (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
iosmanthus authored Apr 28, 2021
1 parent f663f41 commit 334c38a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 7 additions & 4 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type bootOptions struct {
drainer instance.Config
host string
monitor bool
kvOnly bool
}

func installIfMissing(profile *localdata.Profile, component, version string) error {
Expand All @@ -78,7 +79,7 @@ func installIfMissing(profile *localdata.Profile, component, version string) err
func execute() error {
opt := &bootOptions{
tidb: instance.Config{
Num: 1,
Num: -1,
UpTimeout: 60,
},
tikv: instance.Config{
Expand All @@ -88,7 +89,7 @@ func execute() error {
Num: 1,
},
tiflash: instance.Config{
Num: 1,
Num: -1,
UpTimeout: 120,
},
host: "127.0.0.1",
Expand All @@ -105,8 +106,9 @@ Examples:
$ tiup playground nightly # Start a TiDB nightly version local cluster
$ tiup playground v3.0.10 --db 3 --pd 3 --kv 3 # Start a local cluster with 10 nodes
$ tiup playground nightly --monitor=false # Start a local cluster and disable monitor system
$ tiup playground --pd.config ~/config/pd.toml # Start a local cluster with specified configuration file,
$ tiup playground --db.binpath /xx/tidb-server # Start a local cluster with component binary path`,
$ tiup playground --pd.config ~/config/pd.toml # Start a local cluster with specified configuration file
$ tiup playground --db.binpath /xx/tidb-server # Start a local cluster with component binary path
$ tiup playground --kv-mode --pd 3 --kv 3 # Start a local cluster in KV mode (No TiDB Available)`,
SilenceUsage: true,
SilenceErrors: true,
Version: version.NewTiUPVersion().String(),
Expand Down Expand Up @@ -212,6 +214,7 @@ Examples:
rootCmd.Flags().StringVarP(&opt.tidb.Host, "db.host", "", opt.tidb.Host, "Playground TiDB host. If not provided, TiDB will still use `host` flag as its host")
rootCmd.Flags().StringVarP(&opt.pd.Host, "pd.host", "", opt.pd.Host, "Playground PD host. If not provided, PD will still use `host` flag as its host")
rootCmd.Flags().BoolVar(&opt.monitor, "monitor", opt.monitor, "Start prometheus and grafana component")
rootCmd.Flags().BoolVar(&opt.kvOnly, "kv-only", opt.kvOnly, "If start a TiKV cluster only")

rootCmd.Flags().StringVarP(&opt.tidb.ConfigPath, "db.config", "", opt.tidb.ConfigPath, "TiDB instance configuration file")
rootCmd.Flags().StringVarP(&opt.tikv.ConfigPath, "kv.config", "", opt.tikv.ConfigPath, "TiKV instance configuration file")
Expand Down
15 changes: 15 additions & 0 deletions components/playground/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,21 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme

p.bootOptions = options

// If the startup mode is not kv-only mode, set the default count of TiDB instances to 1.
switch {
case options.kvOnly:
if options.tidb.Num > 0 || options.tiflash.Num > 0 || options.pump.Num > 0 || options.drainer.Num > 0 {
return fmt.Errorf("in kv-only mode, TiDB related component are not allowed")
}
options.tidb.Num = 0
options.tiflash.Num = 0
case options.tidb.Num < 0:
options.tidb.Num = 1
fallthrough
case options.tiflash.Num < 0:
options.tiflash.Num = 1
}

if options.pd.Num < 1 || options.tikv.Num < 1 {
return fmt.Errorf("all components count must be great than 0 (tikv=%v, pd=%v)", options.tikv.Num, options.pd.Num)
}
Expand Down

0 comments on commit 334c38a

Please sign in to comment.