Below is the list of changes that have just been committed into a local
5.0 repository of elkin. When elkin does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-04-03 10:11:38+03:00, aelkin@stripped
+3 -0
Bug#22725 Replication outages from ER_SERVER_SHUTDOWN (1053) set in replication events
The reason for the bug was that replaying of a query on slave could not be possible
since its event
was recorded with the killed error. Due to the specific of handling INSERT, which
per-row-while-loop is
unbreakable to killing, the query on ta-table should have not appeared in binlog unless
there was
a call to a stored routine that got interrupted with killing.
The offered solution introduced the following rules for binlogging of INSERT that
accounts its specifics.
For ta-table the query rolls back if got killed and `error' was set to non-zero.
The only raised flag without the error was set is harmless even though insert invoked a
stored routine.
For not-ta-table the combination forces to binlog the query with KILLED error to
indicate that there
was potentially partial execution on master and consistency is under the question.
The fix relies on the specified behaviour of stored routine that must propagate the
error to the top level
query handling if the thd->killed flag was caught raised in the routine execution.
mysql-test/r/kill.result@stripped, 2007-04-03 10:11:36+03:00,
aelkin@stripped +125 -0
changed, and will be changed after bug#27563,#27565 fixed
mysql-test/t/kill.test@stripped, 2007-04-03 10:11:36+03:00,
aelkin@stripped +186 -0
regression tests for the bugs #22725, #27563, #27565
sql/sql_insert.cc@stripped, 2007-04-03 10:11:36+03:00,
aelkin@stripped +56 -25
rollback killed query if ta-table and `error' was set too;
mask-out the flag while the query event is created if no `error';
thd->killed is restored w/o loss of possible changing during event's create.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: aelkin
# Host: dsl-hkibras1-ff1dc300-249.dhcp.inet.fi
# Root: /home/elkin/MySQL/MAIN/mysql-5.0-marvel
--- 1.225/sql/sql_insert.cc 2007-03-19 23:39:47 +02:00
+++ 1.226/sql/sql_insert.cc 2007-04-03 10:11:36 +03:00
@@ -604,24 +604,24 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
table->triggers,
TRG_EVENT_INSERT))
{
- if (values_list.elements != 1 && !thd->net.report_error)
- {
- info.records++;
- continue;
- }
- /*
- TODO: set thd->abort_on_warning if values_list.elements == 1
- and check that all items return warning in case of problem with
- storing field.
+ if (values_list.elements != 1 && !thd->net.report_error)
+ {
+ info.records++;
+ continue;
+ }
+ /*
+ TODO: set thd->abort_on_warning if values_list.elements == 1
+ and check that all items return warning in case of problem with
+ storing field.
*/
- error=1;
- break;
+ error=1;
+ break;
}
}
else
{
if (thd->used_tables) // Column used in values()
- restore_record(table,s->default_values); // Get empty record
+ restore_record(table,s->default_values); // Get empty record
else
{
/*
@@ -629,22 +629,22 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
be overwritten by fill_record() anyway (and fill_record() does not
use default values in this case).
*/
- table->record[0][0]= table->s->default_values[0];
+ table->record[0][0]= table->s->default_values[0];
}
if (fill_record_n_invoke_before_triggers(thd, table->field, *values, 0,
table->triggers,
TRG_EVENT_INSERT))
{
- if (values_list.elements != 1 && ! thd->net.report_error)
- {
- info.records++;
- continue;
- }
- error=1;
- break;
+ if (bvalues_list.elements != 1 && ! thd->net.report_error)
+ {
+ info.records++;
+ continue;
+ }
+ error=1;
+ break;
}
}
-
+
if ((res= table_list->view_check_option(thd,
(values_list.elements == 1 ?
0 :
@@ -725,10 +725,41 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
{
if (error <= 0)
thd->clear_error();
- Query_log_event qinfo(thd, thd->query, thd->query_length,
- transactional_table, FALSE);
- if (mysql_bin_log.write(&qinfo) && transactional_table)
- error=1;
+ if (transactional_table && (thd->killed != THD::NOT_KILLED
&& error))
+ {
+ error= 1; // rollback if KILLED && error
+ }
+ else
+ {
+ /* bug#22725:
+
+ A query which per-row-loop can not be interrupted with KILLED,
+ like INSERT, and that does not invoke stored routines
+ can be binlogged with neglecting the KILLED error.
+
+ If there was no error (error == zero) until after the
+ end of inserting loop the KILLED flag that appeared
+ later can be disregarded since previously possible
+ invocation of stored routines did not result in any
+ error due to the KILLED. In such case the flag is
+ masked out for time of constructing binlog event.
+
+ todo: to avoid asyncronization of `error' and
+ `error_code' of binlog event constructor change the
+ constructor to accept `error_code' as an argument that
+ would be evaluated with consulting thd->killed
+ Applies to most mysql_$query functions.
+ */
+ THD::killed_state old_killed= thd->killed;
+ if (thd->killed != THD::NOT_KILLED && !error)
+ thd->killed= THD::NOT_KILLED; // mask-out since there was no error
+ Query_log_event qinfo(thd, thd->query, thd->query_length,
+ transactional_table, FALSE);
+ if (thd->killed == THD::NOT_KILLED)
+ thd->killed= old_killed; // unmasking accounts flag might change
+ if (mysql_bin_log.write(&qinfo) && transactional_table)
+ error=1;
+ }
}
if (!transactional_table)
thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
--- 1.16/mysql-test/r/kill.result 2006-10-04 14:09:34 +03:00
+++ 1.17/mysql-test/r/kill.result 2007-04-03 10:11:36 +03:00
@@ -41,3 +41,128 @@ select 1;
select RELEASE_LOCK("a");
RELEASE_LOCK("a")
1
+create function bug27563()
+RETURNS int(11)
+DETERMINISTIC
+begin
+select get_lock("a", 10) into @a;
+return 1;
+end|
+create function bug27565()
+RETURNS int(11)
+DETERMINISTIC
+begin
+select a from t1 where a=1 into @a for update;
+return 1;
+end|
+create table t1 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
+affected rows: 0
+create table t2 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=MyISAM;
+affected rows: 0
+create table t3 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
+affected rows: 0
+reset master;
+select get_lock("a", 20);
+get_lock("a", 20)
+1
+insert into t1 values (bug27563(),1);
+kill query 3;
+show binlog events from 98 /* nothing in binlog unless Bug#27563 */;
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 98 Intvar 1 28 INSERT_ID=1
+master-bin.000001 126 Query 1 135 use `test`; insert into t1 values (bug27563(),1)
+master-bin.000001 233 Xid 1 260 COMMIT /* xid=4132 */
+select count(*) from t1 /* must be zero unless Bug#27563 */;
+count(*)
+1
+begin;
+insert into t1 values (bug27563(),1);
+kill query 3;
+select count(*) from t1 /* must be zero unless Bug#27563 */;
+count(*)
+2
+commit;
+insert into t2 values (bug27563(),1);
+kill query 3;
+select count(*) from t2 /* must be one */;
+count(*)
+1
+show binlog events from 98 /* must have the insert on non-ta table */;
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 98 Intvar 1 28 INSERT_ID=1
+master-bin.000001 126 Query 1 135 use `test`; insert into t1 values (bug27563(),1)
+master-bin.000001 233 Xid 1 260 COMMIT /* xid=4132 */
+master-bin.000001 260 Query 1 328 use `test`; BEGIN
+master-bin.000001 328 Intvar 1 28 INSERT_ID=2
+master-bin.000001 356 Query 1 127 use `test`; insert into t1 values (bug27563(),1)
+master-bin.000001 455 Xid 1 482 COMMIT /* xid=4139 */
+master-bin.000001 482 Intvar 1 510 INSERT_ID=1
+master-bin.000001 510 Query 1 609 use `test`; insert into t2 values (bug27563(),1)
+select RELEASE_LOCK("a");
+RELEASE_LOCK("a")
+1
+delete from t1;
+delete from t2;
+insert into t1 values (1,1);
+insert into t2 values (1,1);
+begin;
+update t1 set b=0 where a=1;
+update t2 set b=bug27565()-1 where a=1;
+kill query 3;
+commit;
+Got one of the listed errors
+select * from t1 /* must be: (1,0) */;
+a b
+1 0
+select * from t2 /* must be as before: (1,1) */;
+a b
+1 1
+reset master;
+begin;
+update t1 set b=0 where a=1;
+delete from t3;
+insert into t3 values (0,0),(1,bug27565());
+kill query 3;
+commit;
+Got one of the listed errors
+select count(*) from t3 /* must be zero */;
+count(*)
+0
+show binlog events from 98 /* only killer ta in binlog */;
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 98 Query 1 77 use `test`; delete from t3
+master-bin.000001 175 Xid 1 202 COMMIT /* xid=4167 */
+master-bin.000001 202 Query 1 270 use `test`; BEGIN
+master-bin.000001 270 Query 1 90 use `test`; update t1 set b=0 where a=1
+master-bin.000001 360 Xid 1 387 COMMIT /* xid=4166 */
+reset master;
+begin;
+update t1 set b=0 where a=1;
+delete from t2;
+insert into t2 values (0,0),(1,bug27565());
+kill query 3;
+commit;
+Got one of the listed errors
+select count(*) from t2 /* count must be one */;
+count(*)
+1
+show binlog events from 98 /* insert into non-ta must be in binlog */;
+Log_name Pos Event_type Server_id End_log_pos Info
+master-bin.000001 98 Query 1 175 use `test`; delete from t2
+master-bin.000001 175 Query 1 243 use `test`; BEGIN
+master-bin.000001 243 Query 1 90 use `test`; update t1 set b=0 where a=1
+master-bin.000001 333 Xid 1 360 COMMIT /* xid=4177 */
+master-bin.000001 360 Intvar 1 388 INSERT_ID=2
+master-bin.000001 388 Query 1 493 use `test`; insert into t2 values (0,0),(1,bug27565())
+select
+(@a:=load_file("MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
+is not null;
+(@a:=load_file("MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
+is not null
+1
+select @a like "%#%error_code=1317%" /* must return 1 */;
+@a like "%#%error_code=1317%"
+1
+drop table t1,t2,t3;
+drop function bug27563;
+drop function bug27565;
--- 1.24/mysql-test/t/kill.test 2006-12-08 18:09:39 +02:00
+++ 1.25/mysql-test/t/kill.test 2007-04-03 10:11:36 +03:00
@@ -117,3 +117,189 @@ reap;
select 1;
connection con1;
select RELEASE_LOCK("a");
+
+###
+### bug#22725 : incorrect killed error in binlogged query
+### and
+### Bug#27563 killing noticed in SF() stack but the error gets missed in action
+### Bug#27565 killed query of SF() is not reported correctly and
+###
+
+# the function is insensitive to killing - bug#27563
+delimiter |;
+create function bug27563()
+RETURNS int(11)
+DETERMINISTIC
+begin
+ select get_lock("a", 10) into @a;
+ return 1;
+end|
+delimiter ;|
+
+# the function sensitive to killing though with wrong client error bug#27565
+delimiter |;
+create function bug27565()
+RETURNS int(11)
+DETERMINISTIC
+begin
+ select a from t1 where a=1 into @a for update;
+ return 1;
+end|
+delimiter ;|
+
+--enable_info
+create table t1 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
+create table t2 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=MyISAM;
+create table t3 (a int auto_increment, b int, PRIMARY KEY (a)) ENGINE=InnoDB;
+--disable_info
+reset master;
+
+### ta table case: killing causes rollback
+
+# A. autocommit ON
+connection con1;
+select get_lock("a", 20);
+
+connection con2;
+let $ID= `select connection_id()`;
+send insert into t1 values (bug27563(),1);
+
+connection con1;
+eval kill query $ID;
+
+connection con2;
+# todo: remove 0 return after fixing Bug#27563
+--error 0,ER_QUERY_INTERRUPTED
+reap;
+show binlog events from 98 /* nothing in binlog unless Bug#27563 */;
+select count(*) from t1 /* must be zero unless Bug#27563 */;
+
+# M. multi-statement-ta
+connection con2;
+let $ID= `select connection_id()`;
+begin;
+send insert into t1 values (bug27563(),1);
+
+connection con1;
+eval kill query $ID;
+
+connection con2;
+# todo: remove 0 return after fixing Bug#27563
+--error 0,ER_QUERY_INTERRUPTED
+reap;
+select count(*) from t1 /* must be zero unless Bug#27563 */;
+commit;
+
+
+### non-ta table case: killing must be recorded in binlog
+
+connection con2;
+let $ID= `select connection_id()`;
+send insert into t2 values (bug27563(),1);
+
+connection con1;
+eval kill query $ID;
+
+connection con2;
+# todo: remove 0 return after fixing Bug#27563
+--error 0,ER_QUERY_INTERRUPTED
+reap;
+select count(*) from t2 /* must be one */;
+show binlog events from 98 /* must have the insert on non-ta table */;
+# the value of the error flag of KILLED_QUERY is tested further
+
+connection con1;
+select RELEASE_LOCK("a");
+
+### test with effective killing of SF()
+
+delete from t1;
+delete from t2;
+insert into t1 values (1,1);
+insert into t2 values (1,1);
+
+#
+# Bug#27565
+# test where KILL is propagated as error to the top level
+# still another bug with the error message to the user
+# todo: fix reexecute the result file after fixing
+#
+begin; update t1 set b=0 where a=1;
+
+connection con2;
+let $ID= `select connection_id()`;
+send update t2 set b=bug27565()-1 where a=1;
+
+connection con1;
+eval kill query $ID;
+commit;
+
+connection con2;
+# todo: fix Bug #27565 killed query of SF() is not reported correctly and
+# remove 1105 (wrong)
+#--error ER_QUERY_INTERRUPTED
+--error 1105,ER_QUERY_INTERRUPTED
+reap;
+select * from t1 /* must be: (1,0) */;
+select * from t2 /* must be as before: (1,1) */;
+
+## bug#22725 with effective and propagating killing
+#
+# top-level ta-table
+connection con1;
+reset master;
+begin; update t1 set b=0 where a=1;
+
+connection con2;
+delete from t3;
+let $ID= `select connection_id()`;
+# the query won't perform completely since the function gets intrurrupted
+send insert into t3 values (0,0),(1,bug27565());
+
+connection con1;
+eval kill query $ID;
+commit;
+
+connection con2;
+# todo: fix Bug #27565 killed query of SF() is not reported correctly and
+# remove 1105 (wrong)
+#--error ER_QUERY_INTERRUPTED
+--error 1105,ER_QUERY_INTERRUPTED
+reap;
+select count(*) from t3 /* must be zero */;
+show binlog events from 98 /* only killer ta in binlog */;
+
+# top-level non-ta-table
+connection con1;
+reset master;
+begin; update t1 set b=0 where a=1;
+
+connection con2;
+delete from t2;
+let $ID= `select connection_id()`;
+# the query won't perform completely since the function gets intrurrupted
+send insert into t2 values (0,0),(1,bug27565());
+
+connection con1;
+eval kill query $ID;
+commit;
+
+connection con2;
+# todo: fix Bug #27565 killed query of SF() is not reported correctly and
+# remove 1105 (wrong)
+#--error ER_QUERY_INTERRUPTED
+--error 1105,ER_QUERY_INTERRUPTED
+reap;
+select count(*) from t2 /* count must be one */;
+show binlog events from 98 /* insert into non-ta must be in binlog */;
+--exec $MYSQL_BINLOG --start-position=388 $MYSQLTEST_VARDIR/log/master-bin.000001 >
$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+eval select
+(@a:=load_file("$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
+is not null;
+--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
+eval select @a like "%#%error_code=1317%" /* must return 1 */;
+
+drop table t1,t2,t3;
+drop function bug27563;
+drop function bug27565;
| Thread |
|---|
| • bk commit into 5.0 tree (aelkin:1.2490) BUG#22725 | Andrei Elkin | 3 Apr |