-
Notifications
You must be signed in to change notification settings - Fork 26
scheduler: fix bugs to make scheduler more robust #1941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
4 changes: 4 additions & 0 deletions
4
tests/integration_tests/ddl_for_split_tables_random_schedule/conf/changefeed.toml
This file contains hidden or 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,4 @@ | ||
[scheduler] | ||
enable-table-across-nodes = true | ||
region-threshold = 80 | ||
region-count-per-span = 10 |
28 changes: 28 additions & 0 deletions
28
tests/integration_tests/ddl_for_split_tables_random_schedule/conf/diff_config.toml
This file contains hidden or 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,28 @@ | ||
# diff Configuration. | ||
check-thread-count = 4 | ||
|
||
export-fix-sql = true | ||
|
||
check-struct-only = false | ||
|
||
[task] | ||
output-dir = "/tmp/tidb_cdc_test/ddl_for_split_tables_random_schedule/sync_diff/output" | ||
|
||
source-instances = ["tidb0"] | ||
|
||
target-instance = "mysql1" | ||
|
||
target-check-tables = ["test.*"] | ||
|
||
[data-sources] | ||
[data-sources.tidb0] | ||
host = "127.0.0.1" | ||
port = 4000 | ||
user = "root" | ||
password = "" | ||
|
||
[data-sources.mysql1] | ||
host = "127.0.0.1" | ||
port = 3306 | ||
user = "root" | ||
password = "" |
19 changes: 19 additions & 0 deletions
19
tests/integration_tests/ddl_for_split_tables_random_schedule/data/pre.sql
This file contains hidden or 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,19 @@ | ||
drop database if exists `test`; | ||
create database `test`; | ||
use `test`; | ||
create table table_1 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_2 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_3 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_4 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_5 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_6 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_7 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_8 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_9 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
create table table_10 (id INT AUTO_INCREMENT PRIMARY KEY, data VARCHAR(255)); | ||
|
||
split table test.table_1 between (1) and (200000) regions 100; | ||
split table test.table_2 between (1) and (200000) regions 100; | ||
split table test.table_3 between (1) and (200000) regions 100; | ||
split table test.table_4 between (1) and (200000) regions 100; | ||
split table test.table_5 between (1) and (200000) regions 100; |
95 changes: 95 additions & 0 deletions
95
tests/integration_tests/ddl_for_split_tables_random_schedule/run.sh
This file contains hidden or 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,95 @@ | ||
#!/bin/bash | ||
# This test is aimed to test the schedule process for split tables and non-split tables with dml | ||
# 1. we start three TiCDC servers, and create 5 split tables and 5 non-split tables. | ||
# 2. we enable the split table param, and start a changefeed. | ||
# 3. we execute dmls to these table. | ||
# finally, we check the data consistency between the upstream and downstream, and final dispatchers count of these tables, | ||
# to make sure the schedule process is correct. | ||
|
||
set -eu | ||
|
||
CUR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | ||
source $CUR/../_utils/test_prepare | ||
source $CUR/../_utils/execute_mixed_dml | ||
WORK_DIR=$OUT_DIR/$TEST_NAME | ||
CDC_BINARY=cdc.test | ||
SINK_TYPE=$1 | ||
check_time=60 | ||
|
||
function prepare() { | ||
rm -rf $WORK_DIR && mkdir -p $WORK_DIR | ||
|
||
start_tidb_cluster --workdir $WORK_DIR | ||
|
||
cd $WORK_DIR | ||
|
||
# record tso before we create tables to skip the system table DDLs | ||
start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1}) | ||
|
||
run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix "0" --addr "127.0.0.1:8300" | ||
run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix "1" --addr "127.0.0.1:8301" | ||
run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --logsuffix "2" --addr "127.0.0.1:8302" | ||
|
||
run_sql_file $CUR/data/pre.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT} | ||
|
||
TOPIC_NAME="ticdc-ddl-split-table-with-random-schedule-$RANDOM" | ||
case $SINK_TYPE in | ||
kafka) SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&kafka-version=${KAFKA_VERSION}&max-message-bytes=10485760" ;; | ||
storage) SINK_URI="file://$WORK_DIR/storage_test/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true" ;; | ||
pulsar) | ||
run_pulsar_cluster $WORK_DIR normal | ||
SINK_URI="pulsar://127.0.0.1:6650/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true" | ||
;; | ||
*) SINK_URI="mysql://root:@127.0.0.1:3306/" ;; | ||
esac | ||
do_retry 5 3 run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" -c "test" --config="$CUR/conf/changefeed.toml" | ||
case $SINK_TYPE in | ||
kafka) run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&version=${KAFKA_VERSION}&max-message-bytes=10485760" ;; | ||
storage) run_storage_consumer $WORK_DIR $SINK_URI "" "" ;; | ||
pulsar) run_pulsar_consumer --upstream-uri $SINK_URI ;; | ||
esac | ||
} | ||
|
||
function execute_dml() { | ||
table_name="table_$1" | ||
execute_mixed_dml "$table_name" "${UP_TIDB_HOST}" "${UP_TIDB_PORT}" | ||
} | ||
|
||
main() { | ||
prepare | ||
|
||
declare -a pids=() | ||
|
||
for i in {1..10}; do | ||
execute_dml $i & | ||
pids+=("$!") | ||
done | ||
|
||
sleep 200 | ||
|
||
kill -9 ${pids[@]} | ||
|
||
sleep 60 | ||
|
||
check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml 100 | ||
|
||
query_dispatcher_count "127.0.0.1:8300" "test" 36 100 le # 6 * 5 + 5 + 1 | ||
|
||
cdc_pid_1=$(pgrep -f "$CDC_BINARY.*--addr 127.0.0.1:8300") | ||
if [ -z "$cdc_pid_1" ]; then | ||
echo "ERROR: cdc server 1 is not running" | ||
exit 1 | ||
fi | ||
kill_cdc_pid $cdc_pid_1 | ||
|
||
sleep 60 | ||
|
||
query_dispatcher_count "127.0.0.1:8301" "test" 26 100 le # 4 * 5 + 5 + 1 | ||
|
||
cleanup_process $CDC_BINARY | ||
} | ||
|
||
trap stop_tidb_cluster EXIT | ||
main | ||
check_logs $WORK_DIR | ||
echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>" |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arithmetic comparison
[ "$value" -le "$target" ]
will cause the script to fail if$value
is not an integer (e.g., if it'snull
from thejq
command). The previous string comparison==
was safer in this regard. To make this more robust, you should check if$value
is an integer before performing the arithmetic comparison.