Skip to content

Commit

Permalink
fix(tianm): fix problems related to master slave synchronization (sto…
Browse files Browse the repository at this point in the history
…neatom#819)

1. sql/sql_insert.cc Fix the problem that the insert statement will not generate binlog in the delayed insert mode
2. storage/tianmu/handler/tianmu_handler.cpp Fix the binlog error of the line format generated by the tianmu engine
  • Loading branch information
konghaiya committed Oct 31, 2022
1 parent f22c03a commit 8d32f51
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 48 deletions.
177 changes: 177 additions & 0 deletions mysql-test/suite/tianmu/r/issue819.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
include/master-slave.inc
Warnings:
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
[connection master]
#
# Test the master-slave function of innodb
#
# connection master
use test;
create table ttt(id int primary key,name varchar(5))engine=innodb;
insert into ttt values(1,'AAA');
delete from ttt where id=1;
insert into ttt values(1,'aaa');
select * from ttt;
id name
1 aaa
# connection slave
include/sync_slave_sql_with_master.inc
select * from ttt;
id name
1 aaa
# connection master
drop table ttt;
include/sync_slave_sql_with_master.inc
# connection master
CREATE TABLE t1 (a int not null,b int not null)engine=innodb;
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b))engine=innodb;
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b))engine=innodb;
insert into t1 values (1,1),(2,1),(1,3);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(1,3);
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
select * from t1;
a b
1 1
2 1
1 3
select * from t2;
a b
3 3
select * from t3;
a b
# connection slave
include/sync_slave_sql_with_master.inc
select * from t1;
a b
1 1
2 1
1 3
select * from t2;
a b
3 3
select * from t3;
a b
# connection master
drop table t1,t2,t3;
include/sync_slave_sql_with_master.inc
# connection master
CREATE TABLE t1
(
place_id int (10) unsigned NOT NULL,
shows int(10) unsigned DEFAULT '0' NOT NULL,
ishows int(10) unsigned DEFAULT '0' NOT NULL,
ushows int(10) unsigned DEFAULT '0' NOT NULL,
clicks int(10) unsigned DEFAULT '0' NOT NULL,
iclicks int(10) unsigned DEFAULT '0' NOT NULL,
uclicks int(10) unsigned DEFAULT '0' NOT NULL,
ts timestamp,
PRIMARY KEY (place_id,ts)
)engine=innodb;
INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
VALUES (1,0,0,0,0,0,0,20000928174434);
UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1 AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;
place_id shows
1 1
# connection slave
include/sync_slave_sql_with_master.inc
select place_id,shows from t1;
place_id shows
1 1
# connection master
drop table t1;
include/sync_slave_sql_with_master.inc
#
# Test the master-slave function of tianmu
#
# connection master
use test;
create table ttt(id int primary key,name varchar(5))engine=tianmu;
insert into ttt values(1,'AAA');
update ttt set name='hhhh' where id=1;
select * from ttt;
id name
1 hhhh
# connection slave
include/sync_slave_sql_with_master.inc
select * from ttt;
id name
1 hhhh
# connection master
drop table ttt;
include/sync_slave_sql_with_master.inc
# connection master
create table t1(id int primary key,name varchar(5))engine=tianmu;
insert into t1 values(1,'AAA');
delete from t1 where id=1;
insert into t1 values(1,'aaa');
select * from t1;
id name
1 aaa
# connection slave
include/sync_slave_sql_with_master.inc
select * from t1;
id name
1 aaa
# connection master
drop table t1;
CREATE TABLE t1 (a int not null,b int not null)engine=tianmu;
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b))engine=tianmu;
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b))engine=tianmu;
insert into t1 values (1,1),(2,1),(1,3);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(1,3);
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
select * from t1;
a b
1 1
2 1
1 3
select * from t2;
a b
3 3
select * from t3;
a b
# connection slave
include/sync_slave_sql_with_master.inc
select * from t1;
a b
1 1
2 1
1 3
select * from t2;
a b
3 3
select * from t3;
a b
# connection master
drop table t1,t2,t3;
include/sync_slave_sql_with_master.inc
# connection master
CREATE TABLE t1
(
place_id int (10),
shows int(10),
ishows int(10),
ushows int(10),
clicks int(10),
iclicks int(10),
uclicks int(10),
ts timestamp,
PRIMARY KEY (place_id,ts)
)engine=tianmu;
INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
VALUES (1,0,0,0,0,0,0,20000928174434);
UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1 AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;
place_id shows
1 1
# connection slave
include/sync_slave_sql_with_master.inc
select place_id,shows from t1;
place_id shows
1 1
# connection master
drop table t1;
170 changes: 170 additions & 0 deletions mysql-test/suite/tianmu/t/issue819.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
-- source include/have_tianmu.inc
-- source include/master-slave.inc

--echo #
--echo # Test the master-slave function of innodb
--echo #

--echo # connection master
connection master;
use test;
create table ttt(id int primary key,name varchar(5))engine=innodb;
insert into ttt values(1,'AAA');
delete from ttt where id=1;
insert into ttt values(1,'aaa');
select * from ttt;

