From 4a042efcf094b6d3bcf1714a1e5f1bf113c5ab59 Mon Sep 17 00:00:00 2001 From: pingyu Date: Tue, 26 Jul 2022 20:12:10 +0800 Subject: [PATCH 1/8] wip Signed-off-by: pingyu --- components/playground/command.go | 3 + components/playground/instance/instance.go | 1 + components/playground/instance/tikv_cdc.go | 88 ++++++++++++++++++++++ components/playground/main.go | 24 ++++++ components/playground/playground.go | 39 +++++++++- pkg/cluster/spec/instance.go | 1 + 6 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 components/playground/instance/tikv_cdc.go diff --git a/components/playground/command.go b/components/playground/command.go index 14c1362dd6..4857178f24 100644 --- a/components/playground/command.go +++ b/components/playground/command.go @@ -56,6 +56,7 @@ func buildCommands(tp CommandType, opt *BootOptions) (cmds []Command) { {"tiflash", opt.TiFlash}, {"tidb", opt.TiDB}, {"ticdc", opt.TiCDC}, + {"tikv-cdc", opt.TiKVCDC}, {"drainer", opt.Drainer}, } @@ -98,6 +99,7 @@ func newScaleOut() *cobra.Command { cmd.Flags().IntVarP(&opt.PD.Num, "pd", "", opt.PD.Num, "PD instance number") cmd.Flags().IntVarP(&opt.TiFlash.Num, "tiflash", "", opt.TiFlash.Num, "TiFlash instance number") cmd.Flags().IntVarP(&opt.TiCDC.Num, "ticdc", "", opt.TiCDC.Num, "TiCDC instance number") + cmd.Flags().IntVarP(&opt.TiKVCDC.Num, "kvcdc", "", opt.TiKVCDC.Num, "TiKV-CDC instance number") cmd.Flags().IntVarP(&opt.Pump.Num, "pump", "", opt.Pump.Num, "Pump instance number") cmd.Flags().IntVarP(&opt.Drainer.Num, "drainer", "", opt.Pump.Num, "Drainer instance number") @@ -116,6 +118,7 @@ func newScaleOut() *cobra.Command { cmd.Flags().StringVarP(&opt.PD.BinPath, "pd.binpath", "", opt.PD.BinPath, "PD instance binary path") cmd.Flags().StringVarP(&opt.TiFlash.BinPath, "tiflash.binpath", "", opt.TiFlash.BinPath, "TiFlash instance binary path") cmd.Flags().StringVarP(&opt.TiCDC.BinPath, "ticdc.binpath", "", opt.TiCDC.BinPath, "TiCDC instance binary path") + cmd.Flags().StringVarP(&opt.TiKVCDC.BinPath, "kvcdc.binpath", "", opt.TiKVCDC.BinPath, "TiKVCDC instance binary path") cmd.Flags().StringVarP(&opt.Pump.BinPath, "pump.binpath", "", opt.Pump.BinPath, "Pump instance binary path") cmd.Flags().StringVarP(&opt.Drainer.BinPath, "drainer.binpath", "", opt.Drainer.BinPath, "Drainer instance binary path") diff --git a/components/playground/instance/instance.go b/components/playground/instance/instance.go index aa1789bfa1..294c30326e 100644 --- a/components/playground/instance/instance.go +++ b/components/playground/instance/instance.go @@ -29,6 +29,7 @@ type Config struct { Host string `yaml:"host"` Port int `yaml:"port"` UpTimeout int `yaml:"up_timeout"` + Version string `yaml:"version"` } type instance struct { diff --git a/components/playground/instance/tikv_cdc.go b/components/playground/instance/tikv_cdc.go new file mode 100644 index 0000000000..a082339730 --- /dev/null +++ b/components/playground/instance/tikv_cdc.go @@ -0,0 +1,88 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package instance + +import ( + "context" + "fmt" + "path/filepath" + "strings" + + tiupexec "github.com/pingcap/tiup/pkg/exec" + "github.com/pingcap/tiup/pkg/utils" +) + +// TiKVCDC represent a TiKV-CDC instance. +type TiKVCDC struct { + instance + version utils.Version + pds []*PDInstance + Process +} + +var _ Instance = &TiKVCDC{} + +// NewTiKVCDC create a TiKVCDC instance. +func NewTiKVCDC(version utils.Version, binPath string, dir, host, configPath string, id int, pds []*PDInstance) *TiKVCDC { + tikvCdc := &TiKVCDC{ + instance: instance{ + BinPath: binPath, + ID: id, + Dir: dir, + Host: host, + Port: utils.MustGetFreePort(host, 8800), + ConfigPath: configPath, + }, + version: version, + pds: pds, + } + tikvCdc.StatusPort = tikvCdc.Port + return tikvCdc +} + +// Start implements Instance interface. +func (c *TiKVCDC) Start(ctx context.Context, _ utils.Version) error { + endpoints := pdEndpoints(c.pds, true) + + args := []string{ + "server", + fmt.Sprintf("--addr=%s:%d", c.Host, c.Port), + fmt.Sprintf("--advertise-addr=%s:%d", AdvertiseHost(c.Host), c.Port), + fmt.Sprintf("--pd=%s", strings.Join(endpoints, ",")), + fmt.Sprintf("--log-file=%s", c.LogFile()), + } + if c.ConfigPath != "" { + args = append(args, fmt.Sprintf("--config=%s", c.ConfigPath)) + } + args = append(args, fmt.Sprintf("--data-dir=%s", filepath.Join(c.Dir, "data"))) + + var err error + if c.BinPath, err = tiupexec.PrepareBinary("tikv-cdc", c.version, c.BinPath); err != nil { + return err + } + c.Process = &process{cmd: PrepareCommand(ctx, c.BinPath, args, nil, c.Dir)} + + logIfErr(c.Process.SetOutputFile(c.LogFile())) + return c.Process.Start() +} + +// Component return component name. +func (c *TiKVCDC) Component() string { + return "tikv-cdc" +} + +// LogFile return the log file. +func (c *TiKVCDC) LogFile() string { + return filepath.Join(c.Dir, "tikv_cdc.log") +} diff --git a/components/playground/main.go b/components/playground/main.go index ed82c63cd9..3289fa1922 100644 --- a/components/playground/main.go +++ b/components/playground/main.go @@ -60,6 +60,7 @@ type BootOptions struct { TiKV instance.Config `yaml:"tikv"` TiFlash instance.Config `yaml:"tiflash"` TiCDC instance.Config `yaml:"ticdc"` + TiKVCDC instance.Config `yaml:"tikv_cdc"` Pump instance.Config `yaml:"pump"` Drainer instance.Config `yaml:"drainer"` Host string `yaml:"host"` @@ -89,6 +90,7 @@ const ( pd = "pd" tiflash = "tiflash" ticdc = "ticdc" + kvcdc = "kvcdc" pump = "pump" drainer = "drainer" @@ -109,6 +111,7 @@ const ( pdConfig = "pd.config" tiflashConfig = "tiflash.config" ticdcConfig = "ticdc.config" + kvcdcConfig = "kvcdc.config" pumpConfig = "pump.config" drainerConfig = "drainer.config" @@ -118,8 +121,12 @@ const ( pdBinpath = "pd.binpath" tiflashBinpath = "tiflash.binpath" ticdcBinpath = "ticdc.binpath" + kvcdcBinpath = "kvcdc.binpath" pumpBinpath = "pump.binpath" drainerBinpath = "drainer.binpath" + + // component version + kvcdcVersion = "kvcdc.version" ) func installIfMissing(component, version string) error { @@ -319,6 +326,7 @@ If you'd like to use a TiDB version other than %s, cancel and retry with the fol rootCmd.Flags().Int(pd, defaultOptions.PD.Num, "PD instance number") rootCmd.Flags().Int(tiflash, defaultOptions.TiFlash.Num, "TiFlash instance number") rootCmd.Flags().Int(ticdc, defaultOptions.TiCDC.Num, "TiCDC instance number") + rootCmd.Flags().Int(kvcdc, defaultOptions.TiKVCDC.Num, "TiKV-CDC instance number") rootCmd.Flags().Int(pump, defaultOptions.Pump.Num, "Pump instance number") rootCmd.Flags().Int(drainer, defaultOptions.Drainer.Num, "Drainer instance number") @@ -338,15 +346,19 @@ If you'd like to use a TiDB version other than %s, cancel and retry with the fol rootCmd.Flags().String(pumpConfig, defaultOptions.Pump.ConfigPath, "Pump instance configuration file") rootCmd.Flags().String(drainerConfig, defaultOptions.Drainer.ConfigPath, "Drainer instance configuration file") rootCmd.Flags().String(ticdcConfig, defaultOptions.TiCDC.ConfigPath, "TiCDC instance configuration file") + rootCmd.Flags().String(kvcdcConfig, defaultOptions.TiKVCDC.ConfigPath, "TiKV-CDC instance configuration file") rootCmd.Flags().String(dbBinpath, defaultOptions.TiDB.BinPath, "TiDB instance binary path") rootCmd.Flags().String(kvBinpath, defaultOptions.TiKV.BinPath, "TiKV instance binary path") rootCmd.Flags().String(pdBinpath, defaultOptions.PD.BinPath, "PD instance binary path") rootCmd.Flags().String(tiflashBinpath, defaultOptions.TiFlash.BinPath, "TiFlash instance binary path") rootCmd.Flags().String(ticdcBinpath, defaultOptions.TiCDC.BinPath, "TiCDC instance binary path") + rootCmd.Flags().String(kvcdcBinpath, defaultOptions.TiKVCDC.BinPath, "TiKV-CDC instance binary path") rootCmd.Flags().String(pumpBinpath, defaultOptions.Pump.BinPath, "Pump instance binary path") rootCmd.Flags().String(drainerBinpath, defaultOptions.Drainer.BinPath, "Drainer instance binary path") + rootCmd.Flags().String(kvcdcVersion, defaultOptions.TiKVCDC.Version, "TiKV-CDC instance version") + rootCmd.AddCommand(newDisplay()) rootCmd.AddCommand(newScaleOut()) rootCmd.AddCommand(newScaleIn()) @@ -418,6 +430,11 @@ func populateOpt(flagSet *pflag.FlagSet) (err error) { if err != nil { return } + case kvcdc: + options.TiKVCDC.Num, err = strconv.Atoi(flag.Value.String()) + if err != nil { + return + } case pump: options.Pump.Num, err = strconv.Atoi(flag.Value.String()) if err != nil { @@ -439,6 +456,8 @@ func populateOpt(flagSet *pflag.FlagSet) (err error) { options.TiFlash.ConfigPath = flag.Value.String() case ticdcConfig: options.TiCDC.ConfigPath = flag.Value.String() + case kvcdcConfig: + options.TiKVCDC.ConfigPath = flag.Value.String() case pumpConfig: options.Pump.ConfigPath = flag.Value.String() case drainerConfig: @@ -454,6 +473,8 @@ func populateOpt(flagSet *pflag.FlagSet) (err error) { options.TiFlash.BinPath = flag.Value.String() case ticdcBinpath: options.TiCDC.BinPath = flag.Value.String() + case kvcdcBinpath: + options.TiKVCDC.BinPath = flag.Value.String() case pumpBinpath: options.Pump.BinPath = flag.Value.String() case drainerBinpath: @@ -486,6 +507,9 @@ func populateOpt(flagSet *pflag.FlagSet) (err error) { if err != nil { return } + + case kvcdcVersion: + options.TiKVCDC.Version = flag.Value.String() } }) diff --git a/components/playground/playground.go b/components/playground/playground.go index 3698770456..1ad03ffd71 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -64,6 +64,7 @@ type Playground struct { tidbs []*instance.TiDBInstance tiflashs []*instance.TiFlashInstance ticdcs []*instance.TiCDC + tikv_cdcs []*instance.TiKVCDC pumps []*instance.Pump drainers []*instance.Drainer startedInstances []instance.Instance @@ -309,6 +310,12 @@ func (p *Playground) handleScaleIn(w io.Writer, pid int) error { p.ticdcs = append(p.ticdcs[:i], p.ticdcs[i+1:]...) } } + case spec.ComponentTiKVCDC: + for i := 0; i < len(p.tikv_cdcs); i++ { + if p.tikv_cdcs[i].Pid() == pid { + p.tikv_cdcs = append(p.tikv_cdcs[:i], p.tikv_cdcs[i+1:]...) + } + } case spec.ComponentTiFlash: for i := 0; i < len(p.tiflashs); i++ { if p.tiflashs[i].Pid() == pid { @@ -409,6 +416,8 @@ func (p *Playground) sanitizeComponentConfig(cid string, cfg *instance.Config) e return p.sanitizeConfig(p.bootOptions.TiFlash, cfg) case spec.ComponentCDC: return p.sanitizeConfig(p.bootOptions.TiCDC, cfg) + case spec.ComponentTiKVCDC: + return p.sanitizeConfig(p.bootOptions.TiKVCDC, cfg) case spec.ComponentPump: return p.sanitizeConfig(p.bootOptions.Pump, cfg) case spec.ComponentDrainer: @@ -419,7 +428,8 @@ func (p *Playground) sanitizeComponentConfig(cid string, cfg *instance.Config) e } func (p *Playground) startInstance(ctx context.Context, inst instance.Instance) error { - version, err := environment.GlobalEnv().V1Repository().ResolveComponentVersion(inst.Component(), p.bootOptions.Version) + versionOption := p.bindVersion(inst.Component(), p.bootOptions.Version) + version, err := environment.GlobalEnv().V1Repository().ResolveComponentVersion(inst.Component(), versionOption) if err != nil { return err } @@ -593,6 +603,13 @@ func (p *Playground) WalkInstances(fn func(componentID string, ins instance.Inst } } + for _, ins := range p.tikv_cdcs { + err := fn(spec.ComponentTiKVCDC, ins) + if err != nil { + return err + } + } + for _, ins := range p.drainers { err := fn(spec.ComponentDrainer, ins) if err != nil { @@ -670,6 +687,10 @@ func (p *Playground) addInstance(componentID string, cfg instance.Config) (ins i inst := instance.NewTiCDC(cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) ins = inst p.ticdcs = append(p.ticdcs, inst) + case spec.ComponentTiKVCDC: + inst := instance.NewTiKVCDC(utils.Version(cfg.Version), cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) + ins = inst + p.tikv_cdcs = append(p.tikv_cdcs, inst) case spec.ComponentPump: inst := instance.NewPump(cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) ins = inst @@ -765,6 +786,15 @@ func (p *Playground) waitAllTiFlashUp() { } } +func (p *Playground) bindVersion(comp string, version string) (bindVersion string) { + switch comp { + case spec.ComponentTiKVCDC: + return p.bootOptions.TiKVCDC.Version + default: + return version + } +} + func (p *Playground) bootCluster(ctx context.Context, env *environment.Environment, options *BootOptions) error { for _, cfg := range []*instance.Config{ &options.PD, @@ -773,6 +803,7 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme &options.TiFlash, &options.Pump, &options.Drainer, + &options.TiKVCDC, } { path, err := getAbsolutePath(cfg.ConfigPath) if err != nil { @@ -807,6 +838,7 @@ func (p *Playground) bootCluster(ctx context.Context, env *environment.Environme {spec.ComponentPump, options.Pump}, {spec.ComponentTiDB, options.TiDB}, {spec.ComponentCDC, options.TiCDC}, + {spec.ComponentTiKVCDC, options.TiKVCDC}, {spec.ComponentDrainer, options.Drainer}, {spec.ComponentTiFlash, options.TiFlash}, } @@ -1001,6 +1033,11 @@ func (p *Playground) terminate(sig syscall.Signal) { kill(inst.Component(), inst.Pid(), inst.Wait) } } + for _, inst := range p.tikv_cdcs { + if inst.Process != nil { + kill(inst.Component(), inst.Pid(), inst.Wait) + } + } for _, inst := range p.drainers { if inst.Process != nil { kill(inst.Component(), inst.Pid(), inst.Wait) diff --git a/pkg/cluster/spec/instance.go b/pkg/cluster/spec/instance.go index 1956e003e3..bf4505c8cc 100644 --- a/pkg/cluster/spec/instance.go +++ b/pkg/cluster/spec/instance.go @@ -44,6 +44,7 @@ const ( ComponentDrainer = "drainer" ComponentPump = "pump" ComponentCDC = "cdc" + ComponentTiKVCDC = "tikv-cdc" ComponentTiSpark = "tispark" ComponentSpark = "spark" ComponentAlertmanager = "alertmanager" From 00f906820916f9e71b475072b8083e102cf39075 Mon Sep 17 00:00:00 2001 From: pingyu Date: Wed, 27 Jul 2022 17:43:53 +0800 Subject: [PATCH 2/8] add integration test Signed-off-by: pingyu --- .github/workflows/integrate-playground.yaml | 1 + tests/tiup-playground/test_kvcdc.sh | 91 +++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100755 tests/tiup-playground/test_kvcdc.sh diff --git a/.github/workflows/integrate-playground.yaml b/.github/workflows/integrate-playground.yaml index 86c82fe0a5..1b2df6cbd4 100644 --- a/.github/workflows/integrate-playground.yaml +++ b/.github/workflows/integrate-playground.yaml @@ -39,6 +39,7 @@ jobs: matrix: cases: - "test_playground" + - "test_kvcdc" env: working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }} steps: diff --git a/tests/tiup-playground/test_kvcdc.sh b/tests/tiup-playground/test_kvcdc.sh new file mode 100755 index 0000000000..3c8a9d07a1 --- /dev/null +++ b/tests/tiup-playground/test_kvcdc.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +set -eux + +TEST_DIR=$(cd "$(dirname "$0")"; pwd) +TMP_DIR=$TEST_DIR/_tmp +VERSION="v6.2.0" +MIRROR="http://staging.tiup-server.pingcap.net" # TODO: move to release mirror after TiKV-CDC is released. + + +# Profile home directory +mkdir -p $TMP_DIR/home/bin/ +export TIUP_HOME=$TMP_DIR/home +curl $MIRROR/root.json -o $TMP_DIR/home/bin/root.json + +# Prepare data directory +rm -rf $TIUP_HOME/data +mkdir -p $TIUP_HOME/data +export TIUP_INSTANCE_DATA_DIR=$TIUP_HOME/data/test_play +mkdir -p $TIUP_INSTANCE_DATA_DIR + +mkdir -p $TEST_DIR/cover + +function tiup-playground() { + # echo "in function" + if [ -f "$TEST_DIR/bin/tiup-playground.test" ]; then + $TEST_DIR/bin/tiup-playground.test -test.coverprofile=$TEST_DIR/cover/cov.itest-$(date +'%s')-$RANDOM.out __DEVEL--i-heard-you-like-tests "$@" + else + $TEST_DIR/../../bin/tiup-playground "$@" + fi +} + +function tiup() { + $TEST_DIR/../../bin/tiup "$@" +} + +# usage: check_tidb_num 1 +# make sure the TiKV-CDC number is 1 or other specified number +function check_kvcdc_num() { + mustbe=$1 + num=$(tiup-playground display | grep "tikv-cdc" | wc -l | sed 's/ //g') + if [ "$num" != "$mustbe" ]; then + echo "unexpected tikv-cdc instance number: $num" + tiup-playground display + fi +} + +function kill_all() { + killall -9 tidb-server || true + killall -9 tikv-server || true + killall -9 pd-server || true + killall -9 tiflash || true + killall -9 grafana-server || true + killall -9 tiup-playground || true + killall -9 prometheus || true + killall -9 ng-monitoring-server || true + cat $outfile +} + +outfile=/tmp/tiup-playground-test.out +tiup mirror set $MIRROR +# no tiflash to speed up +tiup-playground $VERSION --db 1 --pd 1 --kv 1 --kvcdc 1 --tiflash 0 > $outfile 2>&1 & + +# wait $outfile generated +sleep 3 + +trap "kill_all" EXIT + +# wait start cluster successfully +timeout 300 grep -q "CLUSTER START SUCCESSFULLY" <(tail -f $outfile) + +tiup-playground display | grep -qv "exit" +tiup-playground scale-out --kvcdc 2 +sleep 5 + +# 1(init) + 2(scale-out) +check_kvcdc_num 3 + +# get pid of one tikv-cdc instance and scale-in +pid=`tiup-playground display | grep "tikv-cdc" | awk 'NR==1 {print $1}'` +tiup-playground scale-in --pid $pid + +sleep 5 +check_kvcdc_num 2 + +# exit +killall -2 tiup-playground.test || killall -2 tiup-playground +sleep 30 + +echo -e "\033[0;36m<<< Run all test success >>>\033[0m" From 72de4e39ba63750d6594ca6f95c868036b20dc16 Mon Sep 17 00:00:00 2001 From: pingyu Date: Wed, 27 Jul 2022 20:42:19 +0800 Subject: [PATCH 3/8] refine codes Signed-off-by: pingyu --- components/playground/instance/tikv_cdc.go | 12 +++++------- components/playground/playground.go | 6 +++--- tests/tiup-playground/test_kvcdc.sh | 6 ++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/components/playground/instance/tikv_cdc.go b/components/playground/instance/tikv_cdc.go index a082339730..2b9d19c774 100644 --- a/components/playground/instance/tikv_cdc.go +++ b/components/playground/instance/tikv_cdc.go @@ -26,15 +26,14 @@ import ( // TiKVCDC represent a TiKV-CDC instance. type TiKVCDC struct { instance - version utils.Version - pds []*PDInstance + pds []*PDInstance Process } var _ Instance = &TiKVCDC{} // NewTiKVCDC create a TiKVCDC instance. -func NewTiKVCDC(version utils.Version, binPath string, dir, host, configPath string, id int, pds []*PDInstance) *TiKVCDC { +func NewTiKVCDC(binPath string, dir, host, configPath string, id int, pds []*PDInstance) *TiKVCDC { tikvCdc := &TiKVCDC{ instance: instance{ BinPath: binPath, @@ -44,15 +43,14 @@ func NewTiKVCDC(version utils.Version, binPath string, dir, host, configPath str Port: utils.MustGetFreePort(host, 8800), ConfigPath: configPath, }, - version: version, - pds: pds, + pds: pds, } tikvCdc.StatusPort = tikvCdc.Port return tikvCdc } // Start implements Instance interface. -func (c *TiKVCDC) Start(ctx context.Context, _ utils.Version) error { +func (c *TiKVCDC) Start(ctx context.Context, version utils.Version) error { endpoints := pdEndpoints(c.pds, true) args := []string{ @@ -68,7 +66,7 @@ func (c *TiKVCDC) Start(ctx context.Context, _ utils.Version) error { args = append(args, fmt.Sprintf("--data-dir=%s", filepath.Join(c.Dir, "data"))) var err error - if c.BinPath, err = tiupexec.PrepareBinary("tikv-cdc", c.version, c.BinPath); err != nil { + if c.BinPath, err = tiupexec.PrepareBinary("tikv-cdc", version, c.BinPath); err != nil { return err } c.Process = &process{cmd: PrepareCommand(ctx, c.BinPath, args, nil, c.Dir)} diff --git a/components/playground/playground.go b/components/playground/playground.go index 1ad03ffd71..b11005f7a4 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -428,8 +428,8 @@ func (p *Playground) sanitizeComponentConfig(cid string, cfg *instance.Config) e } func (p *Playground) startInstance(ctx context.Context, inst instance.Instance) error { - versionOption := p.bindVersion(inst.Component(), p.bootOptions.Version) - version, err := environment.GlobalEnv().V1Repository().ResolveComponentVersion(inst.Component(), versionOption) + boundVersion := p.bindVersion(inst.Component(), p.bootOptions.Version) + version, err := environment.GlobalEnv().V1Repository().ResolveComponentVersion(inst.Component(), boundVersion) if err != nil { return err } @@ -688,7 +688,7 @@ func (p *Playground) addInstance(componentID string, cfg instance.Config) (ins i ins = inst p.ticdcs = append(p.ticdcs, inst) case spec.ComponentTiKVCDC: - inst := instance.NewTiKVCDC(utils.Version(cfg.Version), cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) + inst := instance.NewTiKVCDC(cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) ins = inst p.tikv_cdcs = append(p.tikv_cdcs, inst) case spec.ComponentPump: diff --git a/tests/tiup-playground/test_kvcdc.sh b/tests/tiup-playground/test_kvcdc.sh index 3c8a9d07a1..4642da09ad 100755 --- a/tests/tiup-playground/test_kvcdc.sh +++ b/tests/tiup-playground/test_kvcdc.sh @@ -4,7 +4,9 @@ set -eux TEST_DIR=$(cd "$(dirname "$0")"; pwd) TMP_DIR=$TEST_DIR/_tmp -VERSION="v6.2.0" + +TIDB_VERSION="v6.2.0" +KVCDC_VERSION="v1.0.0-alpha" MIRROR="http://staging.tiup-server.pingcap.net" # TODO: move to release mirror after TiKV-CDC is released. @@ -60,7 +62,7 @@ function kill_all() { outfile=/tmp/tiup-playground-test.out tiup mirror set $MIRROR # no tiflash to speed up -tiup-playground $VERSION --db 1 --pd 1 --kv 1 --kvcdc 1 --tiflash 0 > $outfile 2>&1 & +tiup-playground $TIDB_VERSION --db 1 --pd 1 --kv 1 --tiflash 0 --kvcdc 1 --kvcdc.version $KVCDC_VERSION > $outfile 2>&1 & # wait $outfile generated sleep 3 From 56d20c05c59309fe920794743e3b8539b3e40a26 Mon Sep 17 00:00:00 2001 From: pingyu Date: Wed, 27 Jul 2022 23:26:13 +0800 Subject: [PATCH 4/8] fix CI error Signed-off-by: pingyu --- components/playground/playground.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/playground/playground.go b/components/playground/playground.go index b11005f7a4..f0b03b404e 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -64,7 +64,7 @@ type Playground struct { tidbs []*instance.TiDBInstance tiflashs []*instance.TiFlashInstance ticdcs []*instance.TiCDC - tikv_cdcs []*instance.TiKVCDC + tikvCdcs []*instance.TiKVCDC pumps []*instance.Pump drainers []*instance.Drainer startedInstances []instance.Instance @@ -311,9 +311,9 @@ func (p *Playground) handleScaleIn(w io.Writer, pid int) error { } } case spec.ComponentTiKVCDC: - for i := 0; i < len(p.tikv_cdcs); i++ { - if p.tikv_cdcs[i].Pid() == pid { - p.tikv_cdcs = append(p.tikv_cdcs[:i], p.tikv_cdcs[i+1:]...) + for i := 0; i < len(p.tikvCdcs); i++ { + if p.tikvCdcs[i].Pid() == pid { + p.tikvCdcs = append(p.tikvCdcs[:i], p.tikvCdcs[i+1:]...) } } case spec.ComponentTiFlash: @@ -603,7 +603,7 @@ func (p *Playground) WalkInstances(fn func(componentID string, ins instance.Inst } } - for _, ins := range p.tikv_cdcs { + for _, ins := range p.tikvCdcs { err := fn(spec.ComponentTiKVCDC, ins) if err != nil { return err @@ -690,7 +690,7 @@ func (p *Playground) addInstance(componentID string, cfg instance.Config) (ins i case spec.ComponentTiKVCDC: inst := instance.NewTiKVCDC(cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) ins = inst - p.tikv_cdcs = append(p.tikv_cdcs, inst) + p.tikvCdcs = append(p.tikvCdcs, inst) case spec.ComponentPump: inst := instance.NewPump(cfg.BinPath, dir, host, cfg.ConfigPath, id, p.pds) ins = inst @@ -1033,7 +1033,7 @@ func (p *Playground) terminate(sig syscall.Signal) { kill(inst.Component(), inst.Pid(), inst.Wait) } } - for _, inst := range p.tikv_cdcs { + for _, inst := range p.tikvCdcs { if inst.Process != nil { kill(inst.Component(), inst.Pid(), inst.Wait) } From 3f4e6912b89aaa66559f6ab30c8dc873fd7ff130 Mon Sep 17 00:00:00 2001 From: pingyu Date: Thu, 28 Jul 2022 20:23:59 +0800 Subject: [PATCH 5/8] change default porrt Signed-off-by: pingyu --- components/playground/instance/tikv_cdc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/playground/instance/tikv_cdc.go b/components/playground/instance/tikv_cdc.go index 2b9d19c774..4b3f195a4e 100644 --- a/components/playground/instance/tikv_cdc.go +++ b/components/playground/instance/tikv_cdc.go @@ -40,7 +40,7 @@ func NewTiKVCDC(binPath string, dir, host, configPath string, id int, pds []*PDI ID: id, Dir: dir, Host: host, - Port: utils.MustGetFreePort(host, 8800), + Port: utils.MustGetFreePort(host, 8600), ConfigPath: configPath, }, pds: pds, From e5f094dc8dac60c2580c09c95f5da9249dc25c9a Mon Sep 17 00:00:00 2001 From: pingyu Date: Tue, 6 Sep 2022 20:52:09 +0800 Subject: [PATCH 6/8] fix CI error Signed-off-by: pingyu --- tests/tiup-playground/test_kvcdc.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tiup-playground/test_kvcdc.sh b/tests/tiup-playground/test_kvcdc.sh index 4642da09ad..cbd21deff0 100755 --- a/tests/tiup-playground/test_kvcdc.sh +++ b/tests/tiup-playground/test_kvcdc.sh @@ -6,8 +6,9 @@ TEST_DIR=$(cd "$(dirname "$0")"; pwd) TMP_DIR=$TEST_DIR/_tmp TIDB_VERSION="v6.2.0" -KVCDC_VERSION="v1.0.0-alpha" -MIRROR="http://staging.tiup-server.pingcap.net" # TODO: move to release mirror after TiKV-CDC is released. +KVCDC_VERSION="v1.0.0" +MIRROR="https://tiup-mirrors.pingcap.com" +# MIRROR="http://staging.tiup-server.pingcap.net" # uncomment if staging environment is using. # Profile home directory From 52bf78fbfac94544671855bbb6fa9bde07daa20f Mon Sep 17 00:00:00 2001 From: pingyu Date: Wed, 7 Sep 2022 11:06:26 +0800 Subject: [PATCH 7/8] address comment Signed-off-by: pingyu --- components/playground/instance/tikv_cdc.go | 2 +- tests/tiup-playground/test_kvcdc.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/playground/instance/tikv_cdc.go b/components/playground/instance/tikv_cdc.go index 4b3f195a4e..7d970db1c7 100644 --- a/components/playground/instance/tikv_cdc.go +++ b/components/playground/instance/tikv_cdc.go @@ -59,11 +59,11 @@ func (c *TiKVCDC) Start(ctx context.Context, version utils.Version) error { fmt.Sprintf("--advertise-addr=%s:%d", AdvertiseHost(c.Host), c.Port), fmt.Sprintf("--pd=%s", strings.Join(endpoints, ",")), fmt.Sprintf("--log-file=%s", c.LogFile()), + fmt.Sprintf("--data-dir=%s", filepath.Join(c.Dir, "data")), } if c.ConfigPath != "" { args = append(args, fmt.Sprintf("--config=%s", c.ConfigPath)) } - args = append(args, fmt.Sprintf("--data-dir=%s", filepath.Join(c.Dir, "data"))) var err error if c.BinPath, err = tiupexec.PrepareBinary("tikv-cdc", version, c.BinPath); err != nil { diff --git a/tests/tiup-playground/test_kvcdc.sh b/tests/tiup-playground/test_kvcdc.sh index cbd21deff0..8d10e1bf9e 100755 --- a/tests/tiup-playground/test_kvcdc.sh +++ b/tests/tiup-playground/test_kvcdc.sh @@ -52,7 +52,7 @@ function kill_all() { killall -9 tidb-server || true killall -9 tikv-server || true killall -9 pd-server || true - killall -9 tiflash || true + killall -9 tikv-cdc || true killall -9 grafana-server || true killall -9 tiup-playground || true killall -9 prometheus || true From 6f5d5a7d8d223f109d43b9a900dacf365a07c40f Mon Sep 17 00:00:00 2001 From: pingyu Date: Wed, 7 Sep 2022 15:29:14 +0800 Subject: [PATCH 8/8] merge tikv-cdc test Signed-off-by: pingyu --- .github/workflows/integrate-playground.yaml | 1 - tests/tiup-playground/test_kvcdc.sh | 94 --------------------- tests/tiup-playground/test_playground.sh | 42 ++++++--- 3 files changed, 31 insertions(+), 106 deletions(-) delete mode 100755 tests/tiup-playground/test_kvcdc.sh diff --git a/.github/workflows/integrate-playground.yaml b/.github/workflows/integrate-playground.yaml index 1b2df6cbd4..86c82fe0a5 100644 --- a/.github/workflows/integrate-playground.yaml +++ b/.github/workflows/integrate-playground.yaml @@ -39,7 +39,6 @@ jobs: matrix: cases: - "test_playground" - - "test_kvcdc" env: working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }} steps: diff --git a/tests/tiup-playground/test_kvcdc.sh b/tests/tiup-playground/test_kvcdc.sh deleted file mode 100755 index 8d10e1bf9e..0000000000 --- a/tests/tiup-playground/test_kvcdc.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -TEST_DIR=$(cd "$(dirname "$0")"; pwd) -TMP_DIR=$TEST_DIR/_tmp - -TIDB_VERSION="v6.2.0" -KVCDC_VERSION="v1.0.0" -MIRROR="https://tiup-mirrors.pingcap.com" -# MIRROR="http://staging.tiup-server.pingcap.net" # uncomment if staging environment is using. - - -# Profile home directory -mkdir -p $TMP_DIR/home/bin/ -export TIUP_HOME=$TMP_DIR/home -curl $MIRROR/root.json -o $TMP_DIR/home/bin/root.json - -# Prepare data directory -rm -rf $TIUP_HOME/data -mkdir -p $TIUP_HOME/data -export TIUP_INSTANCE_DATA_DIR=$TIUP_HOME/data/test_play -mkdir -p $TIUP_INSTANCE_DATA_DIR - -mkdir -p $TEST_DIR/cover - -function tiup-playground() { - # echo "in function" - if [ -f "$TEST_DIR/bin/tiup-playground.test" ]; then - $TEST_DIR/bin/tiup-playground.test -test.coverprofile=$TEST_DIR/cover/cov.itest-$(date +'%s')-$RANDOM.out __DEVEL--i-heard-you-like-tests "$@" - else - $TEST_DIR/../../bin/tiup-playground "$@" - fi -} - -function tiup() { - $TEST_DIR/../../bin/tiup "$@" -} - -# usage: check_tidb_num 1 -# make sure the TiKV-CDC number is 1 or other specified number -function check_kvcdc_num() { - mustbe=$1 - num=$(tiup-playground display | grep "tikv-cdc" | wc -l | sed 's/ //g') - if [ "$num" != "$mustbe" ]; then - echo "unexpected tikv-cdc instance number: $num" - tiup-playground display - fi -} - -function kill_all() { - killall -9 tidb-server || true - killall -9 tikv-server || true - killall -9 pd-server || true - killall -9 tikv-cdc || true - killall -9 grafana-server || true - killall -9 tiup-playground || true - killall -9 prometheus || true - killall -9 ng-monitoring-server || true - cat $outfile -} - -outfile=/tmp/tiup-playground-test.out -tiup mirror set $MIRROR -# no tiflash to speed up -tiup-playground $TIDB_VERSION --db 1 --pd 1 --kv 1 --tiflash 0 --kvcdc 1 --kvcdc.version $KVCDC_VERSION > $outfile 2>&1 & - -# wait $outfile generated -sleep 3 - -trap "kill_all" EXIT - -# wait start cluster successfully -timeout 300 grep -q "CLUSTER START SUCCESSFULLY" <(tail -f $outfile) - -tiup-playground display | grep -qv "exit" -tiup-playground scale-out --kvcdc 2 -sleep 5 - -# 1(init) + 2(scale-out) -check_kvcdc_num 3 - -# get pid of one tikv-cdc instance and scale-in -pid=`tiup-playground display | grep "tikv-cdc" | awk 'NR==1 {print $1}'` -tiup-playground scale-in --pid $pid - -sleep 5 -check_kvcdc_num 2 - -# exit -killall -2 tiup-playground.test || killall -2 tiup-playground -sleep 30 - -echo -e "\033[0;36m<<< Run all test success >>>\033[0m" diff --git a/tests/tiup-playground/test_playground.sh b/tests/tiup-playground/test_playground.sh index 8df20df2d3..73200c127e 100755 --- a/tests/tiup-playground/test_playground.sh +++ b/tests/tiup-playground/test_playground.sh @@ -4,7 +4,7 @@ set -eux TEST_DIR=$(cd "$(dirname "$0")"; pwd) TMP_DIR=$TEST_DIR/_tmp - +TIDB_VERSION="v6.2.0" # Profile home directory mkdir -p $TMP_DIR/home/bin/ @@ -28,13 +28,14 @@ function tiup-playground() { fi } -# usage: check_tidb_num 1 +# usage: check_instance_num tidb 1 # make sure the tidb number is 1 or other specified number -function check_tidb_num() { - mustbe=$1 - num=$(tiup-playground display | grep "tidb" | wc -l | sed 's/ //g') +function check_instance_num() { + instance=$1 + mustbe=$2 + num=$(tiup-playground display | grep "$instance" | wc -l | sed 's/ //g') if [ "$num" != "$mustbe" ]; then - echo "unexpected tidb instance number: $num" + echo "unexpected $instance instance number: $num" tiup-playground display fi } @@ -43,6 +44,7 @@ function kill_all() { killall -9 tidb-server || true killall -9 tikv-server || true killall -9 pd-server || true + killall -9 tikv-cdc || true killall -9 tiflash || true killall -9 grafana-server || true killall -9 tiup-playground || true @@ -52,7 +54,7 @@ function kill_all() { } outfile=/tmp/tiup-playground-test.out -tiup-playground v6.0.0 > $outfile 2>&1 & +tiup-playground $TIDB_VERSION > $outfile 2>&1 & # wait $outfile generated sleep 3 @@ -71,14 +73,14 @@ sleep 5 ls "${TIUP_HOME}/data/test_play/prometheus/data" # 1(init) + 2(scale-out) -check_tidb_num 3 +check_instance_num tidb 3 # get pid of one tidb instance and scale-in pid=`tiup-playground display | grep "tidb" | awk 'NR==1 {print $1}'` tiup-playground scale-in --pid $pid sleep 5 -check_tidb_num 2 +check_instance_num tidb 2 # get pid of one tidb instance and kill it pid=`tiup-playground display | grep "tidb" | awk 'NR==1 {print $1}'` @@ -102,7 +104,7 @@ killall -2 tiup-playground.test || killall -2 tiup-playground sleep 100 # test restart with same data -tiup-playground v6.0.0 > $outfile 2>&1 & +tiup-playground $TIDB_VERSION > $outfile 2>&1 & # wait $outfile generated sleep 3 @@ -116,7 +118,7 @@ cat $outfile | grep ":3930" | grep -q "Done" TAG="test_1" outfile_1=/tmp/tiup-playground-test_1.out # no TiFlash to speed up -tiup-playground v6.0.0 --tag $TAG --db 2 --tiflash 0 > $outfile_1 2>&1 & +tiup-playground $TIDB_VERSION --tag $TAG --db 2 --tiflash 0 > $outfile_1 2>&1 & sleep 3 timeout 300 grep -q "CLUSTER START SUCCESSFULLY" <(tail -f $outfile_1) tiup-playground --tag $TAG display | grep -qv "exit" @@ -135,6 +137,24 @@ if [ "$tidb_num" != 3 ]; then exit 1 fi +killall -2 tiup-playground.test || killall -2 tiup-playground +sleep 100 + +# test for TiKV-CDC +echo -e "\033[0;36m<<< Run TiKV-CDC test >>>\033[0m" +tiup-playground $TIDB_VERSION --db 1 --pd 1 --kv 1 --tiflash 0 --kvcdc 1 --kvcdc.version v1.0.0 > $outfile 2>&1 & +sleep 3 +timeout 300 grep -q "CLUSTER START SUCCESSFULLY" <(tail -f $outfile) +tiup-playground display | grep -qv "exit" +# scale out +tiup-playground scale-out --kvcdc 2 +sleep 5 +check_instance_num tikv-cdc 3 # 1(init) + 2(scale-out) +# scale in +pid=`tiup-playground display | grep "tikv-cdc" | awk 'NR==1 {print $1}'` +tiup-playground scale-in --pid $pid +sleep 5 +check_instance_num tikv-cdc 2 # exit all killall -2 tiup-playground.test || killall -2 tiup-playground