-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optionally disable binlogging while executing triggers
Summary: Online schema change (OSC) creates triggers only on master side. Since RBR logs row changes made by triggers, sql_thread will hit errors due to missing tables on slaves. Add a session variable SQL_LOG_BIN_TRIGGERS to optionally disable binlogging for trigger statements so that RBR and OSC are fine with each other. disable_sql_log_bin_triggers flag is added in the TABLE_LIST struct to track tables that are opened during trigger execution. This flag is used to skip writing Table_map_log_events for such tables. With sql_log_bin_triggers enabled, the trigger changes which may be necessary for slave are not propagated. To avoid this, slave_run_triggers_for_rbr option must be enabled on slave. Test Plan: mtr tests Reviewers: jtolmer Reviewed By: jtolmer
- Loading branch information
1 parent
fe89886
commit cdeb012
Showing
14 changed files
with
270 additions
and
3 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,45 @@ | ||
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] | ||
set @@session.sql_log_bin_triggers = OFF; | ||
create table t1 (c1 char(1) primary key, c2 char(1)); | ||
set @@session.sql_log_bin=0; | ||
create table t2 (id char(2) primary key, cnt int, o char(1), n char(1)); | ||
create trigger t1_cnt_b before update on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u0'; | ||
create trigger t1_cnt_db before delete on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=' ' where id = 'd0'; | ||
create trigger t1_cnt_ib before insert on t1 for each row | ||
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i0'; | ||
create trigger t1_cnt_a after update on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u1'; | ||
create trigger t1_cnt_da after delete on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=' ' where id = 'd1'; | ||
create trigger t1_cnt_ia after insert on t1 for each row | ||
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i1'; | ||
insert into t2 values | ||
('u0', 0, ' ', ' '),('u1', 0, ' ', ' '), | ||
('d0', 0, ' ', ' '),('d1', 0, ' ', ' '), | ||
('i0', 0, ' ', ' '),('i1', 0, ' ', ' '); | ||
set @@session.sql_log_bin=1; | ||
# INSERT triggers test | ||
insert into t1 values ('a','b'); | ||
select * from t1; | ||
c1 c2 | ||
a b | ||
# UPDATE triggers test | ||
update t1 set C1= 'd'; | ||
select * from t1; | ||
c1 c2 | ||
d b | ||
# DELETE triggers test | ||
delete from t1 where C1='d'; | ||
select * from t1; | ||
c1 c2 | ||
set @@session.sql_log_bin=0; | ||
drop table t2; | ||
set @@session.sql_log_bin=1; | ||
drop table t1; | ||
include/rpl_end.inc |
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,61 @@ | ||
# This test verifies the functionality of sql_log_bin_triggers configuration | ||
# option using the following steps: | ||
# 1. Create master side triggers and table, don't propogate them to slave by turning off sql_log_bin | ||
# 2. Execute SQL statements on master which run the triggers | ||
# 3. Sync slave with master and verify slave is not broken | ||
|
||
source include/master-slave.inc; | ||
source include/have_binlog_format_row.inc; | ||
|
||
connection master; | ||
set @@session.sql_log_bin_triggers = OFF; | ||
|
||
create table t1 (c1 char(1) primary key, c2 char(1)); | ||
set @@session.sql_log_bin=0; | ||
create table t2 (id char(2) primary key, cnt int, o char(1), n char(1)); | ||
create trigger t1_cnt_b before update on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u0'; | ||
create trigger t1_cnt_db before delete on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=' ' where id = 'd0'; | ||
create trigger t1_cnt_ib before insert on t1 for each row | ||
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i0'; | ||
create trigger t1_cnt_a after update on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=new.C1 where id = 'u1'; | ||
create trigger t1_cnt_da after delete on t1 for each row | ||
update t2 set cnt=cnt+1, o=old.C1, n=' ' where id = 'd1'; | ||
create trigger t1_cnt_ia after insert on t1 for each row | ||
update t2 set cnt=cnt+1, n=new.C1, o=' ' where id = 'i1'; | ||
insert into t2 values | ||
('u0', 0, ' ', ' '),('u1', 0, ' ', ' '), | ||
('d0', 0, ' ', ' '),('d1', 0, ' ', ' '), | ||
('i0', 0, ' ', ' '),('i1', 0, ' ', ' '); | ||
|
||
set @@session.sql_log_bin=1; | ||
sync_slave_with_master; | ||
|
||
connection master; | ||
--echo # INSERT triggers test | ||
insert into t1 values ('a','b'); | ||
sync_slave_with_master; | ||
select * from t1; | ||
|
||
connection master; | ||
--echo # UPDATE triggers test | ||
update t1 set C1= 'd'; | ||
sync_slave_with_master; | ||
select * from t1; | ||
|
||
connection master; | ||
--echo # DELETE triggers test | ||
delete from t1 where C1='d'; | ||
sync_slave_with_master; | ||
select * from t1; | ||
|
||
connection master; | ||
set @@session.sql_log_bin=0; | ||
drop table t2; | ||
set @@session.sql_log_bin=1; | ||
|
||
drop table t1; | ||
|
||
source include/rpl_end.inc; |
66 changes: 66 additions & 0 deletions
66
mysql-test/suite/sys_vars/r/sql_log_bin_triggers_basic.result
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,66 @@ | ||
SET @start_sql_log_bin_triggers = @@global.sql_log_bin_triggers; | ||
SELECT @start_sql_log_bin_triggers; | ||
@start_sql_log_bin_triggers | ||
1 | ||
SET @@global.sql_log_bin_triggers = false; | ||
SET @@global.sql_log_bin_triggers = DEFAULT; | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
1 | ||
SET @@global.sql_log_bin_triggers = @start_sql_log_bin_triggers; | ||
SELECT @@global.sql_log_bin_triggers = true; | ||
@@global.sql_log_bin_triggers = true | ||
1 | ||
SET @@global.sql_log_bin_triggers = false; | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
0 | ||
SET @@global.sql_log_bin_triggers = true; | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
1 | ||
SET @@global.sql_log_bin_triggers = 1; | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
1 | ||
SET @@global.sql_log_bin_triggers = 0; | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
0 | ||
SET @@global.sql_log_bin_triggers = -1; | ||
ERROR 42000: Variable 'sql_log_bin_triggers' can't be set to the value of '-1' | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
0 | ||
SET @@global.sql_log_bin_triggers = 100; | ||
ERROR 42000: Variable 'sql_log_bin_triggers' can't be set to the value of '100' | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
0 | ||
SET @@global.sql_log_bin_triggers = 1000.01; | ||
ERROR 42000: Incorrect argument type to variable 'sql_log_bin_triggers' | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
0 | ||
SET @@session.sql_log_bin_triggers = FALSE; | ||
SELECT @@session.sql_log_bin_triggers; | ||
@@session.sql_log_bin_triggers | ||
0 | ||
SELECT @@global.sql_log_bin_triggers = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES | ||
WHERE VARIABLE_NAME='sql_log_bin_triggers'; | ||
@@global.sql_log_bin_triggers = VARIABLE_VALUE | ||
1 | ||
Warnings: | ||
Warning 1292 Truncated incorrect DOUBLE value: 'OFF' | ||
SELECT @@sql_log_bin_triggers = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.SESSION_VARIABLES | ||
WHERE VARIABLE_NAME='sql_log_bin_triggers'; | ||
@@sql_log_bin_triggers = VARIABLE_VALUE | ||
1 | ||
Warnings: | ||
Warning 1292 Truncated incorrect DOUBLE value: 'OFF' | ||
SET @@global.sql_log_bin_triggers = @start_sql_log_bin_triggers; | ||
SELECT @@global.sql_log_bin_triggers; | ||
@@global.sql_log_bin_triggers | ||
1 |
46 changes: 46 additions & 0 deletions
46
mysql-test/suite/sys_vars/t/sql_log_bin_triggers_basic.test
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,46 @@ | ||
source include/load_sysvars.inc; | ||
|
||
SET @start_sql_log_bin_triggers = @@global.sql_log_bin_triggers; | ||
SELECT @start_sql_log_bin_triggers; | ||
|
||
SET @@global.sql_log_bin_triggers = false; | ||
SET @@global.sql_log_bin_triggers = DEFAULT; | ||
SELECT @@global.sql_log_bin_triggers; | ||
|
||
SET @@global.sql_log_bin_triggers = @start_sql_log_bin_triggers; | ||
SELECT @@global.sql_log_bin_triggers = true; | ||
|
||
SET @@global.sql_log_bin_triggers = false; | ||
SELECT @@global.sql_log_bin_triggers; | ||
SET @@global.sql_log_bin_triggers = true; | ||
SELECT @@global.sql_log_bin_triggers; | ||
|
||
SET @@global.sql_log_bin_triggers = 1; | ||
SELECT @@global.sql_log_bin_triggers; | ||
SET @@global.sql_log_bin_triggers = 0; | ||
SELECT @@global.sql_log_bin_triggers; | ||
|
||
--Error ER_WRONG_VALUE_FOR_VAR | ||
SET @@global.sql_log_bin_triggers = -1; | ||
SELECT @@global.sql_log_bin_triggers; | ||
--Error ER_WRONG_VALUE_FOR_VAR | ||
SET @@global.sql_log_bin_triggers = 100; | ||
SELECT @@global.sql_log_bin_triggers; | ||
--Error ER_WRONG_TYPE_FOR_VAR | ||
SET @@global.sql_log_bin_triggers = 1000.01; | ||
SELECT @@global.sql_log_bin_triggers; | ||
|
||
SET @@session.sql_log_bin_triggers = FALSE; | ||
SELECT @@session.sql_log_bin_triggers; | ||
|
||
SELECT @@global.sql_log_bin_triggers = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES | ||
WHERE VARIABLE_NAME='sql_log_bin_triggers'; | ||
|
||
SELECT @@sql_log_bin_triggers = VARIABLE_VALUE | ||
FROM INFORMATION_SCHEMA.SESSION_VARIABLES | ||
WHERE VARIABLE_NAME='sql_log_bin_triggers'; | ||
|
||
|
||
SET @@global.sql_log_bin_triggers = @start_sql_log_bin_triggers; | ||
SELECT @@global.sql_log_bin_triggers; |
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
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
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