This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
16 changed files
with
288 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# diff Configuration. | ||
|
||
log-level = "info" | ||
|
||
chunk-size = 1000 | ||
|
||
check-thread-count = 4 | ||
|
||
sample-percent = 100 | ||
|
||
use-checksum = true | ||
|
||
fix-sql-file = "fix.sql" | ||
|
||
# tables need to check. | ||
[[check-tables]] | ||
schema = "only_dml" | ||
tables = ["~t.*"] | ||
|
||
[[table-config]] | ||
schema = "only_dml" | ||
table = "t1" | ||
|
||
[[table-config.source-tables]] | ||
instance-id = "source-1" | ||
schema = "only_dml" | ||
table = "t1" | ||
|
||
[[table-config]] | ||
schema = "only_dml" | ||
table = "t2" | ||
|
||
[[table-config.source-tables]] | ||
instance-id = "source-2" | ||
schema = "only_dml" | ||
table = "t2" | ||
|
||
[[source-db]] | ||
host = "127.0.0.1" | ||
port = 3306 | ||
user = "root" | ||
password = "123456" | ||
instance-id = "source-1" | ||
|
||
[[source-db]] | ||
host = "127.0.0.1" | ||
port = 3307 | ||
user = "root" | ||
password = "123456" | ||
instance-id = "source-2" | ||
|
||
[target-db] | ||
host = "127.0.0.1" | ||
port = 4000 | ||
user = "test" | ||
password = "123456" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Master Configuration. | ||
master-addr = ":8261" | ||
advertise-addr = "127.0.0.1:8261" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
name: test | ||
task-mode: all | ||
is-sharding: false | ||
meta-schema: "dm_meta" | ||
# enable-heartbeat: true | ||
heartbeat-update-interval: 1 | ||
heartbeat-report-interval: 1 | ||
timezone: "Asia/Shanghai" | ||
|
||
target-database: | ||
host: "127.0.0.1" | ||
port: 4000 | ||
user: "root" | ||
password: "" | ||
|
||
mysql-instances: | ||
- source-id: "mysql-replica-01" | ||
block-allow-list: "instance" | ||
mydumper-config-name: "global" | ||
loader-config-name: "global" | ||
syncer-config-name: "global" | ||
|
||
- source-id: "mysql-replica-02" | ||
block-allow-list: "instance" | ||
mydumper-config-name: "global" | ||
loader-config-name: "global" | ||
syncer-config-name: "global" | ||
|
||
block-allow-list: | ||
instance: | ||
do-dbs: ["only_dml"] | ||
|
||
mydumpers: | ||
global: | ||
threads: 4 | ||
chunk-filesize: 64 | ||
skip-tz-utc: true | ||
extra-args: "" | ||
|
||
loaders: | ||
global: | ||
pool-size: 16 | ||
dir: "./dumped_data" | ||
|
||
syncers: | ||
global: | ||
worker-count: 16 | ||
batch: 100 | ||
checkpoint-flush-interval: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "worker1" | ||
join = "127.0.0.1:8261" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "worker2" | ||
join = "127.0.0.1:8261" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
source-id: mysql-replica-01 | ||
enable-relay: true | ||
from: | ||
host: 127.0.0.1 | ||
user: root | ||
password: /Q7B9DizNLLTTfiZHv9WoEAKamfpIUs= | ||
port: 3306 | ||
checker: | ||
check-enable: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
source-id: mysql-replica-02 | ||
enable-gtid: true | ||
enable-relay: true | ||
from: | ||
host: 127.0.0.1 | ||
user: root | ||
password: /Q7B9DizNLLTTfiZHv9WoEAKamfpIUs= | ||
port: 3307 | ||
checker: | ||
check-enable: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
drop database if exists `only_dml`; | ||
reset master; | ||
create database `only_dml`; | ||
use `only_dml`; | ||
create table t1 (id int, primary key(`id`)); | ||
insert into t1 values (1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
drop database if exists `only_dml`; | ||
reset master; | ||
create database `only_dml`; | ||
use `only_dml`; | ||
create table t2 (id int, primary key (`id`)); | ||
insert into t2 values (2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
cur=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
source $cur/../_utils/test_prepare | ||
WORK_DIR=$TEST_DIR/$TEST_NAME | ||
TASK_NAME="test" | ||
SQL_RESULT_FILE="$TEST_DIR/sql_res.$TEST_NAME.txt" | ||
|
||
function purge_relay_success() { | ||
binlog_file=$1 | ||
source_id=$2 | ||
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \ | ||
"purge-relay --filename $binlog_file -s $source_id" \ | ||
"\"result\": true" 2 | ||
} | ||
|
||
function run_sql_silent() { | ||
TIDB_PORT=4000 | ||
user="root" | ||
if [[ "$2" = $TIDB_PORT ]]; then | ||
user="test" | ||
fi | ||
mysql -u$user -h127.0.0.1 -P$2 -p$3 --default-character-set utf8 -E -e "$1" >> /dev/null | ||
} | ||
|
||
function insert_data() { | ||
i=1 | ||
|
||
while true; do | ||
sleep 1 | ||
run_sql_silent "insert into only_dml.t1 values ($(($i*2+1)));" $MYSQL_PORT1 $MYSQL_PASSWORD1 | ||
run_sql_silent "insert into only_dml.t2 values ($(($i*2+2)));" $MYSQL_PORT2 $MYSQL_PASSWORD2 | ||
((i++)) | ||
run_sql_silent "insert into only_dml.t1 values ($(($i*2+1)));" $MYSQL_PORT1 $MYSQL_PASSWORD1 | ||
run_sql_silent "insert into only_dml.t2 values ($(($i*2+2)));" $MYSQL_PORT2 $MYSQL_PASSWORD2 | ||
((i++)) | ||
run_sql_silent "flush logs;" $MYSQL_PORT1 $MYSQL_PASSWORD1 | ||
run_sql_silent "flush logs;" $MYSQL_PORT2 $MYSQL_PASSWORD2 | ||
done | ||
} | ||
|
||
function run() { | ||
|
||
run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1 | ||
check_contains 'Query OK, 1 row affected' | ||
run_sql_file $cur/data/db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2 | ||
check_contains 'Query OK, 1 row affected' | ||
|
||
# bound source1 to worker1, source2 to worker2 | ||
run_dm_master $WORK_DIR/master $MASTER_PORT $cur/conf/dm-master.toml | ||
check_rpc_alive $cur/../bin/check_master_online 127.0.0.1:$MASTER_PORT | ||
run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml | ||
check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER1_PORT | ||
|
||
cp $cur/conf/source1.yaml $WORK_DIR/source1.yaml | ||
cp $cur/conf/source2.yaml $WORK_DIR/source2.yaml | ||
sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker1/relay_log" $WORK_DIR/source1.yaml | ||
sed -i "/relay-binlog-name/i\relay-dir: $WORK_DIR/worker2/relay_log" $WORK_DIR/source2.yaml | ||
dmctl_operate_source create $WORK_DIR/source1.yaml $SOURCE_ID1 | ||
|
||
run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml | ||
check_rpc_alive $cur/../bin/check_worker_online 127.0.0.1:$WORKER2_PORT | ||
dmctl_operate_source create $WORK_DIR/source2.yaml $SOURCE_ID2 | ||
|
||
# start a task in all mode, and when enter incremental mode, we only execute DML | ||
dmctl_start_task $cur/conf/dm-task.yaml | ||
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml | ||
|
||
insert_data & | ||
pid=$! | ||
echo "PID of insert_data is $pid" | ||
|
||
# check twice, make sure update active relay log could work for first time and later | ||
for i in {1..2}; do | ||
sleep 6 | ||
server_uuid1=$(tail -n 1 $WORK_DIR/worker1/relay-dir/server-uuid.index) | ||
run_sql_source1 "show binary logs\G" | ||
max_binlog_name=$(grep Log_name "$SQL_RESULT_FILE"| tail -n 1 | awk -F":" '{print $NF}') | ||
earliest_relay_log1=`ls $WORK_DIR/worker1/relay-dir/$server_uuid1 | grep -v 'relay.meta' | sort | head -n 1` | ||
purge_relay_success $max_binlog_name $SOURCE_ID1 | ||
earliest_relay_log2=`ls $WORK_DIR/worker1/relay-dir/$server_uuid1 | grep -v 'relay.meta' | sort | head -n 1` | ||
echo "earliest_relay_log1: $earliest_relay_log1 earliest_relay_log2: $earliest_relay_log2" | ||
[ "$earliest_relay_log1" != "$earliest_relay_log2" ] | ||
|
||
server_uuid1=$(tail -n 1 $WORK_DIR/worker2/relay-dir/server-uuid.index) | ||
run_sql_source2 "show binary logs\G" | ||
max_binlog_name=$(grep Log_name "$SQL_RESULT_FILE"| tail -n 1 | awk -F":" '{print $NF}') | ||
earliest_relay_log1=`ls $WORK_DIR/worker2/relay-dir/$server_uuid1 | grep -v 'relay.meta' | sort | head -n 1` | ||
purge_relay_success $max_binlog_name $SOURCE_ID2 | ||
earliest_relay_log2=`ls $WORK_DIR/worker2/relay-dir/$server_uuid1 | grep -v 'relay.meta' | sort | head -n 1` | ||
echo "earliest_relay_log1: $earliest_relay_log1 earliest_relay_log2: $earliest_relay_log2" | ||
[ "$earliest_relay_log1" != "$earliest_relay_log2" ] | ||
done | ||
|
||
kill $pid | ||
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml | ||
} | ||
|
||
cleanup_data $TEST_NAME | ||
# also cleanup dm processes in case of last run failed | ||
cleanup_process $* | ||
run $* | ||
cleanup_process $* | ||
|
||
echo "[$(date)] <<<<<< test case $TEST_NAME success! >>>>>>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ sequence_sharding_optimistic | |
sequence_sharding_removemeta | ||
drop_column_with_index | ||
gtid | ||
only_dml |