--echo # connection slave
--source include/sync_slave_sql_with_master.inc

select * from ttt;

--echo # connection master
connection master;
drop table ttt;
--source include/sync_slave_sql_with_master.inc

--echo # connection master
connection master;
CREATE TABLE t1 (a int not null,b int not null)engine=innodb;
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b))engine=innodb;
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b))engine=innodb;
insert into t1 values (1,1),(2,1),(1,3);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(1,3);
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;

select * from t1;
select * from t2;
select * from t3;

--echo # connection slave
--source include/sync_slave_sql_with_master.inc

select * from t1;
select * from t2;
select * from t3;

--echo # connection master
connection master;
drop table t1,t2,t3;
--source include/sync_slave_sql_with_master.inc

--echo # connection master
connection master;
CREATE TABLE t1
(
place_id int (10) unsigned NOT NULL,
shows int(10) unsigned DEFAULT '0' NOT NULL,
ishows int(10) unsigned DEFAULT '0' NOT NULL,
ushows int(10) unsigned DEFAULT '0' NOT NULL,
clicks int(10) unsigned DEFAULT '0' NOT NULL,
iclicks int(10) unsigned DEFAULT '0' NOT NULL,
uclicks int(10) unsigned DEFAULT '0' NOT NULL,
ts timestamp,
PRIMARY KEY (place_id,ts)
)engine=innodb;

INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
VALUES (1,0,0,0,0,0,0,20000928174434);
UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1 AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;

--echo # connection slave
--source include/sync_slave_sql_with_master.inc
select place_id,shows from t1;

--echo # connection master
connection master;
drop table t1;
--source include/sync_slave_sql_with_master.inc

--echo #
--echo # Test the master-slave function of tianmu
--echo #

--echo # connection master
connection master;
use test;
create table ttt(id int primary key,name varchar(5))engine=tianmu;
insert into ttt values(1,'AAA');
update ttt set name='hhhh' where id=1;
select * from ttt;

--echo # connection slave
--source include/sync_slave_sql_with_master.inc

select * from ttt;

--echo # connection master
connection master;
drop table ttt;
--source include/sync_slave_sql_with_master.inc

--echo # connection master
connection master;
create table t1(id int primary key,name varchar(5))engine=tianmu;
insert into t1 values(1,'AAA');
delete from t1 where id=1;
insert into t1 values(1,'aaa');
select * from t1;

--echo # connection slave
--source include/sync_slave_sql_with_master.inc
select * from t1;

--echo # connection master
connection master;
drop table t1;

CREATE TABLE t1 (a int not null,b int not null)engine=tianmu;
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b))engine=tianmu;
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b))engine=tianmu;
insert into t1 values (1,1),(2,1),(1,3);
insert into t2 values (1,1),(2,2),(3,3);
insert into t3 values (1,1),(2,1),(1,3);
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;

select * from t1;
select * from t2;
select * from t3;

--echo # connection slave
--source include/sync_slave_sql_with_master.inc

select * from t1;
select * from t2;
select * from t3;

--echo # connection master
connection master;
drop table t1,t2,t3;
--source include/sync_slave_sql_with_master.inc

--echo # connection master
connection master;
CREATE TABLE t1
(
place_id int (10),
shows int(10),
ishows int(10),
ushows int(10),
clicks int(10),
iclicks int(10),
uclicks int(10),
ts timestamp,
PRIMARY KEY (place_id,ts)
)engine=tianmu;

INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
VALUES (1,0,0,0,0,0,0,20000928174434);
UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1 AND ts>="2000-09-28 00:00:00";
select place_id,shows from t1;

--echo # connection slave
--source include/sync_slave_sql_with_master.inc
select place_id,shows from t1;

--echo # connection master
connection master;
drop table t1;
7 changes: 4 additions & 3 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9690,11 +9690,12 @@ search_key_in_table(TABLE *table, MY_BITMAP *bi_cols, uint key_type)
(table->s->db_type() ? table->s->db_type()->db_type == DB_TYPE_TIANMU: false);
enum_sql_command sqlCommand = SQLCOM_END;
if(table->in_use && table->in_use->lex) sqlCommand = table->in_use->lex->sql_command;
bool tianmuDeleteOrUpdate = (tianmu_engine && (sqlCommand == SQLCOM_DELETE ||
if (tianmu_engine && (sqlCommand == SQLCOM_DELETE ||
sqlCommand == SQLCOM_DELETE_MULTI ||
sqlCommand == SQLCOM_UPDATE ||
sqlCommand == SQLCOM_UPDATE_MULTI));
if(tianmuDeleteOrUpdate) DBUG_RETURN(res);
sqlCommand == SQLCOM_UPDATE_MULTI)){
DBUG_RETURN(res);
}

if (key_type & PRI_KEY_FLAG &&
(table->s->primary_key < MAX_KEY))
Expand Down
Loading

0 comments on commit 8d32f51

Please sign in to comment.