-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lightning: check hasDupe and tableID when resolve duplicate rows (#40696
- Loading branch information
1 parent
c0ec81b
commit dc1ebbe
Showing
10 changed files
with
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
# | ||
# 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, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eux | ||
|
||
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/lightning/EnableTestAPI=return" | ||
export GO_FAILPOINTS="${GO_FAILPOINTS};github.com/pingcap/tidb/br/pkg/lightning/backend/local/ReadyForImportEngine=sleep(10000)" | ||
|
||
run_lightning --backend='local' & | ||
shpid="$!" | ||
pid= | ||
|
||
ensure_lightning_is_started() { | ||
for _ in {0..60}; do | ||
pid=$(pstree -p "$shpid" | grep -Eo "tidb-lightning\.\([0-9]*\)" | grep -Eo "[0-9]*") || true | ||
[ -n "$pid" ] && break | ||
sleep 1 | ||
done | ||
if [ -z "$pid" ]; then | ||
echo "lightning doesn't start successfully, please check the log" >&2 | ||
exit 1 | ||
fi | ||
echo "lightning is started, pid is $pid" | ||
} | ||
|
||
ready_for_import_engine() { | ||
for _ in {0..60}; do | ||
grep -Fq "start import engine" "$TEST_DIR"/lightning.log && return | ||
sleep 1 | ||
done | ||
echo "lightning doesn't start import engine, please check the log" >&2 | ||
exit 1 | ||
} | ||
|
||
ensure_lightning_is_started | ||
ready_for_import_engine | ||
|
||
run_curl "https://${PD_ADDR}/pd/api/v1/config/cluster-version" | ||
|
||
length=$(run_curl "https://${PD_ADDR}/pd/api/v1/config/region-label/rules" | jq '[ .[] | select(.rule_type == "key-range" and .labels[0].key == "schedule") ] | length') | ||
if [ "$length" != "1" ]; then | ||
echo "region-label key-range schedule rules should be 1, but got $length" >&2 | ||
exit 1 | ||
fi | ||
|
||
wait "$shpid" | ||
|
||
length=$(run_curl "https://${PD_ADDR}/pd/api/v1/config/region-label/rules" | jq '[ .[] | select(.rule_type == "key-range" and .labels[0].key == "schedule") ] | length') | ||
if [ -n "$length" ] && [ "$length" -ne 0 ]; then | ||
echo "region-label key-range schedule rules should be 0, but got $length" >&2 | ||
exit 1 | ||
fi |
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 @@ | ||
[tikv-importer] | ||
backend = "local" | ||
duplicate-resolution = "remove" | ||
|
||
[mydumper.csv] | ||
header = true |
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 @@ | ||
CREATE TABLE `t` ( | ||
`id` int(11) NOT NULL, | ||
`name` varchar(255) DEFAULT NULL, | ||
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, | ||
UNIQUE KEY `uni_name` (`name`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; |
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 @@ | ||
id,name | ||
1,"aaa01" | ||
2,"aaa02" | ||
3,"aaa03" | ||
4,"aaa04" | ||
5,"aaa04" |
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 @@ | ||
CREATE TABLE `t` ( | ||
`id` int(11) NOT NULL, | ||
`name` varchar(255) DEFAULT NULL, | ||
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, | ||
UNIQUE KEY `uni_name` (`name`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; |
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 @@ | ||
id,name | ||
1,"aaa01" | ||
2,"aaa02" | ||
3,"aaa03" | ||
4,"aaa04" | ||
5,"aaa05" |
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,32 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2023 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, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eux | ||
|
||
check_cluster_version 5 2 0 'duplicate detection' || exit 0 | ||
|
||
run_lightning -d "tests/$TEST_NAME/data1" | ||
run_sql 'admin check table test.t' | ||
run_sql 'select count(*) from test.t' | ||
check_contains 'count(*): 3' | ||
run_sql 'select count(*) from lightning_task_info.conflict_error_v1' | ||
check_contains 'count(*): 2' | ||
|
||
run_sql 'truncate table test.t' | ||
run_lightning -d "tests/$TEST_NAME/data2" | ||
run_sql 'admin check table test.t' | ||
run_sql 'select count(*) from test.t' | ||
check_contains 'count(*): 5' |
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