Commit b06d870f authored by Alfranio Correia's avatar Alfranio Correia

BUG#46364 MyISAM transbuffer problems (NTM problem)

      
It is well-known that due to concurrency issues, a slave can become
inconsistent when a transaction contains updates to both transaction and
non-transactional tables.
                    
In a nutshell, the current code-base tries to preserve causality among the
statements by writing non-transactional statements to the txn-cache which
is flushed upon commit. However, modifications done to non-transactional
tables on behalf of a transaction become immediately visible to other
connections but may not immediately get into the binary log and therefore
consistency may be broken.
            
In general, it is impossible to automatically detect causality/dependency
among statements by just analyzing the statements sent to the server. This
happen because dependency may be hidden in the application code and it is
necessary to know a priori all the statements processed in the context of
a transaction such as in a procedure. Moreover, even for the few cases that
we could automatically address in the server, the computation effort
required could make the approach infeasible.
            
So, in this patch we introduce the option
      - "--binlog-direct-non-transactional-updates" that can be used to bypass
      the current behavior in order to write directly to binary log statements
      that change non-transactional tables.

Besides, it is used to enable the WL#2687 which is disabled by default.
parents 32d17f7d 8da3fea2
......@@ -344,30 +344,14 @@ BEGIN;
--eval INSERT INTO t1 (a, data) VALUES (1, $data);
--eval INSERT INTO t1 (a, data) VALUES (2, $data);
--eval INSERT INTO t2 (a, data) VALUES (3, $data);
if (`SELECT @@binlog_format = 'STATEMENT'`)
{
--error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE
--eval INSERT INTO t1 (a, data) VALUES (4, $data);
}
if (`SELECT @@binlog_format = 'ROW' || @@binlog_format = 'MIXED'`)
{
--eval INSERT INTO t1 (a, data) VALUES (4, $data);
}
--eval INSERT INTO t1 (a, data) VALUES (4, $data);
--error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE
--eval INSERT INTO t1 (a, data) VALUES (5, $data);
--error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE
--eval INSERT INTO t1 (a, data) VALUES (6, $data);
--error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE
--eval INSERT INTO t1 (a, data) VALUES (7, $data);
if (`SELECT @@binlog_format = 'STATEMENT'`)
{
--error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE
--eval UPDATE t2 SET data= CONCAT($data, $data);
}
if (`SELECT @@binlog_format = 'ROW' || @@binlog_format = 'MIXED'`)
{
--eval UPDATE t2 SET data= CONCAT($data, $data);
}
--eval UPDATE t2 SET data= CONCAT($data, $data);
--eval INSERT INTO t1 (a, data) VALUES (8, 's');
--eval INSERT INTO t1 (a, data) VALUES (9, 's');
--eval INSERT INTO t2 (a, data) VALUES (10, 's');
......@@ -380,31 +364,12 @@ BEGIN;
--eval INSERT INTO t1 (a, data) VALUES (15, $data);
--eval INSERT INTO t1 (a, data) VALUES (16, $data);
--eval INSERT INTO t2 (a, data) VALUES (17, $data);
if (`SELECT @@binlog_format = 'STATEMENT'`)
{
--error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE
--eval INSERT INTO t1 (a, data) VALUES (18, $data);
}
if (`SELECT @@binlog_format = 'ROW' || @@binlog_format = 'MIXED'`)
{
--eval INSERT INTO t1 (a, data) VALUES (18, $data);
}
--eval INSERT INTO t1 (a, data) VALUES (18, $data);
--error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE
--eval INSERT INTO t1 (a, data) VALUES (19, $data);
--enable_query_log
COMMIT;
if (`SELECT @@binlog_format = 'STATEMENT'`)
{
connection slave;
--source include/wait_for_slave_sql_to_stop.inc
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
START SLAVE SQL_THREAD;
--source include/wait_for_slave_sql_to_start.inc
connection master;
}
let $diff_statement= SELECT * FROM t1;
--source include/diff_master_slave.inc
......
......@@ -219,13 +219,12 @@ while (`SELECT $ddl_cases >= 1`)
# in the binary log:
#
# 1: DDL EVENT which triggered the previous commmit.
# 2: COMMIT
# 3: BEGIN
# 4: TABLE MAP EVENT
# 5: TABLE MAP EVENT (ndb_apply_status)
# 2: BEGIN
# 3: TABLE MAP EVENT
# 4: TABLE MAP EVENT (ndb_apply_status)
# 5: ROW EVENT
# 6: ROW EVENT
# 7: ROW EVENT
# 8: COMMIT
# 7: COMMIT
#
if (`SELECT '$engine' = 'NDB' && @@binlog_format != 'ROW'`)
{
......@@ -362,8 +361,11 @@ while (`SELECT $ddl_cases >= 1`)
# does not commit the current transaction.
#
# 1: BEGIN
# 2: INSERT
# 3: CREATE TEMPORARY
# 2: CREATE TEMPORARY
# 3: COMMIT
# 4: BEGIN
# 5: INSERT
# 6: COMMIT
#
# In RBR the transaction is not committed either and the statement is not
# written to the binary log:
......@@ -371,10 +373,11 @@ while (`SELECT $ddl_cases >= 1`)
# 1: BEGIN
# 2: TABLE MAP EVENT
# 3: ROW EVENT
# 4: COMMIT
#
if (`select @@binlog_format = 'STATEMENT' || @@binlog_format = 'MIXED'`)
if (`select @@binlog_format = 'STATEMENT' || @@binlog_format = 'MIXED'` )
{
let $commit_event_row_number= 4;
let $commit_event_row_number= 6;
}
#
# In NDB (RBR mode), the commit event is the sixth event
......@@ -482,9 +485,14 @@ while (`SELECT $ddl_cases >= 1`)
# In SBR and MIXED modes, the DDL statement is written to the binary log
# but does not commit the current transaction:
#
# In SBR, we have what follows:
#
# 1: BEGIN
# 2: INSERT
# 3: DROP TEMPORARY
# 2: DROP TEMPORARY
# 3: COMMIT
# 4: BEGIN
# 5: INSERT
# 6: COMMIT
#
# In RBR the transaction is not committed either and the statement is not
# written to the binary log:
......@@ -492,8 +500,13 @@ while (`SELECT $ddl_cases >= 1`)
# 1: BEGIN
# 2: TABLE MAP EVENT
# 3: ROW EVENT
# 4: COMMIT
#
if (`select @@binlog_format = 'STATEMENT'`)
{
let $commit_event_row_number= 6;
}
if (`select @@binlog_format = 'ROW'`)
{
let $commit_event_row_number= 4;
}
......@@ -503,6 +516,7 @@ while (`SELECT $ddl_cases >= 1`)
# 2: TABLE MAP EVENT
# 3: ROW EVENT
# 4: DROP TEMPORARY table IF EXISTS
# 5: COMMIT
#
if (`select @@binlog_format = 'MIXED'`)
{
......
......@@ -1767,7 +1767,10 @@ sync_slave_with_master;
--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/test-nmt-master.sql
--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/test-nmt-slave.sql
--diff_files $MYSQLTEST_VARDIR/tmp/test-nmt-master.sql $MYSQLTEST_VARDIR/tmp/test-nmt-slave.sql
if (`select @@session.binlog_format != 'STATEMENT'`)
{
--diff_files $MYSQLTEST_VARDIR/tmp/test-nmt-master.sql $MYSQLTEST_VARDIR/tmp/test-nmt-slave.sql
}
--echo ###################################################################################
--echo # CLEAN
......
......@@ -44,3 +44,4 @@ log-bin=mysqld-bin
# Run tests with the performance schema instrumentation
loose-enable-performance-schema
binlog-direct-non-transactional-updates
......@@ -37,6 +37,14 @@ The following options may be given as the first argument:
binary log during a transaction. If you often use big,
multi-statement transactions you can increase this to get
more performance
--binlog-direct-non-transactional-updates
Causes updates to non-transactional engines using
statement format to be written directly to binary log.
Before using this option make sure that there are no
dependencies between transactional and non-transactional
tables such as in the statement INSERT INTO t_myisam
SELECT * FROM t_innodb; otherwise, slaves may diverge
from the master.
--binlog-do-db=name Tells the master it should log updates for the specified
database, and exclude all others not explicitly
mentioned.
......@@ -768,6 +776,7 @@ back-log 50
big-tables FALSE
bind-address (No default value)
binlog-cache-size 32768
binlog-direct-non-transactional-updates FALSE
binlog-format STATEMENT
binlog-row-event-max-size 1024
blackhole ON
......
......@@ -37,6 +37,14 @@ The following options may be given as the first argument:
binary log during a transaction. If you often use big,
multi-statement transactions you can increase this to get
more performance
--binlog-direct-non-transactional-updates
Causes updates to non-transactional engines using
statement format to be written directly to binary log.
Before using this option make sure that there are no
dependencies between transactional and non-transactional
tables such as in the statement INSERT INTO t_myisam
SELECT * FROM t_innodb; otherwise, slaves may diverge
from the master.
--binlog-do-db=name Tells the master it should log updates for the specified
database, and exclude all others not explicitly
mentioned.
......@@ -772,6 +780,7 @@ back-log 50
big-tables FALSE
bind-address (No default value)
binlog-cache-size 32768
binlog-direct-non-transactional-updates FALSE
binlog-format STATEMENT
binlog-row-event-max-size 1024
blackhole ON
......
......@@ -33,9 +33,11 @@ mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Query # # use `test`; UPDATE t1m, t1b SET m = 2, b = 3 WHERE n = c
mysqld-bin.000001 # Query # # COMMIT
mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Query # # use `test`; UPDATE t1n, t1b SET e = 2, b = 3 WHERE f = c
mysqld-bin.000001 # Query # # COMMIT
mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Query # # use `test`; INSERT INTO t1n VALUES (1,1), (1,2), (2,1), (2,2)
mysqld-bin.000001 # Query # # use `test`; UPDATE t1m, t1n SET m = 2, e = 3 WHERE n = f
mysqld-bin.000001 # Query # # use `test`; UPDATE t1n, t1b SET e = 2, b = 3 WHERE f = c
mysqld-bin.000001 # Query # # COMMIT
mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Table_map # # table_id: # (test.t1n)
......
set @save_binlog_format= @@global.binlog_format;
set @save_binlog_dirct= @@global.binlog_direct_non_transactional_updates;
create table t1 (a int) engine= myisam;
create table t2 (a int) engine= innodb;
SELECT @@session.binlog_format;
......@@ -8,19 +9,27 @@ SET AUTOCOMMIT=1;
# Test that the session variable 'binlog_format'
# is writable outside a transaction.
set @@session.binlog_format= statement;
set @@session.binlog_direct_non_transactional_updates= TRUE;
SELECT @@session.binlog_format;
@@session.binlog_format
STATEMENT
SELECT @@session.binlog_direct_non_transactional_updates;
@@session.binlog_direct_non_transactional_updates
1
begin;
# Test that the session variable 'binlog_format' is read-only
# inside a transaction with no preceding updates.
set @@session.binlog_format= mixed;
ERROR HY000: Cannot modify @@session.binlog_format inside a transaction
set @@session.binlog_direct_non_transactional_updates= FALSE;
ERROR HY000: Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction
insert into t2 values (1);
# Test that the session variable 'binlog_format' is read-only
# inside a transaction with preceding transactional updates.
set @@session.binlog_format= row;
ERROR HY000: Cannot modify @@session.binlog_format inside a transaction
set @@session.binlog_direct_non_transactional_updates= FALSE;
ERROR HY000: Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction
commit;
begin;
insert into t1 values (2);
......@@ -28,31 +37,47 @@ insert into t1 values (2);
# inside a transaction with preceding non-transactional updates.
set @@session.binlog_format= statement;
ERROR HY000: Cannot modify @@session.binlog_format inside a transaction
set @@session.binlog_direct_non_transactional_updates= FALSE;
ERROR HY000: Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction
commit;
# Test that the session variable 'binlog_format' is writable
# when AUTOCOMMIT=0, before a transaction has started.
set AUTOCOMMIT=0;
set @@session.binlog_format= row;
set @@session.binlog_direct_non_transactional_updates= FALSE;
SELECT @@session.binlog_format;
@@session.binlog_format
ROW
SELECT @@session.binlog_direct_non_transactional_updates;
@@session.binlog_direct_non_transactional_updates
0
insert into t1 values (4);
# Test that the session variable 'binlog_format' is read-only inside an
# AUTOCOMMIT=0 transaction with preceding non-transactional updates.
set @@session.binlog_format= statement;
ERROR HY000: Cannot modify @@session.binlog_format inside a transaction
set @@session.binlog_direct_non_transactional_updates= TRUE;
ERROR HY000: Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction
SELECT @@session.binlog_format;
@@session.binlog_format
ROW
SELECT @@session.binlog_direct_non_transactional_updates;
@@session.binlog_direct_non_transactional_updates
0
commit;
insert into t2 values (5);
# Test that the session variable 'binlog_format' is read-only inside an
# AUTOCOMMIT=0 transaction with preceding transactional updates.
set @@session.binlog_format= row;
ERROR HY000: Cannot modify @@session.binlog_format inside a transaction
set @@session.binlog_direct_non_transactional_updates= TRUE;
ERROR HY000: Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction
SELECT @@session.binlog_format;
@@session.binlog_format
ROW
SELECT @@session.binlog_direct_non_transactional_updates;
@@session.binlog_direct_non_transactional_updates
0
commit;
begin;
insert into t2 values (6);
......@@ -62,15 +87,20 @@ SELECT @@global.binlog_format;
@@global.binlog_format
ROW
set @@global.binlog_format= statement;
set @@global.binlog_direct_non_transactional_updates= TRUE;
SELECT @@global.binlog_format;
@@global.binlog_format
STATEMENT
SELECT @@global.binlog_direct_non_transactional_updates;
@@global.binlog_direct_non_transactional_updates
1
commit;
set @@global.binlog_format= @save_binlog_format;
set @@global.binlog_direct_non_transactional_updates= @save_binlog_dirct;
create table t3(a int, b int) engine= innodb;
create table t4(a int) engine= innodb;
create table t5(a int) engine= innodb;
create trigger tr2 after insert on t3 for each row begin
create trigger tr1 after insert on t3 for each row begin
insert into t4(a) values(1);
set @@session.binlog_format= statement;
insert into t4(a) values(2);
......@@ -83,8 +113,27 @@ ERROR HY000: Cannot change the binary logging format inside a stored function or
SELECT @@session.binlog_format;
@@session.binlog_format
ROW
create table t6(a int, b int) engine= innodb;
create table t7(a int) engine= innodb;
create table t8(a int) engine= innodb;
create trigger tr2 after insert on t6 for each row begin
insert into t7(a) values(1);
set @@global.binlog_direct_non_transactional_updates= FALSE;
insert into t7(a) values(2);
insert into t8(a) values(3);
end |
# Test that the session variable 'binlog_format' is read-only
# in sub-statements.
insert into t6(a,b) values(1,1);
ERROR HY000: Cannot change the binlog direct flag inside a stored function or trigger
SELECT @@session.binlog_direct_non_transactional_updates;
@@session.binlog_direct_non_transactional_updates
0
drop table t1;
drop table t2;
drop table t3;
drop table t4;
drop table t5;
drop table t6;
drop table t7;
drop table t8;
--innodb_lock_wait_timeout=2
--innodb_lock_wait_timeout=2 --binlog-direct-non-transactional-updates=FALSE
......@@ -8,6 +8,7 @@ source include/have_innodb.inc;
source include/have_binlog_format_row.inc;
set @save_binlog_format= @@global.binlog_format;
set @save_binlog_dirct= @@global.binlog_direct_non_transactional_updates;
create table t1 (a int) engine= myisam;
create table t2 (a int) engine= innodb;
......@@ -16,19 +17,25 @@ SET AUTOCOMMIT=1;
--echo # Test that the session variable 'binlog_format'
--echo # is writable outside a transaction.
set @@session.binlog_format= statement;
set @@session.binlog_direct_non_transactional_updates= TRUE;
SELECT @@session.binlog_format;
SELECT @@session.binlog_direct_non_transactional_updates;
begin;
--echo # Test that the session variable 'binlog_format' is read-only
--echo # inside a transaction with no preceding updates.
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT
set @@session.binlog_format= mixed;
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
set @@session.binlog_direct_non_transactional_updates= FALSE;
insert into t2 values (1);
--echo # Test that the session variable 'binlog_format' is read-only
--echo # inside a transaction with preceding transactional updates.
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT
set @@session.binlog_format= row;
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
set @@session.binlog_direct_non_transactional_updates= FALSE;
commit;
begin;
......@@ -37,20 +44,27 @@ begin;
--echo # inside a transaction with preceding non-transactional updates.
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT
set @@session.binlog_format= statement;
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
set @@session.binlog_direct_non_transactional_updates= FALSE;
commit;
--echo # Test that the session variable 'binlog_format' is writable
--echo # when AUTOCOMMIT=0, before a transaction has started.
set AUTOCOMMIT=0;
set @@session.binlog_format= row;
set @@session.binlog_direct_non_transactional_updates= FALSE;
SELECT @@session.binlog_format;
SELECT @@session.binlog_direct_non_transactional_updates;
insert into t1 values (4);
--echo # Test that the session variable 'binlog_format' is read-only inside an
--echo # AUTOCOMMIT=0 transaction with preceding non-transactional updates.
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT
set @@session.binlog_format= statement;
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
set @@session.binlog_direct_non_transactional_updates= TRUE;
SELECT @@session.binlog_format;
SELECT @@session.binlog_direct_non_transactional_updates;
commit;
insert into t2 values (5);
......@@ -58,7 +72,10 @@ insert into t2 values (5);
--echo # AUTOCOMMIT=0 transaction with preceding transactional updates.
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT
set @@session.binlog_format= row;
--error ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
set @@session.binlog_direct_non_transactional_updates= TRUE;
SELECT @@session.binlog_format;
SELECT @@session.binlog_direct_non_transactional_updates;
commit;
begin;
......@@ -67,16 +84,19 @@ begin;
--echo # inside a transaction.
SELECT @@global.binlog_format;
set @@global.binlog_format= statement;
set @@global.binlog_direct_non_transactional_updates= TRUE;
SELECT @@global.binlog_format;
SELECT @@global.binlog_direct_non_transactional_updates;
commit;
set @@global.binlog_format= @save_binlog_format;
set @@global.binlog_direct_non_transactional_updates= @save_binlog_dirct;
create table t3(a int, b int) engine= innodb;
create table t4(a int) engine= innodb;
create table t5(a int) engine= innodb;
delimiter |;
eval create trigger tr2 after insert on t3 for each row begin
eval create trigger tr1 after insert on t3 for each row begin
insert into t4(a) values(1);
set @@session.binlog_format= statement;
insert into t4(a) values(2);
......@@ -90,9 +110,29 @@ delimiter ;|
insert into t3(a,b) values(1,1);
SELECT @@session.binlog_format;
create table t6(a int, b int) engine= innodb;
create table t7(a int) engine= innodb;
create table t8(a int) engine= innodb;
delimiter |;
eval create trigger tr2 after insert on t6 for each row begin
insert into t7(a) values(1);
set @@global.binlog_direct_non_transactional_updates= FALSE;
insert into t7(a) values(2);
insert into t8(a) values(3);
end |
delimiter ;|
--echo # Test that the session variable 'binlog_format' is read-only
--echo # in sub-statements.
--error ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT
insert into t6(a,b) values(1,1);
SELECT @@session.binlog_direct_non_transactional_updates;
drop table t1;
drop table t2;
drop table t3;
drop table t4;
drop table t5;
drop table t6;
drop table t7;
drop table t8;
......@@ -29,9 +29,11 @@ mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Query # # use `test`; UPDATE t1, t2 SET m = 2, b = 3 WHERE n = c
mysqld-bin.000001 # Query # # COMMIT
mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Query # # use `test`; UPDATE t3, t2 SET e = 2, b = 3 WHERE f = c
mysqld-bin.000001 # Query # # COMMIT
mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Query # # use `test`; INSERT INTO t3 VALUES (1,1), (1,2), (2,1), (2,2)
mysqld-bin.000001 # Query # # use `test`; UPDATE t1, t3 SET m = 2, e = 3 WHERE n = f
mysqld-bin.000001 # Query # # use `test`; UPDATE t3, t2 SET e = 2, b = 3 WHERE f = c
mysqld-bin.000001 # Query # # COMMIT
mysqld-bin.000001 # Query # # BEGIN
mysqld-bin.000001 # Table_map # # table_id: # (test.t3)
......
......@@ -6,6 +6,7 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
SET @@session.binlog_direct_non_transactional_updates= FALSE;
DROP DATABASE IF EXISTS db1;
CREATE DATABASE db1;
use db1;
......
......@@ -38,12 +38,14 @@ Warning 1196 Some non-transactional changed tables couldn't be rolled back
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 n VALUES (now(),"brown")
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'yellow 2' WHERE i = 3
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'magenta 2' WHERE f = 'red'
master-bin.000001 # Query # # use `test`; INSERT INTO t VALUES (5 + (2 * 10),"brown")
master-bin.000001 # Query # # use `test`; INSERT INTO n VALUES (now(),"brown")
master-bin.000001 # Query # # ROLLBACK
SET AUTOCOMMIT = 1;
BEGIN;
......@@ -63,12 +65,14 @@ 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 n VALUES (now(),"brown")
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'gray 2' WHERE i = 3
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'dark blue 2' WHERE f = 'red'
master-bin.000001 # Query # # use `test`; INSERT INTO t VALUES (6 + (2 * 10),"brown")
master-bin.000001 # Query # # use `test`; INSERT INTO n VALUES (now(),"brown")
master-bin.000001 # Xid # # COMMIT /* XID */
SET AUTOCOMMIT = 0;
UPDATE t SET f = 'yellow 1' WHERE i = 3;
......@@ -88,12 +92,14 @@ Warning 1196 Some non-transactional changed tables couldn't be rolled back
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 n VALUES (now(),"brown")
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'yellow 1' WHERE i = 3
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'magenta 1' WHERE f = 'red'
master-bin.000001 # Query # # use `test`; INSERT INTO t VALUES (5 + (1 * 10),"brown")
master-bin.000001 # Query # # use `test`; INSERT INTO n VALUES (now(),"brown")
master-bin.000001 # Query # # ROLLBACK
SET AUTOCOMMIT = 0;
UPDATE t SET f = 'gray 1' WHERE i = 3;
......@@ -111,12 +117,14 @@ 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 n VALUES (now(),"brown")
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'gray 1' WHERE i = 3
master-bin.000001 # Xid # # COMMIT /* XID */
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; UPDATE t SET f = 'dark blue 1' WHERE f = 'red'
master-bin.000001 # Query # # use `test`; INSERT INTO t VALUES (6 + (1 * 10),"brown")
master-bin.000001 # Query # # use `test`; INSERT INTO n VALUES (now(),"brown")
master-bin.000001 # Xid # # COMMIT /* XID */
source include/diff_master_slave.inc;
source include/diff_master_slave.inc;
......
......@@ -393,8 +393,10 @@ CREATE TEMPORARY TABLE tt_xx (a int);
-b-b-b-b-b-b-b-b-b-b-b- >> << -b-b-b-b-b-b-b-b-b-b-b-
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1(ddl_case) VALUES (11)
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx (a int)
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1(ddl_case) VALUES (11)
master-bin.000001 # Xid # # COMMIT /* XID */
-e-e-e-e-e-e-e-e-e-e-e- >> << -e-e-e-e-e-e-e-e-e-e-e-
......
......@@ -11868,6 +11868,9 @@ Log_name Pos Event_type Server_id End_log_pos Info
-b-b-b-b-b-b-b-b-b-b-b- >> CT << -b-b-b-b-b-b-b-b-b-b-b-
CREATE TEMPORARY TABLE tt_xx_11 (a int) engine=Innodb;;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx_11 (a int) engine=Innodb
master-bin.000001 # Query # # COMMIT
-e-e-e-e-e-e-e-e-e-e-e- >> CT << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> R << -b-b-b-b-b-b-b-b-b-b-b-
ROLLBACK;
......@@ -11875,6 +11878,9 @@ Log_name Pos Event_type Server_id End_log_pos Info
-e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> B T CT R << -b-b-b-b-b-b-b-b-b-b-b-
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx_11 (a int) engine=Innodb
master-bin.000001 # Query # # COMMIT
-e-e-e-e-e-e-e-e-e-e-e- >> B T CT R << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> drop-CT << -b-b-b-b-b-b-b-b-b-b-b-
......@@ -11906,6 +11912,9 @@ Log_name Pos Event_type Server_id End_log_pos Info
-b-b-b-b-b-b-b-b-b-b-b- >> CT << -b-b-b-b-b-b-b-b-b-b-b-
CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb;;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
master-bin.000001 # Query # # COMMIT
-e-e-e-e-e-e-e-e-e-e-e- >> CT << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> R1 << -b-b-b-b-b-b-b-b-b-b-b-
ROLLBACK TO s1;
......@@ -11919,6 +11928,9 @@ Log_name Pos Event_type Server_id End_log_pos Info
-e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> B T S1 T CT R1 R << -b-b-b-b-b-b-b-b-b-b-b-
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx_12 (a int) engine=Innodb
master-bin.000001 # Query # # COMMIT
-e-e-e-e-e-e-e-e-e-e-e- >> B T S1 T CT R1 R << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> drop-CT << -b-b-b-b-b-b-b-b-b-b-b-
......@@ -11942,6 +11954,9 @@ Log_name Pos Event_type Server_id End_log_pos Info
-b-b-b-b-b-b-b-b-b-b-b- >> CT << -b-b-b-b-b-b-b-b-b-b-b-
CREATE TEMPORARY TABLE tt_xx_13 (a int) engine=Innodb;;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx_13 (a int) engine=Innodb
master-bin.000001 # Query # # COMMIT
-e-e-e-e-e-e-e-e-e-e-e- >> CT << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> T << -b-b-b-b-b-b-b-b-b-b-b-
INSERT INTO tt_1(trans_id, stmt_id) VALUES (355, 5);
......@@ -11953,6 +11968,9 @@ Log_name Pos Event_type Server_id End_log_pos Info
-e-e-e-e-e-e-e-e-e-e-e- >> R << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> B T CT T R << -b-b-b-b-b-b-b-b-b-b-b-
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx_13 (a int) engine=Innodb
master-bin.000001 # Query # # COMMIT
-e-e-e-e-e-e-e-e-e-e-e- >> B T CT T R << -e-e-e-e-e-e-e-e-e-e-e-
-b-b-b-b-b-b-b-b-b-b-b- >> drop-CT << -b-b-b-b-b-b-b-b-b-b-b-
......
......@@ -130,8 +130,8 @@ Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = S
Got one of the listed errors
Got one of the listed errors
Got one of the listed errors
Got one of the listed errors
Got one of the listed errors
Warnings:
Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Non-transactional reads or writes are unsafe if they occur after transactional reads or writes inside a transaction.
Warnings:
Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Non-transactional reads or writes are unsafe if they occur after transactional reads or writes inside a transaction.
COMMIT;
......@@ -139,10 +139,7 @@ BEGIN;
Warnings:
Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Non-transactional reads or writes are unsafe if they occur after transactional reads or writes inside a transaction.
Got one of the listed errors
Got one of the listed errors
COMMIT;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
START SLAVE SQL_THREAD;
source include/diff_master_slave.inc;
########################################################################################
# CLEAN
......
......@@ -393,8 +393,10 @@ CREATE TEMPORARY TABLE tt_xx (a int);
-b-b-b-b-b-b-b-b-b-b-b- >> << -b-b-b-b-b-b-b-b-b-b-b-
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1(ddl_case) VALUES (11)
master-bin.000001 # Query # # use `test`; CREATE TEMPORARY TABLE tt_xx (a int)
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1(ddl_case) VALUES (11)
master-bin.000001 # Xid # # COMMIT /* XID */
-e-e-e-e-e-e-e-e-e-e-e- >> << -e-e-e-e-e-e-e-e-e-e-e-
......@@ -429,8 +431,10 @@ DROP TEMPORARY TABLE IF EXISTS new_tt_xx;
-b-b-b-b-b-b-b-b-b-b-b- >> << -b-b-b-b-b-b-b-b-b-b-b-
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1(ddl_case) VALUES (8)
master-bin.000001 # Query # # use `test`; DROP TEMPORARY TABLE IF EXISTS new_tt_xx
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Query # # BEGIN
master-bin.000001 # Query # # use `test`; INSERT INTO tt_1(ddl_case) VALUES (8)
master-bin.000001 # Xid # # COMMIT /* XID */
-e-e-e-e-e-e-e-e-e-e-e- >> << -e-e-e-e-e-e-e-e-e-e-e-
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,6 +4,7 @@ reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
SET @@session.binlog_direct_non_transactional_updates= FALSE;
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
create table t1(n int);
......
......@@ -4,6 +4,7 @@ reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
SET @@session.binlog_direct_non_transactional_updates= FALSE;
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
create table tm (a int auto_increment primary key) engine=myisam;
create table ti (a int auto_increment primary key) engine=innodb;
......
......@@ -8,6 +8,8 @@ call mtr.add_suppression("Unsafe statement binlogged in statement format since B
connection master;
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
SET @@session.binlog_direct_non_transactional_updates= FALSE;
disable_warnings;
DROP DATABASE IF EXISTS db1;
enable_warnings;
......
......@@ -5,4 +5,5 @@
--source include/have_binlog_format_statement.inc
--source include/have_innodb.inc
SET @@session.binlog_direct_non_transactional_updates= FALSE;
--source ./extra/rpl_tests/rpl_start_stop_slave.test
......@@ -6,4 +6,5 @@
-- source include/have_innodb.inc
-- source include/have_binlog_format_statement.inc
SET @@session.binlog_direct_non_transactional_updates= FALSE;
-- source extra/rpl_tests/rpl_stop_middle_group.test
SELECT @@GLOBAL.binlog_direct_non_transactional_updates;
@@GLOBAL.binlog_direct_non_transactional_updates
1
'#---------------------BS_STVARS_002_01----------------------#'
SET @start_value= @@global.binlog_direct_non_transactional_updates;
SELECT COUNT(@@GLOBAL.binlog_direct_non_transactional_updates);
COUNT(@@GLOBAL.binlog_direct_non_transactional_updates)
1
1 Expected
SELECT COUNT(@@SESSION.binlog_direct_non_transactional_updates);
COUNT(@@SESSION.binlog_direct_non_transactional_updates)
1
1 Expected
'#---------------------BS_STVARS_002_02----------------------#'
SET @@GLOBAL.binlog_direct_non_transactional_updates=TRUE;
SELECT @@GLOBAL.binlog_direct_non_transactional_updates;
@@GLOBAL.binlog_direct_non_transactional_updates
1
SET @@SESSION.binlog_direct_non_transactional_updates=TRUE;
SELECT @@SESSION.binlog_direct_non_transactional_updates;
@@SESSION.binlog_direct_non_transactional_updates
1
'#---------------------BS_STVARS_002_03----------------------#'
SELECT
IF(@@GLOBAL.binlog_direct_non_transactional_updates, "ON", "OFF") = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
IF(@@GLOBAL.binlog_direct_non_transactional_updates, "ON", "OFF") = VARIABLE_VALUE
1
1 Expected
SELECT COUNT(@@GLOBAL.binlog_direct_non_transactional_updates);
COUNT(@@GLOBAL.binlog_direct_non_transactional_updates)
1
1 Expected
SELECT COUNT(VARIABLE_VALUE)
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
COUNT(VARIABLE_VALUE)
1
1 Expected
'#---------------------BS_STVARS_002_04----------------------#'
SELECT
IF(@@SESSION.binlog_direct_non_transactional_updates, "ON", "OFF") = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
IF(@@SESSION.binlog_direct_non_transactional_updates, "ON", "OFF") = VARIABLE_VALUE
1
1 Expected
SELECT COUNT(@@SESSION.binlog_direct_non_transactional_updates);
COUNT(@@SESSION.binlog_direct_non_transactional_updates)
1
1 Expected
SELECT COUNT(VARIABLE_VALUE)
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
COUNT(VARIABLE_VALUE)
1
1 Expected
'#---------------------BS_STVARS_002_05----------------------#'
SELECT COUNT(@@binlog_direct_non_transactional_updates);
COUNT(@@binlog_direct_non_transactional_updates)
1
1 Expected
SELECT COUNT(@@local.binlog_direct_non_transactional_updates);
COUNT(@@local.binlog_direct_non_transactional_updates)
1
1 Expected
SELECT COUNT(@@SESSION.binlog_direct_non_transactional_updates);
COUNT(@@SESSION.binlog_direct_non_transactional_updates)
1
1 Expected
SELECT COUNT(@@GLOBAL.binlog_direct_non_transactional_updates);
COUNT(@@GLOBAL.binlog_direct_non_transactional_updates)
1
1 Expected
SET @@global.binlog_direct_non_transactional_updates= @start_value;
######### mysql-test\t\binlog_direct_non_transactional_updates.test ###########
# #
# Variable Name: binlog_direct_non_transactional_updates #
# Scope: Global & Session #
# Access Type: Static #
# Data Type: bool #
# #
# Description:Test Cases of Dynamic System Variable #
# binlog_direct_non_transactional_updates #
# that checks the behavior of this variable in the following ways #
# * Value Check #
# * Scope Check #
# #
# Reference: #
# http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html #
# #
###############################################################################
SELECT @@GLOBAL.binlog_direct_non_transactional_updates;
--echo '#---------------------BS_STVARS_002_01----------------------#'
####################################################################
# Displaying default value #
####################################################################
SET @start_value= @@global.binlog_direct_non_transactional_updates;
SELECT COUNT(@@GLOBAL.binlog_direct_non_transactional_updates);
--echo 1 Expected
SELECT COUNT(@@SESSION.binlog_direct_non_transactional_updates);
--echo 1 Expected
--echo '#---------------------BS_STVARS_002_02----------------------#'
####################################################################
# Check if Value can set #
####################################################################
SET @@GLOBAL.binlog_direct_non_transactional_updates=TRUE;
SELECT @@GLOBAL.binlog_direct_non_transactional_updates;
SET @@SESSION.binlog_direct_non_transactional_updates=TRUE;
SELECT @@SESSION.binlog_direct_non_transactional_updates;
--echo '#---------------------BS_STVARS_002_03----------------------#'
#################################################################
# Check if the value in GLOBAL Table matches value in variable #
#################################################################
SELECT
IF(@@GLOBAL.binlog_direct_non_transactional_updates, "ON", "OFF") = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
--echo 1 Expected
SELECT COUNT(@@GLOBAL.binlog_direct_non_transactional_updates);
--echo 1 Expected
SELECT COUNT(VARIABLE_VALUE)
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
--echo 1 Expected
--echo '#---------------------BS_STVARS_002_04----------------------#'
#################################################################
# Check if the value in SESSION Table matches value in variable #
#################################################################
SELECT
IF(@@SESSION.binlog_direct_non_transactional_updates, "ON", "OFF") = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
--echo 1 Expected
SELECT COUNT(@@SESSION.binlog_direct_non_transactional_updates);
--echo 1 Expected
SELECT COUNT(VARIABLE_VALUE)
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='binlog_direct_non_transactional_updates';
--echo 1 Expected
--echo '#---------------------BS_STVARS_002_05----------------------#'
################################################################################
# Check if binlog_format can be accessed with and without @@ sign #
################################################################################
SELECT COUNT(@@binlog_direct_non_transactional_updates);
--echo 1 Expected
SELECT COUNT(@@local.binlog_direct_non_transactional_updates);
--echo 1 Expected
SELECT COUNT(@@SESSION.binlog_direct_non_transactional_updates);
--echo 1 Expected
SELECT COUNT(@@GLOBAL.binlog_direct_non_transactional_updates);
--echo 1 Expected
SET @@global.binlog_direct_non_transactional_updates= @start_value;
......@@ -199,7 +199,7 @@ class Mutex_sentry
class binlog_cache_data
{
public:
binlog_cache_data(): m_pending(0), before_stmt_pos (MY_OFF_T_UNDEF),
binlog_cache_data(): m_pending(0), before_stmt_pos(MY_OFF_T_UNDEF),
incident(FALSE)
{
cache_log.end_of_file= max_binlog_cache_size;
......@@ -1769,7 +1769,6 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all)
DBUG_RETURN(0);
}
if (mysql_bin_log.check_write_error(thd))
{
/*
......@@ -4191,48 +4190,16 @@ bool MYSQL_BIN_LOG::is_query_in_union(THD *thd, query_id_t query_id_param)
query_id_param >= thd->binlog_evt_union.first_query_id);
}
/*
These functions are placed in this file since they need access to
binlog_hton, which has internal linkage.
*/
int THD::binlog_setup_trx_data()
{
DBUG_ENTER("THD::binlog_setup_trx_data");
binlog_cache_mngr *cache_mngr=
(binlog_cache_mngr*) thd_get_ha_data(this, binlog_hton);
if (cache_mngr)
DBUG_RETURN(0); // Already set up
cache_mngr= (binlog_cache_mngr*) my_malloc(sizeof(binlog_cache_mngr), MYF(MY_ZEROFILL));
if (!cache_mngr ||
open_cached_file(&cache_mngr->stmt_cache.cache_log, mysql_tmpdir,
LOG_PREFIX, binlog_cache_size, MYF(MY_WME)) ||
open_cached_file(&cache_mngr->trx_cache.cache_log, mysql_tmpdir,
LOG_PREFIX, binlog_cache_size, MYF(MY_WME)))
{
my_free((uchar*)cache_mngr, MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(1); // Didn't manage to set it up
}
thd_set_ha_data(this, binlog_hton, cache_mngr);
cache_mngr= new (thd_get_ha_data(this, binlog_hton)) binlog_cache_mngr;
DBUG_RETURN(0);
}
/**
This function checks if a transactional talbe was updated by the
current transaction.
@param thd The client thread that executed the current statement.
@return
@c true if a transactional table was updated, @false otherwise.
@c true if a transactional table was updated, @c false otherwise.
*/
bool
trans_has_updated_trans_table(THD* thd)
trans_has_updated_trans_table(const THD* thd)
{
binlog_cache_mngr *const cache_mngr=
(binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
......@@ -4246,10 +4213,10 @@ trans_has_updated_trans_table(THD* thd)
@param thd The client thread that executed the current statement.
@return
@c true if a transactional table was updated, @false otherwise.
@c true if a transactional table was updated, @c false otherwise.
*/
bool
stmt_has_updated_trans_table(THD *thd)
stmt_has_updated_trans_table(const THD *thd)
{
Ha_trx_info *ha_info;
......@@ -4261,6 +4228,60 @@ stmt_has_updated_trans_table(THD *thd)
return (FALSE);
}
/**
This function checks if either a trx-cache or a non-trx-cache should
be used. If @c bin_log_direct_non_trans_update is active, the cache
to be used depends on the flag @c is_transactional.
Otherswise, we use the trx-cache if either the @c is_transactional
is true or the trx-cache is not empty.
@param thd The client thread.
@param is_transactional The changes are related to a trx-table.
@return
@c true if a trx-cache should be used, @c false otherwise.
*/
bool use_trans_cache(const THD* thd, bool is_transactional)
{
binlog_cache_mngr *const cache_mngr=
(binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
return
(thd->variables.binlog_direct_non_trans_update ? is_transactional :
(cache_mngr->trx_cache.empty() && !is_transactional ? FALSE : TRUE));
}
/*
These functions are placed in this file since they need access to
binlog_hton, which has internal linkage.
*/
int THD::binlog_setup_trx_data()
{
DBUG_ENTER("THD::binlog_setup_trx_data");
binlog_cache_mngr *cache_mngr=
(binlog_cache_mngr*) thd_get_ha_data(this, binlog_hton);
if (cache_mngr)
DBUG_RETURN(0); // Already set up
cache_mngr= (binlog_cache_mngr*) my_malloc(sizeof(binlog_cache_mngr), MYF(MY_ZEROFILL));
if (!cache_mngr ||
open_cached_file(&cache_mngr->stmt_cache.cache_log, mysql_tmpdir,
LOG_PREFIX, binlog_cache_size, MYF(MY_WME)) ||
open_cached_file(&cache_mngr->trx_cache.cache_log, mysql_tmpdir,
LOG_PREFIX, binlog_cache_size, MYF(MY_WME)))
{
my_free((uchar*)cache_mngr, MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(1); // Didn't manage to set it up
}
thd_set_ha_data(this, binlog_hton, cache_mngr);
cache_mngr= new (thd_get_ha_data(this, binlog_hton)) binlog_cache_mngr;
DBUG_RETURN(0);
}
/*
Function to start a statement and optionally a transaction for the
binary log.
......@@ -4369,8 +4390,8 @@ int THD::binlog_write_table_map(TABLE *table, bool is_transactional)
binlog_cache_mngr *const cache_mngr=
(binlog_cache_mngr*) thd_get_ha_data(this, binlog_hton);
IO_CACHE *file= cache_mngr->get_binlog_cache_log(is_transactional);
IO_CACHE *file=
cache_mngr->get_binlog_cache_log(use_trans_cache(this, is_transactional));
if ((error= the_event.write(file)))
DBUG_RETURN(error);
......@@ -4405,7 +4426,7 @@ THD::binlog_get_pending_rows_event(bool is_transactional) const
if (cache_mngr)
{
binlog_cache_data *cache_data=
cache_mngr->get_binlog_cache_data(is_transactional);
cache_mngr->get_binlog_cache_data(use_trans_cache(this, is_transactional));
rows= cache_data->pending();
}
......@@ -4434,7 +4455,7 @@ THD::binlog_set_pending_rows_event(Rows_log_event* ev, bool is_transactional)
DBUG_ASSERT(cache_mngr);
binlog_cache_data *cache_data=
cache_mngr->get_binlog_cache_data(is_transactional);
cache_mngr->get_binlog_cache_data(use_trans_cache(this, is_transactional));
cache_data->set_pending(ev);
}
......@@ -4460,7 +4481,7 @@ MYSQL_BIN_LOG::remove_pending_rows_event(THD *thd, bool is_transactional)
DBUG_ASSERT(cache_mngr);
binlog_cache_data *cache_data=
cache_mngr->get_binlog_cache_data(is_transactional);
cache_mngr->get_binlog_cache_data(use_trans_cache(thd, is_transactional));
if (Rows_log_event* pending= cache_data->pending())
{
......@@ -4497,7 +4518,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
DBUG_ASSERT(cache_mngr);
binlog_cache_data *cache_data=
cache_mngr->get_binlog_cache_data(is_transactional);
cache_mngr->get_binlog_cache_data(use_trans_cache(thd, is_transactional));
DBUG_PRINT("info", ("cache_mngr->pending(): 0x%lx", (long) cache_data->pending()));
......@@ -4608,35 +4629,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
binlog_cache_mngr *const cache_mngr=
(binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
/*
If we are about to use write rows, we just need to check the type of
the event (either transactional or non-transactional) in order to
choose the cache.
*/
if (thd->is_current_stmt_binlog_format_row())
{
file= cache_mngr->get_binlog_cache_log(event_info->use_trans_cache());
cache_data= cache_mngr->get_binlog_cache_data(event_info->use_trans_cache());
}
/*
However, if we are about to write statements we need to consider other
things. We use the non-transactional cache when:
. the transactional cache is empty which means that there were no
early statement on behalf of the transaction.
. the respective event is tagged as non-transactional.
*/
else if (cache_mngr->trx_cache.empty() &&
!event_info->use_trans_cache())
{
file= &cache_mngr->stmt_cache.cache_log;
cache_data= &cache_mngr->stmt_cache;
}
else
{
file= &cache_mngr->trx_cache.cache_log;
cache_data= &cache_mngr->trx_cache;
}
bool is_trans_cache= use_trans_cache(thd, event_info->use_trans_cache());
file= cache_mngr->get_binlog_cache_log(is_trans_cache);
cache_data= cache_mngr->get_binlog_cache_data(is_trans_cache);
thd->binlog_start_trans_and_stmt();
}
......@@ -4898,7 +4893,6 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
do
{
/*
if we only got a partial header in the last iteration,
get the other half now and process a full header.
......
......@@ -20,8 +20,9 @@ class Relay_log_info;
class Format_description_log_event;
bool trans_has_updated_trans_table(THD* thd);
bool stmt_has_updated_trans_table(THD *thd);
bool trans_has_updated_trans_table(const THD* thd);
bool stmt_has_updated_trans_table(const THD *thd);
bool use_trans_cache(const THD* thd, bool is_transactional);
/*
Transaction Coordinator log - a base abstract class
......
......@@ -6311,3 +6311,8 @@ ER_WRONG_NATIVE_TABLE_STRUCTURE
ER_WRONG_PERFSCHEMA_USAGE
eng "Invalid performance_schema usage."
ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction"
ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot change the binlog direct flag inside a stored function or trigger"
......@@ -6305,3 +6305,7 @@ ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT
eng "The syntax '%s' is deprecated and will be removed in MySQL %s."
ger "Die Syntax '%s' ist veraltet und wird in MySQL %s entfernt."
ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot modify @@session.binlog_direct_non_transactional_updates inside a transaction"
ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT
eng "Cannot change the binlog direct flag inside a stored function or trigger"
......@@ -373,6 +373,7 @@ typedef struct system_variables
ulong group_concat_max_len;
uint binlog_format; ///< binlog format for this thd (see enum_binlog_format)
my_bool binlog_direct_non_trans_update;
uint completion_type;
uint query_cache_type;
uint tx_isolation;
......
......@@ -299,6 +299,48 @@ static Sys_var_enum Sys_binlog_format(
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_format_check),
ON_UPDATE(fix_binlog_format_after_update));
static bool binlog_direct_check(sys_var *self, THD *thd, set_var *var)
{
/*
Makes the session variable 'binlog_direct_non_transactional_updates'
read-only inside a transaction.
*/
if (thd->active_transaction() && (var->type == OPT_SESSION))
{
my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0));
return 1;
}
/*
Makes the session variable 'binlog_direct_non_transactional_updates'
read-only if within a procedure, trigger or function.
*/
if (thd->in_sub_stmt)
{
my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0));
return 1;
}
if (check_has_super(self, thd, var))
return true;
if (var->type == OPT_GLOBAL ||
(thd->variables.binlog_direct_non_trans_update ==
var->save_result.ulonglong_value))
return false;
return false;
}
static Sys_var_mybool Sys_binlog_direct(
"binlog_direct_non_transactional_updates",
"Causes updates to non-transactional engines using statement format to "
"be written directly to binary log. Before using this option make sure "
"that there are no dependencies between transactional and "
"non-transactional tables such as in the statement INSERT INTO t_myisam "
"SELECT * FROM t_innodb; otherwise, slaves may diverge from the master.",
SESSION_VAR(binlog_direct_non_trans_update),
CMD_LINE(OPT_ARG), DEFAULT(FALSE),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_direct_check));
static Sys_var_ulong Sys_bulk_insert_buff_size(
"bulk_insert_buffer_size", "Size of tree cache used in bulk "
"insert optimisation. Note that this is a limit per thread!",
......
......@@ -51,6 +51,13 @@ server-id = 1
# binary logging format - mixed recommended
#binlog_format=mixed
# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = @localstatedir@/
#innodb_data_file_path = ibdata1:10M:autoextend
......
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