Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.

Commit 967ee5c

Browse files
authored
*: use show full tables in ListAllDatabasesTables (#325) (#333)
1 parent c7254f0 commit 967ee5c

File tree

14 files changed

+360
-47
lines changed

14 files changed

+360
-47
lines changed

.github/workflows/go.yml

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,113 @@ jobs:
2929
run: make test WITH_RACE=1
3030
- uses: codecov/codecov-action@v1
3131

32-
integration-test:
32+
integration-test-mysql-5735:
3333
runs-on: ubuntu-latest
3434
timeout-minutes: 15
3535
strategy:
3636
fail-fast: true
37+
services:
38+
mysql:
39+
image: mysql:5.7.35
40+
env:
41+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
42+
ports:
43+
- 3306:3306
44+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
3745
steps:
3846
- uses: actions/checkout@v2
47+
- name: Shutdown Ubuntu MySQL (SUDO)
48+
run: sudo service mysql stop # Shutdown the Default MySQL, "sudo" is necessary, please not remove it
3949
- name: Set up Go 1.16
4050
uses: actions/setup-go@v2
4151
with:
4252
go-version: 1.16
53+
- uses: actions/cache@v2
54+
with:
55+
path: ~/go/pkg/mod
56+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
57+
restore-keys: |
58+
${{ runner.os }}-go-
59+
- name: Get dependencies
60+
run: go mod download
61+
- name: Download dependencies
62+
run: sh install.sh
63+
- name: Integration test
64+
run: make integration_test
65+
- name: Set up tmate session
66+
if: ${{ failure() }}
67+
uses: mxschmitt/action-tmate@v3
68+
69+
integration-test-mysql-8026:
70+
runs-on: ubuntu-latest
71+
timeout-minutes: 15
72+
strategy:
73+
fail-fast: true
74+
services:
75+
mysql:
76+
image: mysql:8.0.26
77+
env:
78+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
79+
ports:
80+
- 3306:3306
81+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
82+
steps:
83+
- uses: actions/checkout@v2
84+
- name: Shutdown Ubuntu MySQL (SUDO)
85+
run: sudo service mysql stop # Shutdown the Default MySQL, "sudo" is necessary, please not remove it
86+
- name: Set up Go 1.16
87+
uses: actions/setup-go@v2
88+
with:
89+
go-version: 1.16
90+
- uses: actions/cache@v2
91+
with:
92+
path: ~/go/pkg/mod
93+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
94+
restore-keys: |
95+
${{ runner.os }}-go-
96+
- name: Get dependencies
97+
run: go mod download
98+
- name: Download dependencies
99+
run: sh install.sh
100+
- name: Integration test
101+
run: make integration_test
102+
- name: Set up tmate session
103+
if: ${{ failure() }}
104+
uses: mxschmitt/action-tmate@v3
105+
106+
integration-test-mysql-8022:
107+
runs-on: ubuntu-latest
108+
timeout-minutes: 15
109+
strategy:
110+
fail-fast: true
111+
services:
112+
mysql:
113+
image: mysql:8.0.22
114+
env:
115+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
116+
ports:
117+
- 3306:3306
118+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
119+
steps:
120+
- uses: actions/checkout@v2
121+
- name: Shutdown Ubuntu MySQL (SUDO)
122+
run: sudo service mysql stop # Shutdown the Default MySQL, "sudo" is necessary, please not remove it
123+
- name: Set up Go 1.16
124+
uses: actions/setup-go@v2
125+
with:
126+
go-version: 1.16
127+
- uses: actions/cache@v2
128+
with:
129+
path: ~/go/pkg/mod
130+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
131+
restore-keys: |
132+
${{ runner.os }}-go-
133+
- name: Get dependencies
134+
run: go mod download
43135
- name: Download dependencies
44136
run: sh install.sh
45-
- name: Start MySQL
46-
run: |
47-
sudo systemctl start mysql.service
48-
mysqladmin -uroot -proot password ''
49137
- name: Integration test
50138
run: make integration_test
139+
- name: Set up tmate session
140+
if: ${{ failure() }}
141+
uses: mxschmitt/action-tmate@v3

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test: failpoint-enable
2929

3030
integration_test: bins failpoint-enable bin/dumpling
3131
@make failpoint-disable
32-
./tests/run.sh
32+
./tests/run.sh $(CASE)
3333

3434
tools:
3535
@echo "install tools..."
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*!40101 SET NAMES binary*/;
2+
CREATE DATABASE `quo``te/database` /*!40100 DEFAULT CHARACTER SET latin1 */;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*!40101 SET NAMES binary*/;
2+
CREATE TABLE `quo``te/table` (
3+
`quo``te/col` int(11) NOT NULL,
4+
`a` int(11) DEFAULT NULL,
5+
`gen``id` int(11) GENERATED ALWAYS AS (`quo``te/col`) VIRTUAL,
6+
PRIMARY KEY (`quo``te/col`)
7+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*!40101 SET NAMES binary*/;
2+
INSERT INTO `quo``te/table` (`quo``te/col`,`a`) VALUES
3+
(0,10),
4+
(1,9),
5+
(2,8),
6+
(3,7),
7+
(4,6),
8+
(5,5),
9+
(6,4),
10+
(7,3),
11+
(8,2),
12+
(9,1),
13+
(10,0);

tests/quote/run.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
44

55
set -eu
66

77
mkdir -p "$DUMPLING_OUTPUT_DIR"/data
8-
cp "$DUMPLING_BASE_NAME/data/quote-database.quote-table.000000000.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase.quo\`te%2Ftable.000000000.sql"
9-
cp "$DUMPLING_BASE_NAME/data/quote-database.quote-table-schema.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase.quo\`te%2Ftable-schema.sql"
10-
cp "$DUMPLING_BASE_NAME/data/quote-database-schema-create.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase-schema-create.sql"
8+
9+
mysql_version=$(echo "select version()" | mysql -uroot -h127.0.0.1 -P3306 | awk 'NR==2' | awk '{print $1}')
10+
echo "current user mysql version is $mysql_version"
11+
if [[ $mysql_version = 5* ]]; then
12+
# there is a bug in mysql 5.x, see https://bugs.mysql.com/bug.php?id=96994, so we use different create db/table sql
13+
cp "$DUMPLING_BASE_NAME/data/quote-database.quote-table.000000000-mysql57.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase.quo\`te%2Ftable.000000000.sql"
14+
cp "$DUMPLING_BASE_NAME/data/quote-database.quote-table-schema-mysql57.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase.quo\`te%2Ftable-schema.sql"
15+
cp "$DUMPLING_BASE_NAME/data/quote-database-schema-create-mysql57.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase-schema-create.sql"
16+
else
17+
cp "$DUMPLING_BASE_NAME/data/quote-database.quote-table.000000000.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase.quo\`te%2Ftable.000000000.sql"
18+
cp "$DUMPLING_BASE_NAME/data/quote-database.quote-table-schema.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase.quo\`te%2Ftable-schema.sql"
19+
cp "$DUMPLING_BASE_NAME/data/quote-database-schema-create.sql" "$DUMPLING_OUTPUT_DIR/data/quo\`te%2Fdatabase-schema-create.sql"
20+
fi
1121

1222
db="quo\`te/database"
1323
run_sql "drop database if exists \`quo\`\`te/database\`"

tests/run.sh

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
44

@@ -17,7 +17,6 @@ mkdir -p "$DUMPLING_TEST_DIR"
1717
PATH="tests/_utils:$PATH"
1818
. "tests/_utils/run_services"
1919

20-
2120
file_should_exist bin/tidb-server
2221
file_should_exist bin/tidb-lightning
2322
file_should_exist bin/dumpling
@@ -26,20 +25,34 @@ file_should_exist bin/sync_diff_inspector
2625
trap stop_services EXIT
2726
start_services
2827

29-
for script in tests/*/run.sh; do
30-
echo "****************** Running test $script..."
28+
run_case_by_fullpath() {
29+
script="$1"
30+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Running test $script..."
3131
DUMPLING_BASE_NAME="$(dirname "$script")"
3232
export DUMPLING_BASE_NAME
3333
TEST_NAME="$(basename "$(dirname "$script")")"
3434
DUMPLING_OUTPUT_DIR="$DUMPLING_TEST_DIR"/sql_res."$TEST_NAME"
3535
export DUMPLING_OUTPUT_DIR
3636

3737
PATH="tests/_utils:$PATH" \
38-
sh "$script"
39-
40-
echo "Cleaning up test output dir: $DUMPLING_OUTPUT_DIR"
38+
bash "$script"
39+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>TEST: $script Passed Cleaning up test output dir: $DUMPLING_OUTPUT_DIR"
4140
rm -rf "$DUMPLING_OUTPUT_DIR"
42-
43-
done
44-
45-
echo "Passed integration tests."
41+
}
42+
43+
if [ "$#" -ge 1 ]; then
44+
test_case="$@"
45+
else
46+
test_case="*"
47+
fi
48+
49+
if [ "$test_case" == "*" ]; then
50+
for script in tests/*/run.sh; do
51+
run_case_by_fullpath "$script"
52+
done
53+
else
54+
script="tests/$test_case/run.sh"
55+
run_case_by_fullpath "$script"
56+
fi
57+
58+
echo "Passed integration tests."

tests/views/run.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ run_sql_file "$DUMPLING_BASE_NAME/data/views-schema-create.sql"
99
export DUMPLING_TEST_DATABASE="views"
1010

1111
run_sql "create table t (a bigint, b varchar(255))"
12-
run_sql "set session collation_connection='utf8mb4_general_ci'; create definer = 'root'@'localhost' view v as select * from t;"
12+
run_sql_file "$DUMPLING_BASE_NAME/data/views.v-schema-view.sql"
13+
1314
# insert 20 records to `t`.
1415
run_sql "insert into t values $(seq -s, 20 | sed 's/,*$//g' | sed 's/[0-9]*/(\0,"\0")/g')"
1516

v4/export/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,16 @@ func adjustFileFormat(conf *Config) error {
706706
}
707707
return nil
708708
}
709+
710+
func matchMysqlBugversion(info ServerInfo) bool {
711+
// if 8.0.3 <= mysql8 version < 8.0.23
712+
// FLUSH TABLES WITH READ LOCK could block other sessions from executing SHOW TABLE STATUS.
713+
// see more in https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-23.html
714+
if info.ServerType != ServerTypeMySQL {
715+
return false
716+
}
717+
currentVersion := info.ServerVersion
718+
bugVersionStart := semver.New("8.0.2")
719+
bugVersionEnd := semver.New("8.0.23")
720+
return bugVersionStart.LessThan(*currentVersion) && currentVersion.LessThan(*bugVersionEnd)
721+
}

v4/export/config_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package export
44

55
import (
6-
"context"
6+
tcontext "github.com/pingcap/dumpling/v4/context"
77

88
. "github.com/pingcap/check"
99
)
@@ -14,7 +14,24 @@ type testConfigSuite struct{}
1414

1515
func (s *testConfigSuite) TestCreateExternalStorage(c *C) {
1616
mockConfig := defaultConfigForTest(c)
17-
loc, err := mockConfig.createExternalStorage(context.Background())
17+
loc, err := mockConfig.createExternalStorage(tcontext.Background())
1818
c.Assert(err, IsNil)
1919
c.Assert(loc.URI(), Matches, "file:.*")
2020
}
21+
22+
func (s *testConfigSuite) TestMatchMysqlBugversion(c *C) {
23+
cases := []struct {
24+
serverInfo ServerInfo
25+
expected bool
26+
}{
27+
{ParseServerInfo(tcontext.Background(), "5.7.25-TiDB-3.0.6"), false},
28+
{ParseServerInfo(tcontext.Background(), "8.0.2"), false},
29+
{ParseServerInfo(tcontext.Background(), "8.0.3"), true},
30+
{ParseServerInfo(tcontext.Background(), "8.0.22"), true},
31+
{ParseServerInfo(tcontext.Background(), "8.0.23"), false},
32+
}
33+
for _, x := range cases {
34+
cmt := Commentf("server info %s", x.serverInfo)
35+
c.Assert(x.expected, Equals, matchMysqlBugversion(x.serverInfo), cmt)
36+
}
37+
}

0 commit comments

Comments
 (0)