mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 03:51:50 +01:00
f3985c649d
General overview: The logic for switching to row format when binlog_format=MIXED had numerous flaws. The underlying problem was the lack of a consistent architecture. General purpose of this changeset: This changeset introduces an architecture for switching to row format when binlog_format=MIXED. It enforces the architecture where it has to. It leaves some bugs to be fixed later. It adds extensive tests to verify that unsafe statements work as expected and that appropriate errors are produced by problems with the selection of binlog format. It was not practical to split this into smaller pieces of work. Problem 1: To determine the logging mode, the code has to take several parameters into account (namely: (1) the value of binlog_format; (2) the capabilities of the engines; (3) the type of the current statement: normal, unsafe, or row injection). These parameters may conflict in several ways, namely: - binlog_format=STATEMENT for a row injection - binlog_format=STATEMENT for an unsafe statement - binlog_format=STATEMENT for an engine only supporting row logging - binlog_format=ROW for an engine only supporting statement logging - statement is unsafe and engine does not support row logging - row injection in a table that does not support statement logging - statement modifies one table that does not support row logging and one that does not support statement logging Several of these conflicts were not detected, or were detected with an inappropriate error message. The problem of BUG#39934 was that no appropriate error message was written for the case when an engine only supporting row logging executed a row injection with binlog_format=ROW. However, all above cases must be handled. Fix 1: Introduce new error codes (sql/share/errmsg.txt). Ensure that all conditions are detected and handled in decide_logging_format() Problem 2: The binlog format shall be determined once per statement, in decide_logging_format(). It shall not be changed before or after that. Before decide_logging_format() is called, all information necessary to determine the logging format must be available. This principle ensures that all unsafe statements are handled in a consistent way. However, this principle is not followed: thd->set_current_stmt_binlog_row_based_if_mixed() is called in several places, including from code executing UPDATE..LIMIT, INSERT..SELECT..LIMIT, DELETE..LIMIT, INSERT DELAYED, and SET @@binlog_format. After Problem 1 was fixed, that caused inconsistencies where these unsafe statements would not print the appropriate warnings or errors for some of the conflicts. Fix 2: Remove calls to THD::set_current_stmt_binlog_row_based_if_mixed() from code executed after decide_logging_format(). Compensate by calling the set_current_stmt_unsafe() at parse time. This way, all unsafe statements are detected by decide_logging_format(). Problem 3: INSERT DELAYED is not unsafe: it is logged in statement format even if binlog_format=MIXED, and no warning is printed even if binlog_format=STATEMENT. This is BUG#45825. Fix 3: Made INSERT DELAYED set itself to unsafe at parse time. This allows decide_logging_format() to detect that a warning should be printed or the binlog_format changed. Problem 4: LIMIT clause were not marked as unsafe when executed inside stored functions/triggers/views/prepared statements. This is BUG#45785. Fix 4: Make statements containing the LIMIT clause marked as unsafe at parse time, instead of at execution time. This allows propagating unsafe-ness to the view.
309 lines
6.6 KiB
Text
309 lines
6.6 KiB
Text
#############################################
|
|
#Authors: TU and Jeb
|
|
#Date: 2007/04
|
|
#Purpose: Generic replication to cluster
|
|
# and ensuring that the ndb_apply_status
|
|
# table is updated.
|
|
#############################################
|
|
# Notes:
|
|
# include/select_ndb_apply_status.inc
|
|
# Selects out the log name, start & end pos
|
|
# from the ndb_apply_status table
|
|
#
|
|
# include/show_binlog_using_logname.inc
|
|
# To select out 1 row from offset 1
|
|
# from the start position in the binlog whose
|
|
# name is = log_name
|
|
#
|
|
# include/tpcb.inc
|
|
# Creates DATABASE tpcb, the tables and
|
|
# stored procedures for loading the DB
|
|
# and for running transactions against DB.
|
|
##############################################
|
|
|
|
|
|
--echo
|
|
--echo *** Test 1 ***
|
|
--echo
|
|
|
|
connection master;
|
|
create table t1 (a int key, b int) engine innodb;
|
|
create table t2 (a int key, b int) engine innodb;
|
|
|
|
--echo
|
|
|
|
--sync_slave_with_master
|
|
alter table t1 engine ndb;
|
|
alter table t2 engine ndb;
|
|
|
|
--echo
|
|
|
|
# check binlog position without begin
|
|
connection master;
|
|
insert into t1 values (1,2);
|
|
|
|
--echo
|
|
|
|
--sync_slave_with_master
|
|
--source include/select_ndb_apply_status.inc
|
|
|
|
--echo
|
|
|
|
connection master;
|
|
--echo # Now check that that is in the apply_status table is consistant
|
|
--echo # with what is in the binlog
|
|
--echo
|
|
--echo # since insert is done with transactional engine, expect a BEGIN
|
|
--echo # at <start_pos>
|
|
--echo
|
|
--replace_result $start_pos <start_pos>
|
|
--replace_column 5 #
|
|
--eval show binlog events from $start_pos limit 1
|
|
|
|
--echo
|
|
--echo # Now the insert, one step after
|
|
--echo
|
|
--replace_result $start_pos <start_pos>
|
|
--replace_column 2 # 5 #
|
|
--eval show binlog events from $start_pos limit 1,1
|
|
|
|
--echo
|
|
--echo # and the COMMIT should be at <end_pos>
|
|
--echo
|
|
--replace_result $start_pos <start_pos> $end_pos <end_pos>
|
|
--replace_column 2 #
|
|
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
|
|
--eval show binlog events from $start_pos limit 2,1
|
|
|
|
--echo
|
|
|
|
# check binlog position with begin
|
|
begin;
|
|
insert into t1 values (2,3);
|
|
insert into t2 values (3,4);
|
|
commit;
|
|
|
|
--echo
|
|
|
|
--sync_slave_with_master
|
|
--source include/select_ndb_apply_status.inc
|
|
|
|
connection master;
|
|
--replace_result $start_pos <start_pos>
|
|
--replace_column 5 #
|
|
--eval show binlog events from $start_pos limit 1
|
|
--echo
|
|
--replace_result $start_pos <start_pos>
|
|
--replace_column 2 # 4 # 5 #
|
|
--eval show binlog events from $start_pos limit 1,2
|
|
--echo
|
|
--replace_result $start_pos <start_pos> $end_pos <end_pos>
|
|
--replace_column 2 #
|
|
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
|
|
--eval show binlog events from $start_pos limit 3,1
|
|
|
|
--echo
|
|
|
|
connection master;
|
|
DROP TABLE test.t1, test.t2;
|
|
--sync_slave_with_master
|
|
SHOW TABLES;
|
|
|
|
# Run in some transactions using stored procedures
|
|
# and ensure that the ndb_apply_status table is
|
|
# updated to show the transactions
|
|
|
|
|
|
--echo
|
|
--echo *** Test 2 ***
|
|
--echo
|
|
|
|
# Create database/tables and stored procdures
|
|
connection master;
|
|
--source include/tpcb.inc
|
|
|
|
# Switch tables on slave to use NDB
|
|
--sync_slave_with_master
|
|
USE tpcb;
|
|
ALTER TABLE account ENGINE NDB;
|
|
ALTER TABLE branch ENGINE NDB;
|
|
ALTER TABLE teller ENGINE NDB;
|
|
ALTER TABLE history ENGINE NDB;
|
|
|
|
--echo
|
|
|
|
# Load DB tpcb and run some transactions
|
|
connection master;
|
|
--disable_query_log
|
|
CALL tpcb.load();
|
|
SET AUTOCOMMIT=0;
|
|
let $run= 5;
|
|
while ($run)
|
|
{
|
|
START TRANSACTION;
|
|
--disable_warnings
|
|
--eval CALL tpcb.trans($rpl_format);
|
|
--enable_warnings
|
|
eval SET @my_errno= $mysql_errno;
|
|
let $run_good= `SELECT @my_errno = 0`;
|
|
let $run_bad= `SELECT @my_errno <> 0`;
|
|
if ($run_good)
|
|
{
|
|
COMMIT;
|
|
}
|
|
if ($run_bad)
|
|
{
|
|
ROLLBACK;
|
|
}
|
|
dec $run;
|
|
}
|
|
|
|
SET AUTOCOMMIT=1;
|
|
--enable_query_log
|
|
|
|
--sync_slave_with_master
|
|
--source include/select_ndb_apply_status.inc
|
|
|
|
--echo
|
|
|
|
connection master;
|
|
--source include/show_binlog_using_logname.inc
|
|
|
|
# Flush the logs on the master moving all
|
|
# Transaction to a new binlog and ensure
|
|
# that the ndb_apply_status table is updated
|
|
# to show the use of the new binlog.
|
|
|
|
--echo
|
|
--echo ** Test 3 **
|
|
--echo
|
|
|
|
# Flush logs on master which should force it
|
|
# to switch to binlog #2
|
|
|
|
FLUSH LOGS;
|
|
|
|
# Run in some transaction to increase end pos in
|
|
# binlog
|
|
|
|
--disable_query_log
|
|
SET AUTOCOMMIT=0;
|
|
let $run= 5;
|
|
while ($run)
|
|
{
|
|
START TRANSACTION;
|
|
--disable_warnings
|
|
--eval CALL tpcb.trans($rpl_format);
|
|
--enable_warnings
|
|
eval SET @my_errno= $mysql_errno;
|
|
let $run_good= `SELECT @my_errno = 0`;
|
|
let $run_bad= `SELECT @my_errno <> 0`;
|
|
if ($run_good)
|
|
{
|
|
COMMIT;
|
|
}
|
|
if ($run_bad)
|
|
{
|
|
ROLLBACK;
|
|
}
|
|
dec $run;
|
|
}
|
|
SET AUTOCOMMIT=1;
|
|
--enable_query_log
|
|
|
|
--echo
|
|
|
|
--sync_slave_with_master
|
|
--source include/select_ndb_apply_status.inc
|
|
|
|
--echo
|
|
|
|
connection master;
|
|
--source include/show_binlog_using_logname.inc
|
|
|
|
# Now we reset both the master and the slave
|
|
# Run some more transaction and ensure
|
|
# that the ndb_apply_status is updated
|
|
# correctly
|
|
|
|
--echo
|
|
--echo ** Test 4 **
|
|
--echo
|
|
|
|
# Reset both slave and master
|
|
# This should reset binlog to #1
|
|
--source include/master-slave-reset.inc
|
|
|
|
--echo
|
|
|
|
# Run in some transactions and check
|
|
connection master;
|
|
--disable_query_log
|
|
SET AUTOCOMMIT=0;
|
|
let $run= 5;
|
|
while ($run)
|
|
{
|
|
START TRANSACTION;
|
|
--disable_warnings
|
|
--eval CALL tpcb.trans($rpl_format);
|
|
--enable_warnings
|
|
eval SET @my_errno= $mysql_errno;
|
|
let $run_good= `SELECT @my_errno = 0`;
|
|
let $run_bad= `SELECT @my_errno <> 0`;
|
|
if ($run_good)
|
|
{
|
|
COMMIT;
|
|
}
|
|
if ($run_bad)
|
|
{
|
|
ROLLBACK;
|
|
}
|
|
dec $run;
|
|
}
|
|
SET AUTOCOMMIT=1;
|
|
--enable_query_log
|
|
|
|
--sync_slave_with_master
|
|
--source include/select_ndb_apply_status.inc
|
|
|
|
--echo
|
|
|
|
connection master;
|
|
--source include/show_binlog_using_logname.inc
|
|
|
|
# Since we are doing replication, it is a good
|
|
# idea to check to make sure all data was
|
|
# Replicated correctly
|
|
|
|
--echo
|
|
--echo *** DUMP MASTER & SLAVE FOR COMPARE ********
|
|
|
|
--exec $MYSQL_DUMP -n -t --compact --order-by-primary --skip-extended-insert tpcb account teller branch history > $MYSQLTEST_VARDIR/tmp/master_apply_status.sql
|
|
|
|
--exec $MYSQL_DUMP_SLAVE -n -t --compact --order-by-primary --skip-extended-insert tpcb account teller branch history > $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql
|
|
|
|
connection master;
|
|
DROP DATABASE tpcb;
|
|
|
|
--sync_slave_with_master
|
|
|
|
####### Commenting out until decision on Bug#27960 ###########
|
|
|
|
#--source include/select_ndb_apply_status.inc
|
|
|
|
#connection master;
|
|
#--eval SHOW BINLOG EVENTS in '$log_name' from $start_pos
|
|
#--source include/show_binlog_using_logname.inc
|
|
|
|
--echo ****** Do dumps compare ************
|
|
|
|
|
|
diff_files $MYSQLTEST_VARDIR/tmp/master_apply_status.sql $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql;
|
|
|
|
## Note: Ths files should only get removed, if the above diff succeeds.
|
|
|
|
--exec rm $MYSQLTEST_VARDIR/tmp/master_apply_status.sql
|
|
--exec rm $MYSQLTEST_VARDIR/tmp/slave_apply_status.sql
|
|
|
|
|
|
# End of 5.1 Test
|