Skip to content

Commit

Permalink
chaos: integrate mysql-8 and mariadb (pingcap#1367) (pingcap#1368)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jan 14, 2021
1 parent 924cd2b commit 0bbda3c
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 102 deletions.
34 changes: 18 additions & 16 deletions .github/workflows/chaos-mesh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,35 @@ jobs:
# run: |
# kind load docker-image dm:chaos --name dm-chaos

# Set up upstream MySQL instances
- name: Set up MySQL
# Set up upstream instances
- name: Set up sources
run: |
kubectl apply -f $GITHUB_WORKSPACE/chaos/manifests/mysql.yaml
kubectl get -f $GITHUB_WORKSPACE/chaos/manifests/mysql.yaml
kubectl describe -f $GITHUB_WORKSPACE/chaos/manifests/mysql.yaml
- name: Wait for MySQL ready # kubectl wait --all not working
kubectl apply -f $GITHUB_WORKSPACE/chaos/manifests/sources.yaml
kubectl get -f $GITHUB_WORKSPACE/chaos/manifests/sources.yaml
kubectl describe -f $GITHUB_WORKSPACE/chaos/manifests/sources.yaml
- name: Wait for sources ready # kubectl wait --all not working
run: |
kubectl wait --for=condition=Ready pod/mysql-0 --timeout=300s || true
kubectl wait --for=condition=Ready pod/mysql57-0 --timeout=300s || true
kubectl wait --for=condition=Ready pod/mysql8-0 --timeout=300s || true
kubectl wait --for=condition=Ready pod/mariadb-0 --timeout=300s || true
sleep 10
kubectl wait --for=condition=Ready pod/mysql-1 --timeout=300s || true
echo show pvc
kubectl get pvc -l app=mysql -o wide
kubectl get pvc -l app=sources -o wide
echo show pv
kubectl get pv -o wide
echo show svc
kubectl get svc -l app=mysql -o wide
kubectl get svc -l app=sources -o wide
echo show sts
kubectl get sts -l app=mysql -o wide
kubectl get sts -l app=sources -o wide
echo show po
kubectl get po -l app=mysql -o wide
kubectl get po -l app=sources -o wide
echo describe po
kubectl describe po -l app=mysql
kubectl describe po -l app=sources
echo describe pvc
kubectl describe pvc -l app=mysql
kubectl wait --for=condition=Ready pod/mysql-0 --timeout=0s
kubectl wait --for=condition=Ready pod/mysql-1 --timeout=0s
kubectl describe pvc -l app=sources
kubectl wait --for=condition=Ready pod/mysql57-0 --timeout=0s
kubectl wait --for=condition=Ready pod/mysql8-0 --timeout=0s
kubectl wait --for=condition=Ready pod/mariadb-0 --timeout=0s
# Set up downstream TiDB instance (deploy a TiDB with mockTiKV, not a TidbCluster managed by TiDB-operator)
- name: Set up TiDB
Expand Down
8 changes: 4 additions & 4 deletions chaos/cases/conf/source1.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
source-id: "mysql-replica-01"
enable-gtid: false
enable-relay: false
source-id: "replica-01"
enable-gtid: true
enable-relay: true

from:
host: "mysql-0.mysql" # same namespace with MySQL
host: "mysql57-0.sources" # same namespace with MySQL
user: "root"
password: ""
port: 3306
8 changes: 4 additions & 4 deletions chaos/cases/conf/source2.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
source-id: "mysql-replica-02"
enable-gtid: true
enable-relay: true
source-id: "replica-02"
enable-gtid: false
enable-relay: false

from:
host: "mysql-1.mysql" # same namespace with MySQL
host: "mysql8-0.sources" # same namespace with MySQL
user: "root"
password: ""
port: 3306
9 changes: 9 additions & 0 deletions chaos/cases/conf/source3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source-id: "replica-03"
enable-gtid: false
enable-relay: true

from:
host: "mariadb-0.sources" # same namespace with MySQL
user: "root"
password: ""
port: 3306
17 changes: 14 additions & 3 deletions chaos/cases/conf/task-optimistic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
name: "task_optimistic"
task-mode: all
shard-mode: optimistic
ignore-checking-items: ["auto_increment_ID"] # tables generated by go-sqlsmith may have auto increment ID
# Display width specification for integer data types was deprecated in MySQL 8.0.17
# create table tb(a int(12)) will be `int` in mysql:8.0.17+ but `int(12)` in mysql:5.7
# so ignore sharding table check, seems has no effect on sync-diff-inspector
# see https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-19.html
ignore-checking-items: ["schema_of_shard_tables","auto_increment_ID"] # tables generated by go-sqlsmith may have auto increment ID
timezone: "UTC"

target-database:
host: "tidb-0.tidb"
Expand All @@ -12,13 +17,19 @@ target-database:

mysql-instances:
-
source-id: "mysql-replica-01"
source-id: "replica-01"
black-white-list: "instance"
mydumper-thread: 4
loader-thread: 16
syncer-thread: 16
-
source-id: "mysql-replica-02"
source-id: "replica-02"
black-white-list: "instance"
mydumper-thread: 4
loader-thread: 16
syncer-thread: 16
-
source-id: "replica-03"
black-white-list: "instance"
mydumper-thread: 4
loader-thread: 16
Expand Down
17 changes: 14 additions & 3 deletions chaos/cases/conf/task-pessimistic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
name: "task_pessimistic"
task-mode: all
shard-mode: pessimistic
ignore-checking-items: ["auto_increment_ID"] # tables generated by go-sqlsmith may have auto increment ID
# Display width specification for integer data types was deprecated in MySQL 8.0.17
# create table tb(a int(12)) will be `int` in mysql:8.0.17+ but `int(12)` in mysql:5.7
# so ignore sharding table check, seems has no effect on sync-diff-inspector
# see https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-19.html
ignore-checking-items: ["schema_of_shard_tables","auto_increment_ID"] # tables generated by go-sqlsmith may have auto increment ID
timezone: "UTC"

target-database:
host: "tidb-0.tidb"
Expand All @@ -12,13 +17,19 @@ target-database:

mysql-instances:
-
source-id: "mysql-replica-01"
source-id: "replica-01"
black-white-list: "instance"
mydumper-thread: 4
loader-thread: 16
syncer-thread: 16
-
source-id: "mysql-replica-02"
source-id: "replica-02"
black-white-list: "instance"
mydumper-thread: 4
loader-thread: 16
syncer-thread: 16
-
source-id: "replica-03"
black-white-list: "instance"
mydumper-thread: 4
loader-thread: 16
Expand Down
3 changes: 2 additions & 1 deletion chaos/cases/conf/task-single.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: "task_single"
task-mode: all
timezone: "UTC"

target-database:
host: "tidb-0.tidb"
Expand All @@ -10,7 +11,7 @@ target-database:

mysql-instances:
-
source-id: "mysql-replica-01"
source-id: "replica-01"
black-white-list: "instance"
mydumper-thread: 4
loader-thread: 16
Expand Down
12 changes: 10 additions & 2 deletions chaos/cases/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type config struct {

Source1 config2.DBConfig `toml:"source-1" yaml:"source-1" json:"source-1"`
Source2 config2.DBConfig `toml:"source-2" yaml:"source-2" json:"source-2"`
Source3 config2.DBConfig `toml:"source-3" yaml:"source-3" json:"source-3"`
Target config2.DBConfig `toml:"target" yaml:"target" json:"target"`
}

Expand All @@ -49,16 +50,21 @@ func newConfig() *config {
fs.IntVar(&cfg.MasterCount, "master-count", 3, "expect count of dm-master")
fs.IntVar(&cfg.WorkerCount, "worker-count", 3, "expect count of dm-worker")

fs.StringVar(&cfg.Source1.Host, "source1.host", "mysql-0.mysql", "host of the first upstream source")
fs.StringVar(&cfg.Source1.Host, "source1.host", "mysql57-0.sources", "host of the first upstream source")
fs.IntVar(&cfg.Source1.Port, "source1.port", 3306, "port of the first upstream source")
fs.StringVar(&cfg.Source1.User, "source1.user", "root", "user of the first upstream source")
fs.StringVar(&cfg.Source1.Password, "source1.password", "", "password of the first upstream source")

fs.StringVar(&cfg.Source2.Host, "source2.host", "mysql-1.mysql", "host of the second upstream source")
fs.StringVar(&cfg.Source2.Host, "source2.host", "mysql8-0.sources", "host of the second upstream source")
fs.IntVar(&cfg.Source2.Port, "source2.port", 3306, "port of the second upstream source")
fs.StringVar(&cfg.Source2.User, "source2.user", "root", "user of the second upstream source")
fs.StringVar(&cfg.Source2.Password, "source2.password", "", "password of the second upstream source")

fs.StringVar(&cfg.Source3.Host, "source3.host", "mariadb-0.sources", "host of the third upstream source")
fs.IntVar(&cfg.Source3.Port, "source3.port", 3306, "port of the third upstream source")
fs.StringVar(&cfg.Source3.User, "source3.user", "root", "user of the third upstream source")
fs.StringVar(&cfg.Source3.Password, "source3.password", "", "password of the third upstream source")

fs.StringVar(&cfg.Target.Host, "target.host", "tidb-0.tidb", "host of the downstream target")
fs.IntVar(&cfg.Target.Port, "target.port", 4000, "port of the downstream target")
fs.StringVar(&cfg.Target.User, "target.user", "root", "user of the downstream target")
Expand All @@ -85,8 +91,10 @@ func (c *config) adjust() {
// `ALTER TABLE .* ADD COLUMN (.* TIMESTAMP)` will have different default value
c.Source1.Session = map[string]string{"sql_mode": "", "explicit_defaults_for_timestamp": "on"}
c.Source2.Session = map[string]string{"sql_mode": "", "explicit_defaults_for_timestamp": "on"}
c.Source3.Session = map[string]string{"sql_mode": ""} // explicit_defaults_for_timestamp enabled when deploy it

c.Source1.Adjust()
c.Source2.Adjust()
c.Source3.Adjust()
c.Target.Adjust()
}
6 changes: 3 additions & 3 deletions chaos/cases/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ func main() {
log.L().Error("fail to check members ready", zap.Error(err)) // only log a error, still try to do other things.
}

// create two sources.
// create sources.
err = createSources(ctx, masterCli, cfg)
if err != nil {
log.L().Error("fail to create source", zap.Error(err))
os.Exit(2)
}

// set upstream and downstream instances state.
err = setInstancesState(ctx, cfg.Target, cfg.Source1, cfg.Source2)
err = setInstancesState(ctx, cfg.Target, cfg.Source1, cfg.Source2, cfg.Source3)
if err != nil {
log.L().Error("fail to set instances state", zap.Error(err))
os.Exit(2)
Expand All @@ -109,7 +109,7 @@ func main() {
defer cancel3()

// run tests cases
err = runCases(ctx3, masterCli, cfg.ConfigDir, cfg.Target, cfg.Source1, cfg.Source2)
err = runCases(ctx3, masterCli, cfg.ConfigDir, cfg.Target, cfg.Source1, cfg.Source2, cfg.Source3)
if err != nil {
log.L().Error("run cases failed", zap.Error(err))
os.Exit(2)
Expand Down
18 changes: 16 additions & 2 deletions chaos/cases/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
)

// createSources does `operate-source create` operation for two sources.
// NOTE: we put two source config files (`source1.yaml` and `source2.yaml`) in `conf` directory.
// NOTE: we put source config files in `conf` directory.
func createSources(ctx context.Context, cli pb.MasterClient, cfg *config) error {
s1Path := filepath.Join(cfg.ConfigDir, "source1.yaml")
s2Path := filepath.Join(cfg.ConfigDir, "source2.yaml")
s3Path := filepath.Join(cfg.ConfigDir, "source3.yaml")

s1Content, err := ioutil.ReadFile(s1Path)
if err != nil {
Expand All @@ -38,19 +39,28 @@ func createSources(ctx context.Context, cli pb.MasterClient, cfg *config) error
if err != nil {
return err
}
s3Content, err := ioutil.ReadFile(s3Path)
if err != nil {
return err
}

cfg1 := config2.NewSourceConfig()
cfg2 := config2.NewSourceConfig()
cfg3 := config2.NewSourceConfig()
if err = cfg1.ParseYaml(string(s1Content)); err != nil {
return err
}
if err = cfg2.ParseYaml(string(s2Content)); err != nil {
return err
}
if err = cfg3.ParseYaml(string(s3Content)); err != nil {
return err
}

// replace DB config.
cfg1.From = cfg.Source1
cfg2.From = cfg.Source2
cfg3.From = cfg.Source3
s1Content2, err := cfg1.Yaml()
if err != nil {
return err
Expand All @@ -59,10 +69,14 @@ func createSources(ctx context.Context, cli pb.MasterClient, cfg *config) error
if err != nil {
return err
}
s3Content3, err := cfg3.Yaml()
if err != nil {
return err
}

resp, err := cli.OperateSource(ctx, &pb.OperateSourceRequest{
Op: pb.SourceOp_StartSource,
Config: []string{s1Content2, s2Content2},
Config: []string{s1Content2, s2Content2, s3Content3},
})
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions chaos/cases/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import (
const (
tableCount = 10 // tables count in schema.
fullInsertCount = 100 // `INSERT INTO` count (not rows count) for each table in full stage.
diffCount = 30 // diff data check count
diffInterval = 10 * time.Second // diff data check interval
incrRoundTime = 20 * time.Second // time to generate incremental data in one round
diffCount = 10 // diff data check count
diffInterval = 20 * time.Second // diff data check interval
incrRoundTime = 10 * time.Second // time to generate incremental data in one round
)

// task is a data migration task test case with one or more sources.
Expand Down Expand Up @@ -343,7 +343,7 @@ func (t *task) genIncrData(ctx context.Context) (err error) {
default:
}

if rand.Intn(1000) < 10 {
if rand.Intn(3000) < 10 {
query, err = randDDL(t.ss)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion chaos/manifests/dm-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
matchLabels:
app: dm-worker
serviceName: dm-worker
replicas: 3 # 3 DM-worker instances
replicas: 4 # 4 DM-worker instances
podManagementPolicy: Parallel
template:
metadata:
Expand Down
59 changes: 0 additions & 59 deletions chaos/manifests/mysql.yaml

This file was deleted.

Loading

0 comments on commit 0bbda3c

Please sign in to comment.