diff --git a/components/playground/main.go b/components/playground/main.go index 87c31812b1..c921e3ca5f 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -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 { @@ -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{ @@ -88,7 +89,7 @@ func execute() error { Num: 1, }, tiflash: instance.Config{ - Num: 1, + Num: -1, UpTimeout: 120, }, host: "127.0.0.1", @@ -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(), @@ -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") diff --git a/components/playground/playground.go b/components/playground/playground.go index 81371cc1c4..18fc532529 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -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) }