From 26ad829b0cfdd04c1b6154b37b45458c42ff3891 Mon Sep 17 00:00:00 2001 From: iosmanthus Date: Thu, 22 Apr 2021 18:21:29 +0800 Subject: [PATCH 1/3] support kv-only mode --- components/playground/main.go | 9 ++++++--- components/playground/playground.go | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/components/playground/main.go b/components/playground/main.go index 87c31812b1..e78ed84806 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{ @@ -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 3071df7af7..85b21a8f1e 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -666,6 +666,16 @@ 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. + if 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 + } else if options.tidb.Num < 0 { + options.tidb.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) } From 6db7292fb7df82bd50a679480c0fbaa522799e4d Mon Sep 17 00:00:00 2001 From: iosmanthus Date: Tue, 27 Apr 2021 17:27:58 +0800 Subject: [PATCH 2/3] rewrite the check as case statement Signed-off-by: iosmanthus --- components/playground/main.go | 2 +- components/playground/playground.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/playground/main.go b/components/playground/main.go index e78ed84806..c921e3ca5f 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -89,7 +89,7 @@ func execute() error { Num: 1, }, tiflash: instance.Config{ - Num: 1, + Num: -1, UpTimeout: 120, }, host: "127.0.0.1", diff --git a/components/playground/playground.go b/components/playground/playground.go index 85b21a8f1e..17913c2090 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -667,13 +667,17 @@ 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. - if options.kvOnly { + 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 - } else if options.tidb.Num < 0 { + options.tiflash.Num = 0 + case options.tidb.Num < 0: options.tidb.Num = 1 + case options.tiflash.Num < 0: + options.tiflash.Num = 1 } if options.pd.Num < 1 || options.tikv.Num < 1 { From a6fcda67aace07aff12f7ba942704a2c1dbf1e98 Mon Sep 17 00:00:00 2001 From: iosmanthus Date: Tue, 27 Apr 2021 21:57:36 +0800 Subject: [PATCH 3/3] add fallthrough while checking the number of TiDB Signed-off-by: iosmanthus --- Dockerfile | 4 ++++ components/playground/playground.go | 1 + 2 files changed, 5 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..8ed46f1438 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM golang:latest +COPY ./ /src/ +WORKDIR /src +RUN make \ No newline at end of file diff --git a/components/playground/playground.go b/components/playground/playground.go index 17913c2090..1fe8bbe874 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -676,6 +676,7 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme options.tiflash.Num = 0 case options.tidb.Num < 0: options.tidb.Num = 1 + fallthrough case options.tiflash.Num < 0: options.tiflash.Num = 1 }