Skip to content

Commit

Permalink
add integration test case
Browse files Browse the repository at this point in the history
  • Loading branch information
asddongmen committed Dec 19, 2023
1 parent 2e9528e commit 4fd7ba8
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 19 deletions.
4 changes: 3 additions & 1 deletion cdc/owner/ddl_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ func (m *ddlManager) executeDDL(ctx context.Context) error {
"the DDL is not executed by Primary Cluster, skip it",
zap.String("namespace", m.changfeedID.Namespace),
zap.String("ID", m.changfeedID.ID),
zap.Any("ddlEvent", m.executingDDL))
zap.Any("ddlEvent", m.executingDDL),
zap.String("bdrRole", m.executingDDL.BDRRole))
tableName := m.executingDDL.TableInfo.TableName
// Set it to nil first to accelerate GC.
m.pendingDDLs[tableName][0] = nil
Expand Down Expand Up @@ -404,6 +405,7 @@ func (m *ddlManager) executeDDL(ctx context.Context) error {
tableName := m.executingDDL.TableInfo.TableName
log.Info("execute a ddl event successfully",
zap.String("ddl", m.executingDDL.Query),
zap.String("namespace", m.executingDDL.BDRRole),
zap.Uint64("commitTs", m.executingDDL.CommitTs),
zap.Stringer("table", tableName),
)
Expand Down
2 changes: 2 additions & 0 deletions tests/integration_tests/bdr_mode/data/down.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
admin set bdr role secondary;

use `bdr_mode`;

begin;
Expand Down
6 changes: 0 additions & 6 deletions tests/integration_tests/bdr_mode/data/start.sql

This file was deleted.

168 changes: 165 additions & 3 deletions tests/integration_tests/bdr_mode/data/up.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
admin set bdr role local_only;
drop database if exists `bdr_mode`;
admin set bdr role primary;
create database `bdr_mode`;
use `bdr_mode`;

create table `t1` (id int primary key, name varchar(20));
create table `t2` (id int primary key, name varchar(20));

begin;
insert into `t1` values (1, '1'), (3, '3'), (5, '5'), (7, '7'), (9, '9');
commit;
Expand All @@ -17,7 +24,162 @@ rollback;

insert into `t1` values (100, '100'), (300, '300'), (500, '500'), (700, '700'), (900, '900');

drop table `t2`;
create table `t2` (id int primary key, name varchar(20));
insert into `t2` values (1, '1'), (3, '3'), (5, '5'), (7, '7'), (9, '9');
insert into `t2` values (2, '2'), (4, '4'), (6, '6'), (8, '8'), (10, '10');
insert into `t2` values (2, '2'), (4, '4'), (6, '6'), (8, '8'), (10, '10');


/* Test ddl operation */

create table t3(
id int primary key,
name varchar(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
)
PARTITION BY RANGE (id)
(
PARTITION p0 VALUES LESS THAN (100),
PARTITION p1 VALUES LESS THAN (200),
PARTITION p2 VALUES LESS THAN (300),
PARTITION p3 VALUES LESS THAN (400)
);

create table t4(
id int primary key,
name varchar(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
UNIQUE KEY `idx_name_id` (`name`,`id`)
)
PARTITION BY RANGE (id)
(
PARTITION p0 VALUES LESS THAN (100),
PARTITION p1 VALUES LESS THAN (200),
PARTITION p2 VALUES LESS THAN (300),
PARTITION p3 VALUES LESS THAN (400)
);

INSERT INTO t3 (id, name) VALUES (1, 'John');
INSERT INTO t3 (id, name) VALUES (2, 'Emma');
INSERT INTO t3 (id, name) VALUES (3, 'Michael');
INSERT INTO t3 (id, name) VALUES (4, 'Sophia');
INSERT INTO t3 (id, name) VALUES (5, 'Daniel');


INSERT INTO t4 (id, name) VALUES (1, 'John');
INSERT INTO t4 (id, name) VALUES (2, 'Emma');
INSERT INTO t4 (id, name) VALUES (3, 'Michael');
INSERT INTO t4 (id, name) VALUES (4, 'Sophia');
INSERT INTO t4 (id, name) VALUES (5, 'Daniel');

-- create view
CREATE VIEW tv3 AS
SELECT name
FROM t3
WHERE name != "John";

-- create and drop view
CREATE VIEW tv4 AS
SELECT name
FROM t4
WHERE name != "Emma";

DROP VIEW tv4;

-- insert some data
INSERT INTO t3 (id, name) VALUES (6, 'John 2');
INSERT INTO t3 (id, name) VALUES (7, 'Emma 2');
INSERT INTO t4 (id, name) VALUES (8, 'Michael 2');
INSERT INTO t4 (id, name) VALUES (9, 'Sophia 2');

-- alter table add ttl
ALTER TABLE t3 TTL = `created_at` + INTERVAL 1 MONTH;
ALTER TABLE t3 TTL_ENABLE = 'OFF';


-- alter table add and remove ttl
ALTER TABLE t4 TTL = `created_at` + INTERVAL 1 MONTH;
ALTER TABLE t4 REMOVE TTL;


-- alter table comment
ALTER TABLE t3 COMMENT = 'test comment';
ALTER TABLE t3 COMMENT = 'test comment 2';

-- insert some data
INSERT INTO t3 (id, name) VALUES (10, 'Daniel 2');
INSERT INTO t3 (id, name) VALUES (11, 'John 3');
INSERT INTO t4 (id, name) VALUES (13, 'Michael 3');
INSERT INTO t4 (id, name) VALUES (14, 'Sophia 3');

-- add partition
ALTER TABLE t3 ADD PARTITION (PARTITION p4 VALUES LESS THAN (500));


-- insert some data
INSERT INTO t3 (id, name) VALUES (15, 'Daniel 3');
INSERT INTO t3 (id, name) VALUES (16, 'John 4');
INSERT INTO t4 (id, name) VALUES (17, 'Michael 4');
INSERT INTO t4 (id, name) VALUES (18, 'Sophia 4');

-- ALTER TABLE ALTER COLUME DEFAULT value
ALTER TABLE t3 ALTER COLUMN name SET DEFAULT 'test';

-- insert some data
INSERT INTO t3 (id, name) VALUES (19, 'Daniel 5');
INSERT INTO t3 (id, name) VALUES (20, 'John 5');
INSERT INTO t4 (id, name) VALUES (21, 'Michael 5');
INSERT INTO t4 (id, name) VALUES (22, 'Sophia 5');


-- add column that can be null
ALTER TABLE t3 ADD COLUMN age int;
-- add not null column with default value
ALTER TABLE t3 ADD COLUMN gender varchar(255) not null default 'male';

-- insert some data
INSERT INTO t3 (id, name) VALUES (23, 'Daniel 6');
INSERT INTO t3 (id, name) VALUES (24, 'John 6');
INSERT INTO t4 (id, name) VALUES (25, 'Michael 6');
INSERT INTO t4 (id, name) VALUES (26, 'Sophia 6');

-- add not unique index
ALTER TABLE t3 ADD INDEX idx_name (name);
ALTER TABLE t3 ADD INDEX idx_name_age (name, age);

-- insert some data
INSERT INTO t3 (id, name) VALUES (27, 'Daniel 7');
INSERT INTO t3 (id, name) VALUES (28, 'John 7');
INSERT INTO t4 (id, name) VALUES (29, 'Michael 7');
INSERT INTO t4 (id, name) VALUES (30, 'Sophia 7');


-- drop not unique index
ALTER TABLE t3 DROP INDEX idx_name_age;

-- insert some data
INSERT INTO t3 (id, name) VALUES (31, 'Daniel 8');
INSERT INTO t3 (id, name) VALUES (32, 'John 8');
INSERT INTO t4 (id, name) VALUES (33, 'Michael 8');
INSERT INTO t4 (id, name) VALUES (34, 'Sophia 8');

-- alter index name
ALTER TABLE t3 RENAME INDEX idx_name TO idx_name_new;

-- alter index visibility
ALTER TABLE t3 ALTER INDEX idx_name_new INVISIBLE;
ALTER TABLE t3 ALTER INDEX idx_name_new VISIBLE;

-- insert some data
INSERT INTO t3 (id, name) VALUES (35, 'Daniel 9');
INSERT INTO t3 (id, name) VALUES (36, 'John 9');
INSERT INTO t4 (id, name) VALUES (37, 'Michael 9');
INSERT INTO t4 (id, name) VALUES (38, 'Sophia 9');

-- drop UK
ALTER TABLE t4 DROP INDEX idx_name_id;


-- insert some data
INSERT INTO t3 (id, name) VALUES (39, 'Daniel 10');
INSERT INTO t3 (id, name) VALUES (40, 'John 10');
INSERT INTO t4 (id, name) VALUES (41, 'Michael 10');
INSERT INTO t4 (id, name) VALUES (42, 'Sophia 10');
9 changes: 0 additions & 9 deletions tests/integration_tests/bdr_mode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ function run() {
# up
SINK_URI_2="mysql://[email protected]:4000"

run_sql_file $CUR/data/start.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
run_sql_file $CUR/data/start.sql ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}
# the table must be created before starting the BDRmode changefeed
# since the BDRmode changefeed will ignore DDL
check_table_exists "bdr_mode.t1" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
check_table_exists "bdr_mode.t1" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}

# up -> down
run_cdc_cli changefeed create --sink-uri="$SINK_URI_1" -c "test-1" --config="$CUR/conf/cf.toml"
# down -> up
Expand All @@ -45,10 +38,8 @@ function run() {
run_sql_file $CUR/data/down.sql ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}

run_sql_file $CUR/data/finished.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
run_sql_file $CUR/data/finished.sql ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT}

check_table_exists "bdr_mode.finish_mark" ${UP_TIDB_HOST} ${UP_TIDB_PORT} 60
check_table_exists "bdr_mode.finish_mark" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 60

check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml

Expand Down

0 comments on commit 4fd7ba8

Please sign in to comment.