Commit 2049d1af authored by 's avatar

Bug #50407 mysqlbinlog --database=X produces bad output for SAVEPOINTs

When mysqlbinlog was given the --database=X flag, it always printed
'ROLLBACK TO', but the corresponding 'SAVEPOINT' statement was not
printed. The replicated filter(replicated-do/ignore-db) and binlog
filter (binlog-do/ignore-db) has the same problem. They are solved
in this patch together.

After this patch, We always check whether the query is 'SAVEPOINT'
statement or not. Because this is a literal check, 'SAVEPOINT' and
'ROLLBACK TO' statements are also binlogged in uppercase with no
any comments.

The binlog before this patch can be handled correctly except one case
that any comments are in front of the keywords. for example:
 /* bla bla */ SAVEPOINT a;
 /* bla bla */ ROLLBACK TO a;
parent 8d22c5f3
...@@ -730,9 +730,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, ...@@ -730,9 +730,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
switch (ev_type) { switch (ev_type) {
case QUERY_EVENT: case QUERY_EVENT:
if (strncmp(((Query_log_event*)ev)->query, "BEGIN", 5) && if (!((Query_log_event*)ev)->is_trans_keyword() &&
strncmp(((Query_log_event*)ev)->query, "COMMIT", 6) &&
strncmp(((Query_log_event*)ev)->query, "ROLLBACK", 8) &&
shall_skip_database(((Query_log_event*)ev)->db)) shall_skip_database(((Query_log_event*)ev)->db))
goto end; goto end;
if (opt_base64_output_mode == BASE64_OUTPUT_ALWAYS) if (opt_base64_output_mode == BASE64_OUTPUT_ALWAYS)
......
...@@ -479,7 +479,7 @@ FLUSH LOGS; ...@@ -479,7 +479,7 @@ FLUSH LOGS;
RESET MASTER; RESET MASTER;
FLUSH LOGS; FLUSH LOGS;
# #
# Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified is exist # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified exists
/*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/; DELIMITER /*!*/;
...@@ -532,7 +532,7 @@ DELIMITER ; ...@@ -532,7 +532,7 @@ DELIMITER ;
ROLLBACK /* added by mysqlbinlog */; ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
# #
# Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified is not exist # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified does not exist
/*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/; DELIMITER /*!*/;
...@@ -565,5 +565,76 @@ DELIMITER ; ...@@ -565,5 +565,76 @@ DELIMITER ;
# End of log file # End of log file
ROLLBACK /* added by mysqlbinlog */; ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
#
# Test if the 'SAVEPOINT', 'ROLLBACK TO' are output if the database specified exists
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
SET TIMESTAMP=1266652094/*!*/;
SET @@session.pseudo_thread_id=999999999/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=0/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C latin1 *//*!*/;
SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
use test/*!*/;
SET TIMESTAMP=1266652094/*!*/;
SavePoint mixed_cases
/*!*/;
use db1/*!*/;
SET TIMESTAMP=1266652094/*!*/;
INSERT INTO db1.t2 VALUES("in savepoint mixed_cases")
/*!*/;
SET TIMESTAMP=1266652094/*!*/;
INSERT INTO db1.t1 VALUES(40)
/*!*/;
use test/*!*/;
SET TIMESTAMP=1266652094/*!*/;
ROLLBACK TO mixed_cases
/*!*/;
use db1/*!*/;
SET TIMESTAMP=1266652094/*!*/;
INSERT INTO db1.t2 VALUES("after rollback to")
/*!*/;
SET TIMESTAMP=1266652094/*!*/;
INSERT INTO db1.t1 VALUES(50)
/*!*/;
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
#
# Test if the 'SAVEPOINT', 'ROLLBACK TO' are output if the database specified does not exist
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
SET TIMESTAMP=1266652094/*!*/;
SET @@session.pseudo_thread_id=999999999/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=0/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C latin1 *//*!*/;
SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
use test/*!*/;
SET TIMESTAMP=1266652094/*!*/;
SavePoint mixed_cases
/*!*/;
SET TIMESTAMP=1266652094/*!*/;
ROLLBACK TO mixed_cases
/*!*/;
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
End of 5.0 tests End of 5.0 tests
End of 5.1 tests End of 5.1 tests
...@@ -48,12 +48,12 @@ Log_name Pos Event_type Server_id End_log_pos Info ...@@ -48,12 +48,12 @@ Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # BEGIN
master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # use `test`; savepoint my_savepoint master-bin.000001 # Query # # SAVEPOINT my_savepoint
master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map # # table_id: # (test.t2) master-bin.000001 # Table_map # # table_id: # (test.t2)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # use `test`; rollback to savepoint my_savepoint master-bin.000001 # Query # # ROLLBACK TO my_savepoint
master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Xid # # COMMIT /* XID */
delete from t1; delete from t1;
delete from t2; delete from t2;
...@@ -77,12 +77,12 @@ Log_name Pos Event_type Server_id End_log_pos Info ...@@ -77,12 +77,12 @@ Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # BEGIN
master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # use `test`; savepoint my_savepoint master-bin.000001 # Query # # SAVEPOINT my_savepoint
master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map # # table_id: # (test.t2) master-bin.000001 # Table_map # # table_id: # (test.t2)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Query # # use `test`; rollback to savepoint my_savepoint master-bin.000001 # Query # # ROLLBACK TO my_savepoint
master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Table_map # # table_id: # (test.t1)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Xid # # COMMIT /* XID */
......
...@@ -44,10 +44,10 @@ show binlog events from <binlog_start>; ...@@ -44,10 +44,10 @@ show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; insert into t1 values(3) master-bin.000001 # Query # # use `test`; insert into t1 values(3)
master-bin.000001 # Query # # use `test`; savepoint my_savepoint master-bin.000001 # Query # # SAVEPOINT my_savepoint
master-bin.000001 # Query # # use `test`; insert into t1 values(4) master-bin.000001 # Query # # use `test`; insert into t1 values(4)
master-bin.000001 # Query # # use `test`; insert into t2 select * from t1 master-bin.000001 # Query # # use `test`; insert into t2 select * from t1
master-bin.000001 # Query # # use `test`; rollback to savepoint my_savepoint master-bin.000001 # Query # # ROLLBACK TO my_savepoint
master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Xid # # COMMIT /* XID */
delete from t1; delete from t1;
delete from t2; delete from t2;
...@@ -70,10 +70,10 @@ show binlog events from <binlog_start>; ...@@ -70,10 +70,10 @@ show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; insert into t1 values(5) master-bin.000001 # Query # # use `test`; insert into t1 values(5)
master-bin.000001 # Query # # use `test`; savepoint my_savepoint master-bin.000001 # Query # # SAVEPOINT my_savepoint
master-bin.000001 # Query # # use `test`; insert into t1 values(6) master-bin.000001 # Query # # use `test`; insert into t1 values(6)
master-bin.000001 # Query # # use `test`; insert into t2 select * from t1 master-bin.000001 # Query # # use `test`; insert into t2 select * from t1
master-bin.000001 # Query # # use `test`; rollback to savepoint my_savepoint master-bin.000001 # Query # # ROLLBACK TO my_savepoint
master-bin.000001 # Query # # use `test`; insert into t1 values(7) master-bin.000001 # Query # # use `test`; insert into t1 values(7)
master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Xid # # COMMIT /* XID */
delete from t1; delete from t1;
......
...@@ -5,7 +5,9 @@ reset slave; ...@@ -5,7 +5,9 @@ reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave; start slave;
DROP DATABASE IF EXISTS db1; DROP DATABASE IF EXISTS db1;
DROP DATABASE IF EXISTS db2;
CREATE DATABASE db1; CREATE DATABASE db1;
CREATE DATABASE db2;
use db1; use db1;
CREATE TABLE db1.t1 (a INT) ENGINE=InnoDB; CREATE TABLE db1.t1 (a INT) ENGINE=InnoDB;
CREATE TABLE db1.t2 (s CHAR(255)) ENGINE=MyISAM; CREATE TABLE db1.t2 (s CHAR(255)) ENGINE=MyISAM;
...@@ -102,8 +104,66 @@ SELECT * from db1.t2; ...@@ -102,8 +104,66 @@ SELECT * from db1.t2;
s s
before call db1.p1() before call db1.p1()
executed db1.p2() executed db1.p2()
START SLAVE;
#
# SAVEPOINT and ROLLBACK TO have the same problem in BUG#43263
# This was reported by BUG#50407
[on master]
SET SESSION AUTOCOMMIT=0
BEGIN;
INSERT INTO db1.t1 VALUES(20);
#
# Verify whether this statement is binlogged correctly
/*comment*/ SAVEPOINT has_comment;
USE db1;
INSERT INTO db1.t1 VALUES(30);
INSERT INTO db1.t2 VALUES("in savepoint has_comment");
USE db2;
SavePoint mixed_cases;
USE db1;
INSERT INTO db1.t2 VALUES("in savepoint mixed_cases");
INSERT INTO db1.t1 VALUES(40);
USE db2;
ROLLBACK TO mixed_cases;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
ROLLBACK TO has_comment;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
USE db1;
INSERT INTO db1.t2 VALUES("after rollback to");
INSERT INTO db1.t1 VALUES(50);
USE db2;
COMMIT;
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO db1.t1 VALUES(20)
master-bin.000001 # Query # # SAVEPOINT has_comment
master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t1 VALUES(30)
master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t2 VALUES("in savepoint has_comment")
master-bin.000001 # Query # # SAVEPOINT mixed_cases
master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t2 VALUES("in savepoint mixed_cases")
master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t1 VALUES(40)
master-bin.000001 # Query # # ROLLBACK TO mixed_cases
master-bin.000001 # Query # # ROLLBACK TO has_comment
master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t2 VALUES("after rollback to")
master-bin.000001 # Query # # use `db1`; INSERT INTO db1.t1 VALUES(50)
master-bin.000001 # Xid # # COMMIT /* XID */
[on slave]
#
# Verify INSERT statements in savepoints are executed, for MyISAM table
# is not effected by ROLLBACK TO
SELECT * FROM db1.t2 WHERE s LIKE '% savepoint %';
s
in savepoint has_comment
in savepoint mixed_cases
#
# Verify INSERT statements on the Innodb table are rolled back;
SELECT * FROM db1.t1 WHERE a IN (30, 40);
a
# #
# Clean up # Clean up
# #
DROP DATABASE db1; DROP DATABASE db1;
DROP DATABASE db1; DROP DATABASE db2;
...@@ -998,7 +998,7 @@ master-bin.000001 # Query 1 # use `test_rpl`; INSERT INTO t1 VALUES (3, 'before ...@@ -998,7 +998,7 @@ master-bin.000001 # Query 1 # use `test_rpl`; INSERT INTO t1 VALUES (3, 'before
master-bin.000001 # Xid 1 # # master-bin.000001 # Xid 1 # #
master-bin.000001 # Query 1 # BEGIN master-bin.000001 # Query 1 # BEGIN
master-bin.000001 # Query 1 # use `test_rpl`; INSERT INTO t1 VALUES (5, 'before savepoint s2') master-bin.000001 # Query 1 # use `test_rpl`; INSERT INTO t1 VALUES (5, 'before savepoint s2')
master-bin.000001 # Query 1 # use `test_rpl`; SAVEPOINT s2 master-bin.000001 # Query 1 # SAVEPOINT s2
master-bin.000001 # Query 1 # use `test_rpl`; INSERT INTO t1 VALUES (6, 'after savepoint s2') master-bin.000001 # Query 1 # use `test_rpl`; INSERT INTO t1 VALUES (6, 'after savepoint s2')
master-bin.000001 # Table_map 1 # table_id: # (test_rpl.t1) master-bin.000001 # Table_map 1 # table_id: # (test_rpl.t1)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
......
...@@ -4,9 +4,11 @@ source include/have_binlog_format_statement.inc; ...@@ -4,9 +4,11 @@ source include/have_binlog_format_statement.inc;
disable_warnings; disable_warnings;
DROP DATABASE IF EXISTS db1; DROP DATABASE IF EXISTS db1;
DROP DATABASE IF EXISTS db2;
enable_warnings; enable_warnings;
CREATE DATABASE db1; CREATE DATABASE db1;
CREATE DATABASE db2;
use db1; use db1;
...@@ -116,10 +118,55 @@ eval SELECT $result as 'Must be 0'; ...@@ -116,10 +118,55 @@ eval SELECT $result as 'Must be 0';
SELECT * from db1.t1; SELECT * from db1.t1;
SELECT * from db1.t2; SELECT * from db1.t2;
START SLAVE;
source include/wait_for_slave_sql_to_start.inc;
--echo #
--echo # SAVEPOINT and ROLLBACK TO have the same problem in BUG#43263
--echo # This was reported by BUG#50407
connection master;
echo [on master]
SET SESSION AUTOCOMMIT=0;
let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1);
BEGIN;
INSERT INTO db1.t1 VALUES(20);
--echo #
--echo # Verify whether this statement is binlogged correctly
/*comment*/ SAVEPOINT has_comment;
USE db1;
INSERT INTO db1.t1 VALUES(30);
INSERT INTO db1.t2 VALUES("in savepoint has_comment");
USE db2;
SavePoint mixed_cases;
USE db1;
INSERT INTO db1.t2 VALUES("in savepoint mixed_cases");
INSERT INTO db1.t1 VALUES(40);
USE db2;
ROLLBACK TO mixed_cases;
ROLLBACK TO has_comment;
USE db1;
INSERT INTO db1.t2 VALUES("after rollback to");
INSERT INTO db1.t1 VALUES(50);
USE db2;
COMMIT;
source include/show_binlog_events.inc;
sync_slave_with_master;
--echo [on slave]
--echo #
--echo # Verify INSERT statements in savepoints are executed, for MyISAM table
--echo # is not effected by ROLLBACK TO
SELECT * FROM db1.t2 WHERE s LIKE '% savepoint %';
--echo #
--echo # Verify INSERT statements on the Innodb table are rolled back;
SELECT * FROM db1.t1 WHERE a IN (30, 40);
--echo # --echo #
--echo # Clean up --echo # Clean up
--echo # --echo #
connection master; connection master;
DROP DATABASE db1; DROP DATABASE db1;
connection slave; DROP DATABASE db2;
DROP DATABASE db1; source include/master-slave-end.inc;
...@@ -434,12 +434,19 @@ FLUSH LOGS; ...@@ -434,12 +434,19 @@ FLUSH LOGS;
# Transaction3 end # Transaction3 end
--echo # --echo #
--echo # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified is exist --echo # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified exists
--exec $MYSQL_BINLOG --database=test --short-form $MYSQLTEST_VARDIR/std_data/binlog_transaction.000001 --exec $MYSQL_BINLOG --database=test --short-form $MYSQLTEST_VARDIR/std_data/binlog_transaction.000001
--echo # --echo #
--echo # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified is not exist --echo # Test if the 'BEGIN', 'ROLLBACK' and 'COMMIT' are output if the database specified does not exist
--exec $MYSQL_BINLOG --database=not_exist --short-form $MYSQLTEST_VARDIR/std_data/binlog_transaction.000001 --exec $MYSQL_BINLOG --database=not_exist --short-form $MYSQLTEST_VARDIR/std_data/binlog_transaction.000001
--echo #
--echo # Test if the 'SAVEPOINT', 'ROLLBACK TO' are output if the database specified exists
--exec $MYSQL_BINLOG --database=db1 --short-form $MYSQLTEST_VARDIR/std_data/binlog_savepoint.000001
--echo #
--echo # Test if the 'SAVEPOINT', 'ROLLBACK TO' are output if the database specified does not exist
--exec $MYSQL_BINLOG --database=not_exist --short-form $MYSQLTEST_VARDIR/std_data/binlog_savepoint.000001
--echo End of 5.0 tests --echo End of 5.0 tests
--echo End of 5.1 tests --echo End of 5.1 tests
......
...@@ -1714,11 +1714,14 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv) ...@@ -1714,11 +1714,14 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv)
binlog_trans_log_savepos(thd, (my_off_t*) sv); binlog_trans_log_savepos(thd, (my_off_t*) sv);
/* Write it to the binary log */ /* Write it to the binary log */
String log_query;
if (log_query.append(STRING_WITH_LEN("SAVEPOINT ")) ||
log_query.append(thd->lex->ident.str, thd->lex->ident.length))
DBUG_RETURN(1);
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
int const error= Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
thd->binlog_query(THD::STMT_QUERY_TYPE, TRUE, TRUE, errcode);
thd->query(), thd->query_length(), TRUE, FALSE, errcode); DBUG_RETURN(mysql_bin_log.write(&qinfo));
DBUG_RETURN(error);
} }
static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
...@@ -1733,11 +1736,14 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) ...@@ -1733,11 +1736,14 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
if (unlikely(thd->transaction.all.modified_non_trans_table || if (unlikely(thd->transaction.all.modified_non_trans_table ||
(thd->options & OPTION_KEEP_LOG))) (thd->options & OPTION_KEEP_LOG)))
{ {
String log_query;
if (log_query.append(STRING_WITH_LEN("ROLLBACK TO ")) ||
log_query.append(thd->lex->ident.str, thd->lex->ident.length))
DBUG_RETURN(1);
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
int error= Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(),
thd->binlog_query(THD::STMT_QUERY_TYPE, TRUE, TRUE, errcode);
thd->query(), thd->query_length(), TRUE, FALSE, errcode); DBUG_RETURN(mysql_bin_log.write(&qinfo));
DBUG_RETURN(error);
} }
binlog_trans_log_truncate(thd, *(my_off_t*)sv); binlog_trans_log_truncate(thd, *(my_off_t*)sv);
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -4272,7 +4278,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) ...@@ -4272,7 +4278,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
*/ */
const char *local_db= event_info->get_db(); const char *local_db= event_info->get_db();
if ((thd && !(thd->options & OPTION_BIN_LOG)) || if ((thd && !(thd->options & OPTION_BIN_LOG)) ||
(!binlog_filter->db_ok(local_db))) (thd->lex->sql_command != SQLCOM_ROLLBACK_TO_SAVEPOINT &&
thd->lex->sql_command != SQLCOM_SAVEPOINT &&
!binlog_filter->db_ok(local_db)))
{ {
VOID(pthread_mutex_unlock(&LOCK_log)); VOID(pthread_mutex_unlock(&LOCK_log));
DBUG_RETURN(0); DBUG_RETURN(0);
......
...@@ -3063,10 +3063,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli, ...@@ -3063,10 +3063,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
::do_apply_event(), then the companion SET also have so ::do_apply_event(), then the companion SET also have so
we don't need to reset_one_shot_variables(). we don't need to reset_one_shot_variables().
*/ */
if (!strncmp(query_arg, "BEGIN", q_len_arg) || if (is_trans_keyword() || rpl_filter->db_ok(thd->db))
!strncmp(query_arg, "COMMIT", q_len_arg) ||
!strncmp(query_arg, "ROLLBACK", q_len_arg) ||
rpl_filter->db_ok(thd->db))
{ {
thd->set_time((time_t)when); thd->set_time((time_t)when);
thd->set_query((char*)query_arg, q_len_arg); thd->set_query((char*)query_arg, q_len_arg);
......
...@@ -1682,6 +1682,28 @@ public: /* !!! Public in this patch to allow old usage */ ...@@ -1682,6 +1682,28 @@ public: /* !!! Public in this patch to allow old usage */
const char *query_arg, const char *query_arg,
uint32 q_len_arg); uint32 q_len_arg);
#endif /* HAVE_REPLICATION */ #endif /* HAVE_REPLICATION */
/*
If true, the event always be applied by slave SQL thread or be printed by
mysqlbinlog
*/
bool is_trans_keyword()
{
/*
Before the patch for bug#50407, The 'SAVEPOINT and ROLLBACK TO'
queries input by user was written into log events directly.
So the keywords can be written in both upper case and lower case
together, strncasecmp is used to check both cases. they also could be
binlogged with comments in the front of these keywords. for examples:
/ * bla bla * / SAVEPOINT a;
/ * bla bla * / ROLLBACK TO a;
but we don't handle these cases and after the patch, both quiries are
binlogged in upper case with no comments.
*/
return !strncmp(query, "BEGIN", q_len) ||
!strncmp(query, "COMMIT", q_len) ||
!strncasecmp(query, "SAVEPOINT", 9) ||
!strncasecmp(query, "ROLLBACK", 8);
}
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment