Skip to content

Commit

Permalink
feat(binlog): unsupported DDL in binlog layer should be filtered.(sto…
Browse files Browse the repository at this point in the history
…neatom#1186)

Add test case for filtering errors.
Filter the errors of secondary index、unique index、fulltext index、trigger、 foreign key in binlog layer.
  • Loading branch information
DandreChen committed Feb 2, 2023
1 parent b5a96d1 commit 82bc9e6
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 16 deletions.
9 changes: 1 addition & 8 deletions mysql-test/suite/tianmu/r/bit.result
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,7 @@ INSERT INTO t2 VALUES (3, 2, 'two'), (2, 3, 'three'), (2, 0, 'zero'),
(3, 2, 'two'), (3, 1, 'one');
DROP TABLE t2;
CREATE TABLE t1(a BIT(13), KEY(a));
INSERT IGNORE INTO t1(a) VALUES (65535),(65525),(65535),(65535),(65535),
(65535),(65535),(65535),(65535),(65535),
(65535),(65525),(65535),(65535),(65535),
(65535),(65535),(65535),(65535),(65535);
SELECT 1 FROM t1 GROUP BY a;
1
1
DROP TABLE t1;
ERROR HY000: Tianmu engine does not support secondary index.
CREATE TABLE t1 (b BIT NOT NULL, i2 INTEGER NOT NULL, s VARCHAR(255) NOT NULL);
INSERT INTO t1 VALUES(0x01,100,''), (0x00,300,''), (0x01,200,''), (0x00,100,'');
SELECT HEX(b), i2 FROM t1 WHERE (i2>=100 AND i2<201) AND b=TRUE;
Expand Down
131 changes: 131 additions & 0 deletions mysql-test/suite/tianmu/r/issue1186.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
include/master-slave.inc
[connection master]
DROP DATABASE IF EXISTS issue1186_test;
include/sync_slave_sql_with_master.inc
# on master:
CREATE DATABASE issue1186_test;
USE issue1186_test;
include/sync_slave_sql_with_master.inc
# on master:
show databases;
Database
information_schema
cache
issue1186_test
mtr
mysql
performance_schema
sys
sys_tianmu
test
#
# Secondary INDEX
#
# on master:
CREATE TABLE tb_stu_info1 (id int(11) NOT NULL, height int(11) DEFAULT NULL,KEY height (height)) ENGINE=INNODB;
CREATE TABLE tb_stu_info2 (id int(11) NOT NULL, height int(11) DEFAULT NULL,INDEX height (height)) ENGINE=INNODB;
CREATE TABLE tb_stu_info3 (id int, col_name varchar(10)) ENGINE=INNODB;
CREATE INDEX index_name ON tb_stu_info3(col_name);
ALTER TABLE tb_stu_info3 DROP INDEX index_name;
ALTER TABLE tb_stu_info3 add INDEX index_name (col_name) ;
ALTER TABLE tb_stu_info3 RENAME INDEX index_name TO index_name1;
ALTER TABLE tb_stu_info3 DROP INDEX index_name1;
ALTER TABLE tb_stu_info3 add KEY index_name (col_name) ;
ALTER TABLE tb_stu_info3 RENAME KEY index_name TO index_name2;
ALTER TABLE tb_stu_info3 DROP KEY index_name2;
include/sync_slave_sql_with_master.inc
# on slave:
show tables;
Tables_in_test
#
# UNIQUE INDEX
#
# on master:
CREATE TABLE tb_stu_info_1 (id int(11) NOT NULL, height int(11) DEFAULT NULL,UNIQUE KEY height (height)) ENGINE=INNODB;
CREATE TABLE tb_stu_info_2 (id int(11) NOT NULL, height int(11) DEFAULT NULL,UNIQUE INDEX height (height)) ENGINE=INNODB;
CREATE TABLE tb_stu_info_3 (id int(11) NOT NULL, height int(11) DEFAULT NULL) ENGINE=INNODB;
ALTER TABLE tb_stu_info_3 ADD CONSTRAINT constraint_name UNIQUE INDEX(height);
ALTER TABLE tb_stu_info_3 RENAME INDEX constraint_name TO constraint_name1;
ALTER TABLE tb_stu_info_3 DROP INDEX constraint_name1;
ALTER TABLE tb_stu_info_3 ADD CONSTRAINT constraint_name UNIQUE KEY(height);
ALTER TABLE tb_stu_info_3 RENAME KEY constraint_name TO constraint_name2;
ALTER TABLE tb_stu_info_3 DROP KEY constraint_name2;
CREATE UNIQUE INDEX index_name ON tb_stu_info_3(height);
include/sync_slave_sql_with_master.inc
# on slave:
show tables;
Tables_in_test
#
# FULL INDEX
#
# on master:
CREATE TABLE tb_posts1 (id int(4) NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL,
post_content text,
PRIMARY KEY (id),
FULLTEXT KEY post_content (post_content)
)ENGINE=INNODB;
CREATE TABLE tb_posts2 (id int(4) NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL,
post_content text,
PRIMARY KEY (id)
)ENGINE=INNODB;
ALTER TABLE tb_posts2 ADD FULLTEXT INDEX index_name (post_content);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
ALTER TABLE tb_posts2 DROP INDEX index_name;
CREATE FULLTEXT INDEX index_name ON tb_posts2 (post_content);
DROP INDEX index_name ON tb_posts2;
include/sync_slave_sql_with_master.inc
# on slave:
show tables;
Tables_in_test
#
# TRIGGER
#
# on master:
CREATE TABLE employees(
id INT auto_increment PRIMARY KEY,
employeeNumber INT NOT NULL,
lastname VARCHAR(50) NOT NULL,
action VARCHAR(50) DEFAULT NULL) ENGINE=INNODB;
CREATE TABLE employees_audit(
id INT auto_increment PRIMARY KEY,
employeeNumber INT NOT NULL,
lastname VARCHAR(50) NOT NULL,
action VARCHAR(50) DEFAULT NULL) ENGINE=INNODB;
CREATE TABLE employees_audit2(
id INT auto_increment PRIMARY KEY,
employeeNumber INT NOT NULL,
lastname VARCHAR(50) NOT NULL,
action VARCHAR(50) DEFAULT NULL) ENGINE=INNODB;
CREATE TRIGGER before_employee_update
BEFORE UPDATE ON employees
FOR EACH ROW
BEGIN
INSERT INTO employees_audit
SET action = 'update',
employeeNumber = 1,
lastname = "nihao",
new_lastname = "niyehao";
END |
include/sync_slave_sql_with_master.inc
# on slave:
show triggers;
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
# on master:
DROP DATABASE issue1186_test;
include/sync_slave_sql_with_master.inc
# on slave:
show databases;
Database
information_schema
cache
mtr
mysql
performance_schema
sys
sys_tianmu
test
tianmu_data
stop slave;
17 changes: 9 additions & 8 deletions mysql-test/suite/tianmu/t/bit.test
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,16 @@ INSERT INTO t2 VALUES (3, 2, 'two'), (2, 3, 'three'), (2, 0, 'zero'),
#bug928 SELECT COUNT(DISTINCT b,c) FROM t2 GROUP BY a;
DROP TABLE t2;

--error 3234
CREATE TABLE t1(a BIT(13), KEY(a));
--disable_warnings
INSERT IGNORE INTO t1(a) VALUES (65535),(65525),(65535),(65535),(65535),
(65535),(65535),(65535),(65535),(65535),
(65535),(65525),(65535),(65535),(65535),
(65535),(65535),(65535),(65535),(65535);
--enable_warnings
SELECT 1 FROM t1 GROUP BY a;
DROP TABLE t1;
#--disable_warnings
#INSERT IGNORE INTO t1(a) VALUES (65535),(65525),(65535),(65535),(65535),
# (65535),(65535),(65535),(65535),(65535),
# (65535),(65525),(65535),(65535),(65535),
# (65535),(65535),(65535),(65535),(65535);
#--enable_warnings
#SELECT 1 FROM t1 GROUP BY a;
#DROP TABLE t1;

#SELECT with a BIT column in WHERE clause returns unexpected result

Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/tianmu/t/issue1186-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--default-storage-engine=InnoDB
1 change: 1 addition & 0 deletions mysql-test/suite/tianmu/t/issue1186-slave.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sql_mode='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,MANDATORY_TIANMU'
173 changes: 173 additions & 0 deletions mysql-test/suite/tianmu/t/issue1186.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
--source include/have_tianmu.inc
--source include/have_binlog_format_row.inc

--disable_warnings
-- source include/master-slave.inc
DROP DATABASE IF EXISTS issue1186_test;
--enable_warnings

--source include/sync_slave_sql_with_master.inc

connection master;
--echo # on master:

CREATE DATABASE issue1186_test;

USE issue1186_test;

--source include/sync_slave_sql_with_master.inc
--echo # on master:
show databases;

--echo #
--echo # Secondary INDEX
--echo #

connection master;
--echo # on master:

CREATE TABLE tb_stu_info1 (id int(11) NOT NULL, height int(11) DEFAULT NULL,KEY height (height)) ENGINE=INNODB;

CREATE TABLE tb_stu_info2 (id int(11) NOT NULL, height int(11) DEFAULT NULL,INDEX height (height)) ENGINE=INNODB;

CREATE TABLE tb_stu_info3 (id int, col_name varchar(10)) ENGINE=INNODB;

CREATE INDEX index_name ON tb_stu_info3(col_name);

ALTER TABLE tb_stu_info3 DROP INDEX index_name;

ALTER TABLE tb_stu_info3 add INDEX index_name (col_name) ;

ALTER TABLE tb_stu_info3 RENAME INDEX index_name TO index_name1;

ALTER TABLE tb_stu_info3 DROP INDEX index_name1;

ALTER TABLE tb_stu_info3 add KEY index_name (col_name) ;

ALTER TABLE tb_stu_info3 RENAME KEY index_name TO index_name2;

ALTER TABLE tb_stu_info3 DROP KEY index_name2;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show tables;

--echo #
--echo # UNIQUE INDEX
--echo #

connection master;
--echo # on master:

CREATE TABLE tb_stu_info_1 (id int(11) NOT NULL, height int(11) DEFAULT NULL,UNIQUE KEY height (height)) ENGINE=INNODB;

CREATE TABLE tb_stu_info_2 (id int(11) NOT NULL, height int(11) DEFAULT NULL,UNIQUE INDEX height (height)) ENGINE=INNODB;

CREATE TABLE tb_stu_info_3 (id int(11) NOT NULL, height int(11) DEFAULT NULL) ENGINE=INNODB;

ALTER TABLE tb_stu_info_3 ADD CONSTRAINT constraint_name UNIQUE INDEX(height);

ALTER TABLE tb_stu_info_3 RENAME INDEX constraint_name TO constraint_name1;

ALTER TABLE tb_stu_info_3 DROP INDEX constraint_name1;

ALTER TABLE tb_stu_info_3 ADD CONSTRAINT constraint_name UNIQUE KEY(height);

ALTER TABLE tb_stu_info_3 RENAME KEY constraint_name TO constraint_name2;

ALTER TABLE tb_stu_info_3 DROP KEY constraint_name2;

CREATE UNIQUE INDEX index_name ON tb_stu_info_3(height);

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show tables;

--echo #
--echo # FULL INDEX
--echo #

connection master;
--echo # on master:

CREATE TABLE tb_posts1 (id int(4) NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL,
post_content text,
PRIMARY KEY (id),
FULLTEXT KEY post_content (post_content)
)ENGINE=INNODB;

# is wrong
# ALTER TABLE tb_posts1 DROP KEY post_content;

CREATE TABLE tb_posts2 (id int(4) NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL,
post_content text,
PRIMARY KEY (id)
)ENGINE=INNODB;

ALTER TABLE tb_posts2 ADD FULLTEXT INDEX index_name (post_content);

ALTER TABLE tb_posts2 DROP INDEX index_name;

CREATE FULLTEXT INDEX index_name ON tb_posts2 (post_content);

DROP INDEX index_name ON tb_posts2;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show tables;

--echo #
--echo # TRIGGER
--echo #

connection master;
--echo # on master:

CREATE TABLE employees(
id INT auto_increment PRIMARY KEY,
employeeNumber INT NOT NULL,
lastname VARCHAR(50) NOT NULL,
action VARCHAR(50) DEFAULT NULL) ENGINE=INNODB;

CREATE TABLE employees_audit(
id INT auto_increment PRIMARY KEY,
employeeNumber INT NOT NULL,
lastname VARCHAR(50) NOT NULL,
action VARCHAR(50) DEFAULT NULL) ENGINE=INNODB;

CREATE TABLE employees_audit2(
id INT auto_increment PRIMARY KEY,
employeeNumber INT NOT NULL,
lastname VARCHAR(50) NOT NULL,
action VARCHAR(50) DEFAULT NULL) ENGINE=INNODB;


DELIMITER |;
CREATE TRIGGER before_employee_update
BEFORE UPDATE ON employees
FOR EACH ROW
BEGIN
INSERT INTO employees_audit
SET action = 'update',
employeeNumber = 1,
lastname = "nihao",
new_lastname = "niyehao";
END |
DELIMITER ;|

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show triggers;


connection master;
--echo # on master:

DROP DATABASE issue1186_test;

--source include/sync_slave_sql_with_master.inc
--echo # on slave:
show databases;
stop slave;
14 changes: 14 additions & 0 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4972,6 +4972,20 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
thd->killed= THD::NOT_KILLED;
}
/*
Tianmu engine as slave: ignore some errors
*/
else if(ER_TIANMU_NOT_SUPPORTED_SECONDARY_INDEX == actual_error
|| ER_TIANMU_NOT_SUPPORTED_UNIQUE_INDEX == actual_error
|| ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX == actual_error
|| ER_TIANMU_NOT_SUPPORTED_TRIGGER == actual_error
|| ER_TIANMU_NOT_SUPPORTED_FOREIGN_KEY == actual_error
|| ER_TIANMU_NOT_FOUND_INDEX == actual_error)
{
DBUG_PRINT("info",("error ignored"));
clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
thd->killed= THD::NOT_KILLED;
}
/*
Other cases: mostly we expected no error and get one.
*/
Expand Down

0 comments on commit 82bc9e6

Please sign in to comment.