2005-12-22 06:39:02 +01:00
|
|
|
#############################################################################
|
|
|
|
# Original Author: JBM #
|
|
|
|
# Original Date: Aug/18/2005 #
|
|
|
|
#############################################################################
|
|
|
|
# TEST: To test the LOAD_FILE() in rbr #
|
|
|
|
#############################################################################
|
2006-01-18 00:45:23 +01:00
|
|
|
# Change Author: JBM
|
|
|
|
# Change Date: 2006-01-16
|
|
|
|
# Change: Added Order by for NDB
|
|
|
|
##########
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
# Includes
|
|
|
|
-- source include/master-slave.inc
|
BUG#39701: Mixed binlog format does not switch to row mode on
LOAD_FILE
LOAD_FILE is not safe to replicate in STATEMENT mode, because it
depends on a file (which is loaded on master and may not exist in
slave(s)). This leads to scenarios on which the slave replicates the
statement with 'load_file' and it will try to load the file from local
file system. Given that the file may not exist in the slave filesystem
the operation will not succeed (probably returning NULL), causing
master and slave(s) to diverge. However, when using MIXED mode
replication, this can be made to work, if the statement including
LOAD_FILE is marked as unsafe, triggering a switch to ROW mode,
meaning that the contents of the file are written to binlog as row
events. Consequently, the contents from the file in the master will
reach the slave via the binlog.
This patch addresses this bug by marking the load_file function as
unsafe. When in mixed mode and when LOAD_FILE is issued, there will be
a switch to row mode. Furthermore, when in statement mode, the
LOAD_FILE will raise a warning that the statement is unsafe in that
mode.
2009-03-24 18:27:33 +00:00
|
|
|
-- source include/have_binlog_format_mixed_or_row.inc
|
2005-12-22 06:39:02 +01:00
|
|
|
|
BUG#39701: Mixed binlog format does not switch to row mode on
LOAD_FILE
LOAD_FILE is not safe to replicate in STATEMENT mode, because it
depends on a file (which is loaded on master and may not exist in
slave(s)). This leads to scenarios on which the slave replicates the
statement with 'load_file' and it will try to load the file from local
file system. Given that the file may not exist in the slave filesystem
the operation will not succeed (probably returning NULL), causing
master and slave(s) to diverge. However, when using MIXED mode
replication, this can be made to work, if the statement including
LOAD_FILE is marked as unsafe, triggering a switch to ROW mode,
meaning that the contents of the file are written to binlog as row
events. Consequently, the contents from the file in the master will
reach the slave via the binlog.
This patch addresses this bug by marking the load_file function as
unsafe. When in mixed mode and when LOAD_FILE is issued, there will be
a switch to row mode. Furthermore, when in statement mode, the
LOAD_FILE will raise a warning that the statement is unsafe in that
mode.
2009-03-24 18:27:33 +00:00
|
|
|
-- source extra/rpl_tests/rpl_loadfile.test
|
|
|
|
|
|
|
|
# BUG#39701: Mixed binlog format does not switch to row mode on LOAD_FILE
|
|
|
|
#
|
|
|
|
# DESCRIPTION
|
|
|
|
#
|
|
|
|
# Problem: when using load_file string function and mixed binlogging format
|
|
|
|
# there was no switch to row based binlogging format. This leads
|
|
|
|
# to scenarios on which the slave replicates the statement and it
|
|
|
|
# will try to load the file from local file system, which in most
|
|
|
|
# likely it will not exist.
|
|
|
|
#
|
|
|
|
# Solution:
|
|
|
|
# Marking this function as unsafe for statement format, makes the
|
|
|
|
# statement using it to be logged in row based format. As such, data
|
|
|
|
# replicated from the master, becomes the content of the loaded file.
|
|
|
|
# Consequently, the slave receives the necessary data to complete
|
|
|
|
# the load_file instruction correctly.
|
|
|
|
#
|
|
|
|
# IMPLEMENTATION
|
|
|
|
#
|
|
|
|
# The test is implemented as follows:
|
|
|
|
#
|
|
|
|
# On Master,
|
|
|
|
# i) write to file the desired content.
|
|
|
|
# ii) create table and stored procedure with load_file
|
|
|
|
# iii) stop slave
|
|
|
|
# iii) execute load_file
|
|
|
|
# iv) remove file
|
|
|
|
#
|
|
|
|
# On Slave,
|
|
|
|
# v) start slave
|
|
|
|
# vi) sync it with master so that it gets the updates from binlog (which
|
|
|
|
# should have bin logged in row format).
|
|
|
|
#
|
|
|
|
# If the the binlog format does not change to row, then the assertion
|
|
|
|
# done in the following step fails. This happens because tables differ
|
|
|
|
# since the file does not exist anymore, meaning that when slave
|
|
|
|
# attempts to execute LOAD_FILE statement it inserts NULL on table
|
|
|
|
# instead of the same contents that the master loaded when it executed
|
|
|
|
# the procedure (which was executed when file existed).
|
|
|
|
#
|
|
|
|
# vii) assert that the contents of master and slave
|
|
|
|
# table are the same
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
connection master;
|
BUG#39701: Mixed binlog format does not switch to row mode on
LOAD_FILE
LOAD_FILE is not safe to replicate in STATEMENT mode, because it
depends on a file (which is loaded on master and may not exist in
slave(s)). This leads to scenarios on which the slave replicates the
statement with 'load_file' and it will try to load the file from local
file system. Given that the file may not exist in the slave filesystem
the operation will not succeed (probably returning NULL), causing
master and slave(s) to diverge. However, when using MIXED mode
replication, this can be made to work, if the statement including
LOAD_FILE is marked as unsafe, triggering a switch to ROW mode,
meaning that the contents of the file are written to binlog as row
events. Consequently, the contents from the file in the master will
reach the slave via the binlog.
This patch addresses this bug by marking the load_file function as
unsafe. When in mixed mode and when LOAD_FILE is issued, there will be
a switch to row mode. Furthermore, when in statement mode, the
LOAD_FILE will raise a warning that the statement is unsafe in that
mode.
2009-03-24 18:27:33 +00:00
|
|
|
source include/reset_master_and_slave.inc;
|
|
|
|
|
|
|
|
connection master;
|
|
|
|
let $file= $MYSQLTEST_VARDIR/tmp/bug_39701.data;
|
|
|
|
|
|
|
|
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
|
|
|
|
--eval SELECT repeat('x',20) INTO OUTFILE '$file'
|
|
|
|
|
|
|
|
disable_warnings;
|
|
|
|
DROP TABLE IF EXISTS t1;
|
|
|
|
enable_warnings;
|
|
|
|
|
|
|
|
CREATE TABLE t1 (t text);
|
|
|
|
DELIMITER |;
|
2009-03-27 12:59:31 +02:00
|
|
|
CREATE PROCEDURE p(file varchar(4096))
|
BUG#39701: Mixed binlog format does not switch to row mode on
LOAD_FILE
LOAD_FILE is not safe to replicate in STATEMENT mode, because it
depends on a file (which is loaded on master and may not exist in
slave(s)). This leads to scenarios on which the slave replicates the
statement with 'load_file' and it will try to load the file from local
file system. Given that the file may not exist in the slave filesystem
the operation will not succeed (probably returning NULL), causing
master and slave(s) to diverge. However, when using MIXED mode
replication, this can be made to work, if the statement including
LOAD_FILE is marked as unsafe, triggering a switch to ROW mode,
meaning that the contents of the file are written to binlog as row
events. Consequently, the contents from the file in the master will
reach the slave via the binlog.
This patch addresses this bug by marking the load_file function as
unsafe. When in mixed mode and when LOAD_FILE is issued, there will be
a switch to row mode. Furthermore, when in statement mode, the
LOAD_FILE will raise a warning that the statement is unsafe in that
mode.
2009-03-24 18:27:33 +00:00
|
|
|
BEGIN
|
|
|
|
INSERT INTO t1 VALUES (LOAD_FILE(file));
|
|
|
|
END|
|
|
|
|
DELIMITER ;|
|
|
|
|
|
|
|
|
# stop slave before issuing the load_file on master
|
2005-12-22 06:39:02 +01:00
|
|
|
connection slave;
|
BUG#39701: Mixed binlog format does not switch to row mode on
LOAD_FILE
LOAD_FILE is not safe to replicate in STATEMENT mode, because it
depends on a file (which is loaded on master and may not exist in
slave(s)). This leads to scenarios on which the slave replicates the
statement with 'load_file' and it will try to load the file from local
file system. Given that the file may not exist in the slave filesystem
the operation will not succeed (probably returning NULL), causing
master and slave(s) to diverge. However, when using MIXED mode
replication, this can be made to work, if the statement including
LOAD_FILE is marked as unsafe, triggering a switch to ROW mode,
meaning that the contents of the file are written to binlog as row
events. Consequently, the contents from the file in the master will
reach the slave via the binlog.
This patch addresses this bug by marking the load_file function as
unsafe. When in mixed mode and when LOAD_FILE is issued, there will be
a switch to row mode. Furthermore, when in statement mode, the
LOAD_FILE will raise a warning that the statement is unsafe in that
mode.
2009-03-24 18:27:33 +00:00
|
|
|
source include/stop_slave.inc;
|
|
|
|
|
|
|
|
connection master;
|
|
|
|
|
|
|
|
# test: check that logging falls back to rbr.
|
|
|
|
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
|
|
|
|
--eval CALL p('$file')
|
|
|
|
|
|
|
|
# test: remove the file from the filesystem and assert that slave still
|
|
|
|
# gets the loaded file
|
|
|
|
remove_file $file;
|
|
|
|
|
|
|
|
# now that the file is removed it is safe (regarding what we want to test)
|
|
|
|
# to start slave
|
|
|
|
connection slave;
|
|
|
|
source include/start_slave.inc;
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2006-01-18 00:45:23 +01:00
|
|
|
connection master;
|
2006-02-13 19:03:12 +01:00
|
|
|
sync_slave_with_master;
|
|
|
|
|
BUG#39701: Mixed binlog format does not switch to row mode on
LOAD_FILE
LOAD_FILE is not safe to replicate in STATEMENT mode, because it
depends on a file (which is loaded on master and may not exist in
slave(s)). This leads to scenarios on which the slave replicates the
statement with 'load_file' and it will try to load the file from local
file system. Given that the file may not exist in the slave filesystem
the operation will not succeed (probably returning NULL), causing
master and slave(s) to diverge. However, when using MIXED mode
replication, this can be made to work, if the statement including
LOAD_FILE is marked as unsafe, triggering a switch to ROW mode,
meaning that the contents of the file are written to binlog as row
events. Consequently, the contents from the file in the master will
reach the slave via the binlog.
This patch addresses this bug by marking the load_file function as
unsafe. When in mixed mode and when LOAD_FILE is issued, there will be
a switch to row mode. Furthermore, when in statement mode, the
LOAD_FILE will raise a warning that the statement is unsafe in that
mode.
2009-03-24 18:27:33 +00:00
|
|
|
# assertion: assert that the slave got the updates even
|
|
|
|
# if the file was removed before the slave started,
|
|
|
|
# meaning that contents were indeed transfered
|
|
|
|
# through binlog (in row format)
|
|
|
|
let $diff_table_1=master:test.t1;
|
|
|
|
let $diff_table_2=slave:test.t1;
|
|
|
|
source include/diff_tables.inc;
|
|
|
|
|
|
|
|
# CLEAN UP
|
|
|
|
DROP TABLE t1;
|
|
|
|
DROP PROCEDURE p;
|
|
|
|
sync_slave_with_master;
|