Patch approved.
Sorry, but I changed my opinion. I think it is better to remove the test
case.
Cheers
Luis Soares wrote:
> #At file:///home/lsoares/Workspace/mysql-server/bugfix/41725/5.0-bt/ based on
> revid:satya.bn@stripped
>
> 2748 Luis Soares 2009-04-11
> BUG#41725: slave crashes when inserting into temporary table after
> stop/start slave
>
> When stopping and restarting the slave while it is replicating
> temporary tables, the server would crash or raise an assertion
> failure. This was due to the fact that although temporary tables are
> saved between slave threads restart, the reference to the thread in
> use (table->in_use) was not being properly updated when the restart
> happened (it would still reference the old/invalid thread instead of
> the new one).
>
> This patch addresses this issue by resetting the reference to the new
> slave thread on slave thread restart.
> @ mysql-test/r/rpl_temporary.result
> Result file.
> @ mysql-test/t/rpl_temporary.test
> Test case that checks that both failures go away.
> @ sql/slave.cc
> Changed slave.cc to reset sql_thd reference in temporary tables.
>
> modified:
> mysql-test/r/rpl_temporary.result
> mysql-test/t/rpl_temporary.test
> sql/slave.cc
> === modified file 'mysql-test/r/rpl_temporary.result'
> --- a/mysql-test/r/rpl_temporary.result 2009-03-25 16:10:27 +0000
> +++ b/mysql-test/r/rpl_temporary.result 2009-04-11 16:11:39 +0000
> @@ -133,3 +133,22 @@ select * from t1;
> a
> 1
> drop table t1;
> +DROP TABLE IF EXISTS t1;
> +CREATE TEMPORARY TABLE t1 (a char(1));
> +INSERT INTO t1 VALUES ('a');
> +include/stop_slave.inc
> +include/start_slave.inc
> +INSERT INTO t1 VALUES ('b');
> +DROP TABLE IF EXISTS t1;
> +CREATE TEMPORARY TABLE `t1`(`a` tinyint,`b` char(1))engine=myisam;
> +INSERT INTO `t1` set `a`=128,`b`='128';
> +Warnings:
> +Warning 1264 Out of range value adjusted for column 'a' at row 1
> +Warning 1265 Data truncated for column 'b' at row 1
> +include/stop_slave.inc
> +include/start_slave.inc
> +INSERT INTO `t1` set `a`=128,`b`='128';
> +Warnings:
> +Warning 1264 Out of range value adjusted for column 'a' at row 1
> +Warning 1265 Data truncated for column 'b' at row 1
> +DROP TABLE t1;
>
> === modified file 'mysql-test/t/rpl_temporary.test'
> --- a/mysql-test/t/rpl_temporary.test 2009-03-25 16:10:27 +0000
> +++ b/mysql-test/t/rpl_temporary.test 2009-04-11 16:11:39 +0000
> @@ -217,4 +217,74 @@ drop table t1;
> # Delete the anonymous users
> source include/delete_anonymous_users.inc;
>
> +# ##################################################################
> +# BUG#41725: slave crashes when inserting into temporary table after
> +# stop/start slave
> +#
> +# This test checks that both reported issues (assertion failure and
> +# crash) go away. It is implemented as follows:
> +#
> +# case 1: assertion failure
> +# i) create and insert into temporary table on master
> +# ii) sync slave with master
> +# iii) stop and restart slave
> +# iv) insert into master another value
> +# v) sync slave with master
> +#
> +#
> +# case 2: crash (SIGSEV)
> +# i) create and insert into temporary table on master (insert
> +# produces warnings)
> +# ii) sync slave with master
> +# iii) stop and restart slave
> +# iv) insert into master more values
> +# v) sync slave with master
> +
> +# case 1: Assertion in Field_string::store() failed because current
> +# thread reference differed from table->in_use after slave
> +# restart
> +
> +connection master;
> +
> +disable_warnings;
> +DROP TABLE IF EXISTS t1;
> +enable_warnings;
> +
> +CREATE TEMPORARY TABLE t1 (a char(1));
> +INSERT INTO t1 VALUES ('a');
> +sync_slave_with_master;
> +
> +source include/stop_slave.inc;
> +source include/start_slave.inc;
> +
> +connection master;
> +INSERT INTO t1 VALUES ('b');
> +sync_slave_with_master;
> +
> +# case 2: crash on sp_rcontext::find_handler because it used
> +# reference to invalid THD object after slave restart
> +
> +connection master;
> +
> +disable_warnings;
> +DROP TABLE IF EXISTS t1;
> +enable_warnings;
> +CREATE TEMPORARY TABLE `t1`(`a` tinyint,`b` char(1))engine=myisam;
> +INSERT INTO `t1` set `a`=128,`b`='128';
> +
> +sync_slave_with_master;
> +
> +source include/stop_slave.inc;
> +source include/start_slave.inc;
> +
> +connection master;
> +INSERT INTO `t1` set `a`=128,`b`='128';
> +sync_slave_with_master;
> +
> +# cleanup
> +
> +connection master;
> +DROP TABLE t1;
> +sync_slave_with_master;
> +
> # End of 5.0 tests
>
> === modified file 'sql/slave.cc'
> --- a/sql/slave.cc 2009-02-10 22:47:54 +0000
> +++ b/sql/slave.cc 2009-04-11 16:11:39 +0000
> @@ -540,6 +540,14 @@ void st_relay_log_info::close_temporary_
> slave_open_temp_tables= 0;
> }
>
> +static void set_thd_in_use_temporary_tables(RELAY_LOG_INFO *rli)
> +{
> + TABLE *table;
> +
> + for (table= rli->save_temporary_tables ; table ; table= table->next)
> + table->in_use= rli->sql_thd;
> +}
> +
> /*
> purge_relay_logs()
>
> @@ -3913,6 +3921,7 @@ slave_begin:
> }
> thd->init_for_queries();
> thd->temporary_tables = rli->save_temporary_tables; // restore temp tables
> + set_thd_in_use_temporary_tables(rli); // (re)set sql_thd in use for saved temp
> tables
> pthread_mutex_lock(&LOCK_thread_count);
> threads.append(thd);
> pthread_mutex_unlock(&LOCK_thread_count);
> @@ -4085,6 +4094,7 @@ the slave SQL thread with \"SLAVE START\
> DBUG_ASSERT(rli->sql_thd == thd);
> THD_CHECK_SENTRY(thd);
> rli->sql_thd= 0;
> + set_thd_in_use_temporary_tables(rli); // (re)set sql_thd in use for saved temp
> tables
> pthread_mutex_lock(&LOCK_thread_count);
> THD_CHECK_SENTRY(thd);
> delete thd;
>
>
> ------------------------------------------------------------------------
>
>
>