diff options
author | unknown <aelkin/elkin@koti.dsl.inet.fi> | 2007-10-29 15:20:59 +0200 |
---|---|---|
committer | unknown <aelkin/elkin@koti.dsl.inet.fi> | 2007-10-29 15:20:59 +0200 |
commit | 95f3db7be1b3425b47f34090f33c7eeb52f97703 (patch) | |
tree | 7ee3c865779ddc72072daa205d4b5d3c3c0280fa /sql/sql_update.cc | |
parent | c8b6d1050933f0b9b18367c421702c9f16907de5 (diff) | |
download | mariadb-git-95f3db7be1b3425b47f34090f33c7eeb52f97703.tar.gz |
Bug #27571 asynchronousity in setting mysql_`query`::error and
Query_log_event::error_code
A query can perform completely having the local var error of mysql_$query
zero, where $query in insert, update, delete, load,
and be binlogged with error_code e.g KILLED_QUERY while there is no
reason do to so.
That can happen because Query_log_event consults thd->killed flag to
evaluate error_code.
Fixed with implementing a scheme suggested and partly implemented at
time of bug@22725 work-on. error_status is cached immediatly after the
control leaves the main rows-loop and that instance always corresponds
to `error' the local of mysql_$query functions. The cached value
is passed to Query_log_event constructor, not the default thd->killed
which can be changed in between of the caching and the constructing.
mysql-test/r/binlog_killed.result:
results changed
mysql-test/t/binlog_killed.test:
Demonstrating that effective killing during rows-loop execution leads to the speficied actions:
binlogging with the error for a query modified a not-transactional table or
rolling back effects for transactional table;
fixing possible non-determinism with ID when query_log_enabled;
leave commented out tests for multi-update,delete due to another bug;
removing an obsolete tests template;
changing system rm to --remove_file.
sql/log_event.cc:
adding killed status arg
sql/log_event.h:
added killed status arg
sql/sql_delete.cc:
deploying the update part patch for delete, multi-delete
sql/sql_insert.cc:
deploying the update-part patch for insert..select
sql/sql_load.cc:
deploying the update-part patch for load data.
simulation added.
sql/sql_update.cc:
Impementing the fix as described in the comments left by bug@22725.
Also simulation of killing after the loop that would affect binlogging in the old code.
mysql-test/t/binlog_killed_bug27571-master.opt:
post rows-loop killing simulation's options
mysql-test/t/binlog_killed_bug27571.test:
Checking that if killing happens inbetween of the end of rows loop and
recording into binlog that will not lead to recording any error incl
the killed error.
mysql-test/t/binlog_killed_simulate-master.opt:
simulation options
mysql-test/t/binlog_killed_simulate.test:
tests for
a query (update is choosen) being killed after the row-loop;
load data killed within the loop - effective killed error in the event is gained.
Diffstat (limited to 'sql/sql_update.cc')
-rw-r--r-- | sql/sql_update.cc | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc index f3695976508..14c34b6e0f1 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -134,6 +134,7 @@ int mysql_update(THD *thd, SELECT_LEX *select_lex= &thd->lex->select_lex; bool need_reopen; List<Item> all_fields; + THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_update"); LINT_INIT(timestamp_query_id); @@ -519,43 +520,26 @@ int mysql_update(THD *thd, table->file->unlock_row(); thd->row_count++; } + /* + Caching the killed status to pass as the arg to query event constuctor; + The cached value can not change whereas the killed status can + (externally) since this point and change of the latter won't affect + binlogging. + It's assumed that if an error was set in combination with an effective + killed status then the error is due to killing. + */ + killed_status= thd->killed; // get the status of the volatile + // simulated killing after the loop must be ineffective for binlogging + DBUG_EXECUTE_IF("simulate_kill_bug27571", + { + thd->killed= THD::KILL_QUERY; + };); + error= (killed_status == THD::NOT_KILLED)? error : 1; + if (!transactional_table && updated > 0) thd->transaction.stmt.modified_non_trans_table= TRUE; - - /* - todo bug#27571: to avoid asynchronization of `error' and - `error_code' of binlog event constructor - - The concept, which is a bit different for insert(!), is to - replace `error' assignment with the following lines - - killed_status= thd->killed; // get the status of the volatile - - Notice: thd->killed is type of "state" whereas the lhs has - "status" the suffix which translates according to WordNet: a state - at a particular time - at the time of the end of per-row loop in - our case. Binlogging ops are conducted with the status. - - error= (killed_status == THD::NOT_KILLED)? error : 1; - - which applies to most mysql_$query functions. - Event's constructor will accept `killed_status' as an argument: - - Query_log_event qinfo(..., killed_status); - - thd->killed might be changed after killed_status had got cached and this - won't affect binlogging event but other effects remain. - - Open issue: In a case the error happened not because of KILLED - - and then KILLED was caught later still within the loop - we shall - do something to avoid binlogging of incorrect ER_SERVER_SHUTDOWN - error_code. - */ - - if (thd->killed && !error) - error= 1; // Aborted end_read_record(&info); free_io_cache(table); // If ORDER BY delete select; @@ -587,7 +571,7 @@ int mysql_update(THD *thd, if (error < 0) thd->clear_error(); Query_log_event qinfo(thd, thd->query, thd->query_length, - transactional_table, FALSE); + transactional_table, FALSE, killed_status); if (mysql_bin_log.write(&qinfo) && transactional_table) error=1; // Rollback update } @@ -1522,6 +1506,11 @@ void multi_update::send_error(uint errcode,const char *err) */ if (mysql_bin_log.is_open()) { + /* + THD::killed status might not have been set ON at time of an error + got caught and if happens later the killed error is written + into repl event. + */ Query_log_event qinfo(thd, thd->query, thd->query_length, transactional_tables, FALSE); mysql_bin_log.write(&qinfo); @@ -1709,10 +1698,19 @@ err2: bool multi_update::send_eof() { char buff[STRING_BUFFER_USUAL_SIZE]; + THD::killed_state killed_status= THD::NOT_KILLED; thd->proc_info="updating reference tables"; - /* Does updates for the last n - 1 tables, returns 0 if ok */ + /* + Does updates for the last n - 1 tables, returns 0 if ok; + error takes into account killed status gained in do_updates() + */ int local_error = (table_count) ? do_updates(0) : 0; + /* + if local_error is not set ON until after do_updates() then + later carried out killing should not affect binlogging. + */ + killed_status= (local_error == 0)? THD::NOT_KILLED : thd->killed; thd->proc_info= "end"; /* We must invalidate the query cache before binlog writing and @@ -1740,7 +1738,7 @@ bool multi_update::send_eof() if (local_error == 0) thd->clear_error(); Query_log_event qinfo(thd, thd->query, thd->query_length, - transactional_tables, FALSE); + transactional_tables, FALSE, killed_status); if (mysql_bin_log.write(&qinfo) && trans_safe) local_error= 1; // Rollback update } |