From 47f7cb0afb214f51f36e422718e7f6ca9189fee8 Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Fri, 7 Dec 2018 15:18:34 +0800 Subject: [PATCH 1/6] add test for reparo --- Makefile | 3 ++- tests/_utils/run_reparo | 20 +++++++++++++++++++ tests/reparo/drainer.toml | 41 +++++++++++++++++++++++++++++++++++++++ tests/reparo/reparo.toml | 28 ++++++++++++++++++++++++++ tests/reparo/run.sh | 34 ++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/_utils/run_reparo create mode 100644 tests/reparo/drainer.toml create mode 100644 tests/reparo/reparo.toml create mode 100644 tests/reparo/run.sh diff --git a/Makefile b/Makefile index 317449d2e..5582e5981 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ all: dev install dev: check test build -build: pump drainer +build: pump drainer reparo pump: $(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/pump cmd/pump/main.go @@ -63,6 +63,7 @@ integration_test: build @which bin/pd-server @which bin/drainer @which bin/pump + @which bin/reparo tests/run.sh fmt: diff --git a/tests/_utils/run_reparo b/tests/_utils/run_reparo new file mode 100644 index 000000000..9c320b0b4 --- /dev/null +++ b/tests/_utils/run_reparo @@ -0,0 +1,20 @@ +#!/bin/sh + +set -ue + +OUT_DIR=/tmp/tidb_binlog_test + +killall reparo || true + + +config=${TEST_DIR-.}/reparo.toml +log=$OUT_DIR/reparo.log + +echo "[$(date)] <<<<<< START IN TEST ${TEST_NAME-} FOR: $config >>>>>>" >> "$log" + +if [ -f "$config" ] +then + reparo -config $config -log-file $log >> $log 2>&1 +else + reapro -log-file $log >> $log 2>&1 +fi diff --git a/tests/reparo/drainer.toml b/tests/reparo/drainer.toml new file mode 100644 index 000000000..479752a34 --- /dev/null +++ b/tests/reparo/drainer.toml @@ -0,0 +1,41 @@ +# drainer Configuration. + +# addr (i.e. 'host:port') to listen on for drainer connections +# will register this addr into etcd +# addr = "127.0.0.1:8249" + +# the interval time (in seconds) of detect pumps' status +detect-interval = 10 + +# drainer meta data directory path +data-dir = "data.drainer" + +# a comma separated list of PD endpoints +pd-urls = "http://127.0.0.1:2379" + +# syncer Configuration. +[syncer] + +# disable sync these schema +ignore-schemas = "INFORMATION_SCHEMA,PERFORMANCE_SCHEMA,mysql" + +# number of binlog events in a transaction batch +txn-batch = 1 + +# work count to execute binlogs +worker-count = 1 + +disable-dispatch = false + +# safe mode will split update to delete and insert +safe-mode = false + +# downstream storage, equal to --dest-db-type +# valid values are "mysql", "pb", "tidb", "flash", "kafka" +db-type = "pb" + +[syncer.to] +#dir = "/data/data.drainer" +compression = "gzip" + + diff --git a/tests/reparo/reparo.toml b/tests/reparo/reparo.toml new file mode 100644 index 000000000..b15daff99 --- /dev/null +++ b/tests/reparo/reparo.toml @@ -0,0 +1,28 @@ +# drainer 输出的 protobuf 格式 binlog 文件的存储路径 +data-dir = "data.drainer" + +# log-file = "" +# log-rotate = "hour" +log-level = "info" + +# start-datetime and stop-datetime enable you to pick a range of binlog to reparo. +# The datetime format is like '2018-02-28 12:12:12'. +#start-datetime = "2018-10-24 00:00:00" +#stop-datetime = "2018-11-26 00:00:00" + +# Start-tso is similar to start-datetime, but in pd-server tso format. e.g. 395181938313123110 +# Stop-tso is is similar to stop-datetime, but in pd-server tso format. e.g. 395181938313123110 +# start-tso = 0 +# stop-tso = 0 + +# dest-type choose a destination, which value can be "mysql", "print". +# for print, it just prints decoded value. +dest-type = "mysql" +compression = "gzip" + +# 如果指定的 dest-type 为 mysql 或 tidb,需要配置 dest-db。 +[dest-db] +host = "127.0.0.1" +port = 3306 +user = "root" +password = "" \ No newline at end of file diff --git a/tests/reparo/run.sh b/tests/reparo/run.sh new file mode 100644 index 000000000..35115ab23 --- /dev/null +++ b/tests/reparo/run.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -e + +cd "$(dirname "$0")" + +run_drainer & + +# according to the config, db name or table start with `do_start` or exact equals `do_name` will be synced to downstream +# we use the name start with `do_no_start` and `do_not_name` to make sure other db or table will not be synced to downstream + +run_sql "DROP DATABASE IF EXISTS reparo_test;" +run_sql "CREATE DATABASE reparo_test" +run_sql "CREATE TABLE reparo_test.test(id int, name varchar(10), PRIMARY KEY(id))" + +run_sql "INSERT INTO reparo_test.test VALUES(1, 'a'), (2, 'b')" +run_sql "INSERT INTO reparo_test.test VALUES(3, 'c'), (4, 'd')" +run_sql "UPDATE reparo_test.test SET name = 'bb' where id = 2" +run_sql "DELETE FROM reparo_test.test WHERE name = 'bb'" +run_sql "INSERT INTO reparo_test.test VALUES(5, 'e')" + +sleep 5 + +run_reparo & + +sleep 5 + +down_run_sql "SELECT count(*) FROM reparo_test.test" +check_contains "count(*): 4" + +# clean up +run_sql "DROP DATABASE IF EXISTS reparo_test" + +killall drainer From 850533411529209c11398e184577763583b19c2e Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Fri, 7 Dec 2018 20:05:25 +0800 Subject: [PATCH 2/6] make script executeable --- tests/reparo/drainer.toml | 2 +- tests/reparo/reparo.toml | 2 +- tests/reparo/run.sh | 0 3 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 tests/reparo/run.sh diff --git a/tests/reparo/drainer.toml b/tests/reparo/drainer.toml index 479752a34..ecc19b3e7 100644 --- a/tests/reparo/drainer.toml +++ b/tests/reparo/drainer.toml @@ -36,6 +36,6 @@ db-type = "pb" [syncer.to] #dir = "/data/data.drainer" -compression = "gzip" +#compression = "gzip" diff --git a/tests/reparo/reparo.toml b/tests/reparo/reparo.toml index b15daff99..8eda6d904 100644 --- a/tests/reparo/reparo.toml +++ b/tests/reparo/reparo.toml @@ -18,7 +18,7 @@ log-level = "info" # dest-type choose a destination, which value can be "mysql", "print". # for print, it just prints decoded value. dest-type = "mysql" -compression = "gzip" +#compression = "gzip" # 如果指定的 dest-type 为 mysql 或 tidb,需要配置 dest-db。 [dest-db] diff --git a/tests/reparo/run.sh b/tests/reparo/run.sh old mode 100644 new mode 100755 From 2487cb8ae22301fa04e99919cfddee2858abb2b0 Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Fri, 7 Dec 2018 20:14:05 +0800 Subject: [PATCH 3/6] make script executeable --- tests/_utils/run_reparo | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tests/_utils/run_reparo diff --git a/tests/_utils/run_reparo b/tests/_utils/run_reparo old mode 100644 new mode 100755 From 35e413d89577523d0e538cee870f0d0cc0ef2f33 Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Fri, 7 Dec 2018 20:23:22 +0800 Subject: [PATCH 4/6] minor update --- tests/reparo/run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/reparo/run.sh b/tests/reparo/run.sh index 35115ab23..2479db7a8 100755 --- a/tests/reparo/run.sh +++ b/tests/reparo/run.sh @@ -4,6 +4,7 @@ set -e cd "$(dirname "$0")" +mkdir data.drainer run_drainer & # according to the config, db name or table start with `do_start` or exact equals `do_name` will be synced to downstream From 25a3450eddb75894e61c172153848ba8af35b714 Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Fri, 7 Dec 2018 20:34:51 +0800 Subject: [PATCH 5/6] minor update --- tests/reparo/drainer.toml | 2 +- tests/reparo/run.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/reparo/drainer.toml b/tests/reparo/drainer.toml index ecc19b3e7..d3f8a7379 100644 --- a/tests/reparo/drainer.toml +++ b/tests/reparo/drainer.toml @@ -34,7 +34,7 @@ safe-mode = false # valid values are "mysql", "pb", "tidb", "flash", "kafka" db-type = "pb" -[syncer.to] +#[syncer.to] #dir = "/data/data.drainer" #compression = "gzip" diff --git a/tests/reparo/run.sh b/tests/reparo/run.sh index 2479db7a8..35115ab23 100755 --- a/tests/reparo/run.sh +++ b/tests/reparo/run.sh @@ -4,7 +4,6 @@ set -e cd "$(dirname "$0")" -mkdir data.drainer run_drainer & # according to the config, db name or table start with `do_start` or exact equals `do_name` will be synced to downstream From 47fe47e294e5ed96e858371149c07ee83ce603af Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Thu, 13 Dec 2018 16:01:57 +0800 Subject: [PATCH 6/6] remove useless comment --- tests/reparo/run.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/reparo/run.sh b/tests/reparo/run.sh index 35115ab23..fc4cb3b3c 100755 --- a/tests/reparo/run.sh +++ b/tests/reparo/run.sh @@ -6,9 +6,6 @@ cd "$(dirname "$0")" run_drainer & -# according to the config, db name or table start with `do_start` or exact equals `do_name` will be synced to downstream -# we use the name start with `do_no_start` and `do_not_name` to make sure other db or table will not be synced to downstream - run_sql "DROP DATABASE IF EXISTS reparo_test;" run_sql "CREATE DATABASE reparo_test" run_sql "CREATE TABLE reparo_test.test(id int, name varchar(10), PRIMARY KEY(id))"