Commit 0ce86cdc authored by cbell/Chuck@mysql_cab's avatar cbell/Chuck@mysql_cab

BUG#17654 : --read-from-remote-server causes core

This patch corrects a problem encountered when reading the binlog from a remote
host. The application was crashing because the buffer variable (temp_buf) in 
log_event was not pointing to the incoming data. For a normal file read, this 
buffer is allocated by a previous call of read_log_event. However, when reading
from a remote host, the first call to read_log_event is not executed therefore
no buffer is allocated. Furthermore, there is no need to allocate a new buffer 
because the incoming stream is what needs to be read. 

This patch adds the call to initialize the temp_buf variable if reading from a 
remote host. It also adds a check at destroy time to ensure the temp_buf is not
freed if reading from a remote host.
parent 73cffa77
...@@ -682,8 +682,16 @@ Begin_load_query event for file_id: %u\n", exlq->file_id); ...@@ -682,8 +682,16 @@ Begin_load_query event for file_id: %u\n", exlq->file_id);
end: end:
rec_count++; rec_count++;
/*
Destroy the log_event object. If reading from a remote host,
set the temp_buf to NULL so that memory isn't freed twice.
*/
if (ev) if (ev)
{
if (remote_opt)
ev->temp_buf= 0;
delete ev; delete ev;
}
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -1172,6 +1180,12 @@ could be out of memory"); ...@@ -1172,6 +1180,12 @@ could be out of memory");
error= 1; error= 1;
goto err; goto err;
} }
/*
If reading from a remote host, ensure the temp_buf for the
Log_event class is pointing to the incoming stream.
*/
if (remote_opt)
ev->register_temp_buf((char*) net->read_pos + 1);
Log_event_type type= ev->get_type_code(); Log_event_type type= ev->get_type_code();
if (glob_description_event->binlog_version >= 3 || if (glob_description_event->binlog_version >= 3 ||
......
...@@ -190,6 +190,75 @@ DELIMITER ; ...@@ -190,6 +190,75 @@ DELIMITER ;
ROLLBACK /* added by mysqlbinlog */; ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
--- Test 4 Second Remote test --
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
stop slave;
reset master;
reset slave;
start slave;
SELECT COUNT(*) from t1;
COUNT(*)
352
SELECT COUNT(*) from t2;
COUNT(*)
500
SELECT COUNT(*) from t3;
COUNT(*)
500
SELECT * FROM t1 ORDER BY word LIMIT 5;
word
Aarhus
Aarhus
Aarhus
Aarhus
Aarhus
SELECT * FROM t2 ORDER BY id LIMIT 5;
id
1
2
3
4
5
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
c1 c3 c4 c5
1 2006-02-22 00:00:00 Tested in Texas 2.2
2 2006-02-22 00:00:00 Tested in Texas 4.4
3 2006-02-22 00:00:00 Tested in Texas 6.6
4 2006-02-22 00:00:00 Tested in Texas 8.8
5 2006-02-22 00:00:00 Tested in Texas 11
SELECT COUNT(*) from t1;
COUNT(*)
352
SELECT COUNT(*) from t2;
COUNT(*)
500
SELECT COUNT(*) from t3;
COUNT(*)
500
SELECT * FROM t1 ORDER BY word LIMIT 5;
word
Aarhus
Aarhus
Aarhus
Aarhus
Aarhus
SELECT * FROM t2 ORDER BY id LIMIT 5;
id
1
2
3
4
5
SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
c1 c3 c4 c5
1 2006-02-22 00:00:00 Tested in Texas 2.2
2 2006-02-22 00:00:00 Tested in Texas 4.4
3 2006-02-22 00:00:00 Tested in Texas 6.6
4 2006-02-22 00:00:00 Tested in Texas 8.8
5 2006-02-22 00:00:00 Tested in Texas 11
--- Test 5 LOAD DATA -- --- Test 5 LOAD DATA --
/*!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*/;
...@@ -273,4 +342,11 @@ HEX(f) ...@@ -273,4 +342,11 @@ HEX(f)
835C 835C
--- Test cleanup -- --- Test cleanup --
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT NOT NULL KEY, b INT);
INSERT INTO t1 VALUES(1,1);
SELECT * FROM t1;
a b
1 1
FLUSH LOGS;
DROP TABLE IF EXISTS t1, t2, t3, t04, t05, t4, t5; DROP TABLE IF EXISTS t1, t2, t3, t04, t05, t4, t5;
...@@ -181,67 +181,67 @@ select "--- Test 3 First Remote test --" as ""; ...@@ -181,67 +181,67 @@ select "--- Test 3 First Remote test --" as "";
--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
# This part is disabled due to bug #17654 # This part is disabled due to bug #17654
################### Start Bug 17654 ######################
#--disable_query_log
#select "--- Test 4 Second Remote test --" as "";
#--enable_query_log
#--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql
#--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 >> $MYSQLTEST_VARDIR/tmp/remote.sql --disable_query_log
select "--- Test 4 Second Remote test --" as "";
--enable_query_log
--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql
--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 >> $MYSQLTEST_VARDIR/tmp/remote.sql
# Now that we have our file, lets get rid of the current database. # Now that we have our file, lets get rid of the current database.
# Cleanup the master and the slave and try to recreate. # Cleanup the master and the slave and try to recreate.
#DROP TABLE t1; DROP TABLE t1;
#DROP TABLE t2; DROP TABLE t2;
#DROP TABLE t3; DROP TABLE t3;
#sync_slave_with_master; sync_slave_with_master;
#we expect STOP SLAVE to produce a warning as the slave is stopped #we expect STOP SLAVE to produce a warning as the slave is stopped
#(the server was started with skip-slave-start) #(the server was started with skip-slave-start)
#--disable_warnings --disable_warnings
#stop slave; stop slave;
#--enable_warnings --enable_warnings
#--require r/slave-stopped.result --require r/slave-stopped.result
#show status like 'Slave_running'; show status like 'Slave_running';
#connection master; connection master;
#reset master; reset master;
#connection slave; connection slave;
#reset slave; reset slave;
#start slave; start slave;
#--require r/slave-running.result --require r/slave-running.result
#show status like 'Slave_running'; show status like 'Slave_running';
#connection master; connection master;
# We should be clean at this point, now we will run in the file from above. # We should be clean at this point, now we will run in the file from above.
#--exec $MYSQL -e "source $MYSQLTEST_VARDIR/tmp/remote.sql" --exec $MYSQL -e "source $MYSQLTEST_VARDIR/tmp/remote.sql"
# Lets Check the tables on the Master # Lets Check the tables on the Master
#SELECT COUNT(*) from t1; SELECT COUNT(*) from t1;
#SELECT COUNT(*) from t2; SELECT COUNT(*) from t2;
#SELECT COUNT(*) from t3; SELECT COUNT(*) from t3;
#SELECT * FROM t1 ORDER BY word LIMIT 5; SELECT * FROM t1 ORDER BY word LIMIT 5;
#SELECT * FROM t2 ORDER BY id LIMIT 5; SELECT * FROM t2 ORDER BY id LIMIT 5;
#SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
# Should have the same on the slave; # Should have the same on the slave;
#sync_slave_with_master; sync_slave_with_master;
#SELECT COUNT(*) from t1; SELECT COUNT(*) from t1;
#SELECT COUNT(*) from t2; SELECT COUNT(*) from t2;
#SELECT COUNT(*) from t3; SELECT COUNT(*) from t3;
#SELECT * FROM t1 ORDER BY word LIMIT 5; SELECT * FROM t1 ORDER BY word LIMIT 5;
#SELECT * FROM t2 ORDER BY id LIMIT 5; SELECT * FROM t2 ORDER BY id LIMIT 5;
#SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5; SELECT c1, c3, c4, c5 FROM t3 ORDER BY c1 LIMIT 5;
#connection master; connection master;
# We should be gold by the time, so I will get rid of our file. # We should be gold by the time, so I will get rid of our file.
#--exec rm $MYSQLTEST_VARDIR/tmp/remote.sql --exec rm $MYSQLTEST_VARDIR/tmp/remote.sql
################### End Bug 17654 ###################### ################### End Bug 17654 ######################
# LOAD DATA # LOAD DATA
...@@ -313,7 +313,34 @@ select "--- Test cleanup --" as ""; ...@@ -313,7 +313,34 @@ select "--- Test cleanup --" as "";
--enable_query_log --enable_query_log
# clean up # clean up
connection master; connection master;
DROP TABLE IF EXISTS t1, t2, t3, t04, t05, t4, t5;
sync_slave_with_master; sync_slave_with_master;
connection master;
# BUG#17654 also test mysqlbinlog to ensure it can read the binlog from a remote server
# and ensure that the results are the same as if read from a file (the same file).
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (a INT NOT NULL KEY, b INT);
INSERT INTO t1 VALUES(1,1);
SELECT * FROM t1;
FLUSH LOGS;
--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql
--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/local.sql
--diff_files $MYSQLTEST_VARDIR/tmp/local.sql $MYSQLTEST_VARDIR/tmp/remote.sql
--exec rm $MYSQLTEST_VARDIR/tmp/remote.sql
--exec rm $MYSQLTEST_VARDIR/tmp/local.sql
DROP TABLE IF EXISTS t1, t2, t3, t04, t05, t4, t5;
# End of 4.1 tests # End of 4.1 tests
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