Skip to content

Commit ca051fa

Browse files
committed
Allow row events in replication stream for slave in all cases
(even when configured with --binlog-format=statement). Before we got an error on the slave and the slave stopped if the master was configured with --binlog-format=mixed or --binlog-format=row.
1 parent d278fb4 commit ca051fa

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include/master-slave.inc
2+
[connection master]
3+
use test;
4+
create table t1 (a int primary key);
5+
insert into t1 values (1),(2),(3),(4),(5);
6+
update t1 set a=a*10;
7+
use test;
8+
select * from t1;
9+
a
10+
10
11+
20
12+
30
13+
40
14+
50
15+
include/show_binlog_events.inc
16+
Log_name Pos Event_type Server_id End_log_pos Info
17+
slave-bin.000001 # Gtid # # GTID #-#-#
18+
slave-bin.000001 # Query # # use `test`; create table t1 (a int primary key)
19+
slave-bin.000001 # Gtid # # BEGIN GTID #-#-#
20+
slave-bin.000001 # Table_map # # table_id: # (test.t1)
21+
slave-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
22+
slave-bin.000001 # Query # # COMMIT
23+
slave-bin.000001 # Gtid # # BEGIN GTID #-#-#
24+
slave-bin.000001 # Table_map # # table_id: # (test.t1)
25+
slave-bin.000001 # Update_rows_v1 # # table_id: # flags: STMT_END_F
26+
slave-bin.000001 # Query # # COMMIT
27+
drop table t1;
28+
include/rpl_end.inc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--binlog-format=row
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--binlog-format=statement
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# check that master starterd with log-format=ROW replication can replicate to
3+
# slave started with log-format=STATEMENT
4+
#
5+
6+
--source include/have_binlog_format_row.inc
7+
--source include/master-slave.inc
8+
9+
use test;
10+
11+
create table t1 (a int primary key);
12+
insert into t1 values (1),(2),(3),(4),(5);
13+
update t1 set a=a*10;
14+
15+
sync_slave_with_master;
16+
use test;
17+
select * from t1;
18+
source include/show_binlog_events.inc;
19+
20+
connection master;
21+
drop table t1;
22+
23+
--source include/rpl_end.inc

sql/sql_class.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5156,16 +5156,13 @@ void xid_cache_delete(XID_STATE *xid_state)
51565156
BINLOG_FORMAT = STATEMENT and at least one table uses a storage
51575157
engine limited to row-logging.
51585158
5159-
6. Error: Cannot execute row injection: binlogging impossible since
5160-
BINLOG_FORMAT = STATEMENT.
5161-
5162-
7. Warning: Unsafe statement binlogged in statement format since
5159+
6. Warning: Unsafe statement binlogged in statement format since
51635160
BINLOG_FORMAT = STATEMENT.
51645161
51655162
In addition, we can produce the following error (not depending on
51665163
the variables of the decision diagram):
51675164
5168-
8. Error: Cannot execute statement: binlogging impossible since more
5165+
7. Error: Cannot execute statement: binlogging impossible since more
51695166
than one engine is involved and at least one engine is
51705167
self-logging.
51715168
@@ -5444,10 +5441,10 @@ int THD::decide_logging_format(TABLE_LIST *tables)
54445441
if (lex->is_stmt_row_injection())
54455442
{
54465443
/*
5447-
6. Error: Cannot execute row injection since
5448-
BINLOG_FORMAT = STATEMENT
5444+
We have to log the statement as row or give an error.
5445+
Better to accept what master gives us than stopping replication.
54495446
*/
5450-
my_error((error= ER_BINLOG_ROW_INJECTION_AND_STMT_MODE), MYF(0));
5447+
set_current_stmt_binlog_format_row();
54515448
}
54525449
else if ((flags_write_all_set & HA_BINLOG_STMT_CAPABLE) == 0 &&
54535450
sqlcom_can_generate_row_events(this))
@@ -5472,7 +5469,7 @@ int THD::decide_logging_format(TABLE_LIST *tables)
54725469
DBUG_PRINT("info", ("binlog_unsafe_warning_flags: 0x%x",
54735470
binlog_unsafe_warning_flags));
54745471
}
5475-
/* log in statement format! */
5472+
/* log in statement format (or row if row event)! */
54765473
}
54775474
/* No statement-only engines and binlog_format != STATEMENT.
54785475
I.e., nothing prevents us from row logging if needed. */

0 commit comments

Comments
 (0)