diff options
author | seppo <seppo.jaakola@iki.fi> | 2019-10-01 10:41:33 +0300 |
---|---|---|
committer | Jan Lindström <jan.lindstrom@mariadb.com> | 2019-10-01 10:41:33 +0300 |
commit | c42c4233cbc03656ac42e87481743c0a77d0a279 (patch) | |
tree | f8671f655d4568eb8ff7f5b054fc1e6276e7fb77 /sql/sp_head.cc | |
parent | dc588e3d3fc0d3610ffb6f4e9c804dc539394669 (diff) | |
download | mariadb-git-c42c4233cbc03656ac42e87481743c0a77d0a279.tar.gz |
MDEV-20225 BF aborting SP execution (#1394)
* MDEV-20225 BF aborting SP execution
When stored procedure execution was chosen as victim for a BF abort, the old implemnetationn called for rollback immediately
when execution was inside SP isntruction. Technically this happened in wsrep_after_statement() call, which identified the
need for a rollback.
The problem was that MariaDB does not accept rollback (nor commit) inside sub statement, there are several asserts about it,
checking for THD::in_sub_stmt.
This patch contains a fix, which skips calling wsrep_after_statement() for SP execution, which is marked as BF must abort. Instead,
we return error code to upper level, where rollback will eventually happen, ouside of SP execution.
Also, appending the affected trigger table (dropped or created) in the populated key set for the write set,
which prevents parallel applying of other transactions working on the same table.
* MDEV-20225 BF aborting SP execution, second patch
First PR missed 4 commits, which are now squashed in this patch:
- Added galera_sp_bf_abort test.
A MTR test case which will reproduce BF-BF conflict if all keys
corresponding to affected tables are not assigned for DROP TRIGGER.
- Fixed incorrect use of sync pointsin MDEV-20225
- Added condition for SQLCOM_DROP_TRIGGER in wsrep_can_run_in_toi()
to make it replicate.
* MDEV-20225 BF aborting SP execution, third patch
The galera_trigger.test caused a situation, where SP invocation caused a trigger
to fire, and the trigger executed as sub statement SP, and was BF aborted by applier.
because of wsrep_after_statement() was called for the sub-statement level, it ended up
in exeuting rollback and asserted there.
Thus fix will catch sub-statement level SP execution, and avoids calling wsrep_after_statement()
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r-- | sql/sp_head.cc | 106 |
1 files changed, 63 insertions, 43 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc index dfbfde64029..87664e16004 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1345,6 +1345,69 @@ sp_head::execute(THD *thd, bool merge_da_on_success) #endif /* WITH_WSREP */ err_status= i->execute(thd, &ip); +#ifdef WITH_WSREP + if (WSREP(thd)) + { + if (((thd->wsrep_trx().state() == wsrep::transaction::s_executing || thd->in_sub_stmt) && + (thd->is_fatal_error || thd->killed))) + { + WSREP_DEBUG("SP abort err status %d in sub %d trx state %d", + err_status, thd->in_sub_stmt, thd->wsrep_trx().state()); + err_status= 1; + thd->is_fatal_error= 1; + /* + SP was killed, and it is not due to a wsrep conflict. + We skip after_command hook at this point because + otherwise it clears the error, and cleans up the + whole transaction. For now we just return and finish + our handling once we are back to mysql_parse. + + Same applies to a SP execution, which was aborted due + to wsrep related conflict, but which is executing as sub statement. + SP in sub statement level should not commit not rollback, + we have to call for rollback is up-most SP level. + */ + WSREP_DEBUG("Skipping after_command hook for killed SP"); + } + else + { + const bool must_replay= wsrep_must_replay(thd); + if (must_replay) + { + WSREP_DEBUG("MUST_REPLAY set after SP, err_status %d trx state: %d", + err_status, thd->wsrep_trx().state()); + } + (void) wsrep_after_statement(thd); + + /* + Reset the return code to zero if the transaction was + replayed succesfully. + */ + if (must_replay && !wsrep_current_error(thd)) + { + err_status= 0; + thd->get_stmt_da()->reset_diagnostics_area(); + } + /* + Final wsrep error status for statement is known only after + wsrep_after_statement() call. If the error is set, override + error in thd diagnostics area and reset wsrep client_state error + so that the error does not get propagated via client-server protocol. + */ + if (wsrep_current_error(thd)) + { + wsrep_override_error(thd, wsrep_current_error(thd), + wsrep_current_error_status(thd)); + thd->wsrep_cs().reset_error(); + /* Reset also thd->killed if it has been set during BF abort. */ + if (thd->killed == KILL_QUERY) + thd->killed= NOT_KILLED; + /* if failed transaction was not replayed, must return with error from here */ + if (!must_replay) err_status = 1; + } + } + } +#endif /* WITH_WSREP */ thd->m_digest= parent_digest; if (i->free_list) @@ -3605,49 +3668,6 @@ sp_instr_stmt::exec_core(THD *thd, uint *nextp) (char *)thd->security_ctx->host_or_ip, 3); int res= mysql_execute_command(thd); -#ifdef WITH_WSREP - if (WSREP(thd)) - { - if ((thd->is_fatal_error || thd->killed_errno()) && - (thd->wsrep_trx().state() == wsrep::transaction::s_executing)) - { - /* - SP was killed, and it is not due to a wsrep conflict. - We skip after_statement hook at this point because - otherwise it clears the error, and cleans up the - whole transaction. For now we just return and finish - our handling once we are back to mysql_parse. - */ - WSREP_DEBUG("Skipping after_command hook for killed SP"); - } - else - { - const bool must_replay= wsrep_must_replay(thd); - (void) wsrep_after_statement(thd); - /* - Reset the return code to zero if the transaction was - replayed succesfully. - */ - if (res && must_replay && !wsrep_current_error(thd)) - res= 0; - /* - Final wsrep error status for statement is known only after - wsrep_after_statement() call. If the error is set, override - error in thd diagnostics area and reset wsrep client_state error - so that the error does not get propagated via client-server protocol. - */ - if (wsrep_current_error(thd)) - { - wsrep_override_error(thd, wsrep_current_error(thd), - wsrep_current_error_status(thd)); - thd->wsrep_cs().reset_error(); - /* Reset also thd->killed if it has been set during BF abort. */ - if (thd->killed == KILL_QUERY) - thd->reset_killed(); - } - } - } -#endif /* WITH_WSREP */ MYSQL_QUERY_EXEC_DONE(res); *nextp= m_ip+1; return res; |