Skip to content

Commit

Permalink
MDEV-23872 Crash in galera::TrxHandle::state()
Browse files Browse the repository at this point in the history
Prepared statements which were run over binary protocol crashed
a server if the statement did not have CF_PS_ARRAY_BINDING_OPTIMIZED
flag and the statement was executed in bulk mode and a BF abort occrurred.
This was because the bulk execution resulted in several statements without
calling wsrep_after_statement() between, which confused wsrep transaction
state tracking.

As a fix, call wsrep_after_statement() in bulk loop after each execution
if CF_PS_ARRAY_BINDING_OPTIMIZED is not set.

Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
  • Loading branch information
temeo authored and Jan Lindström committed Nov 3, 2020
1 parent 9e14a2d commit 4489b66
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sql/sql_prepare.cc
Expand Up @@ -122,7 +122,10 @@ When one supplies long data for a placeholder:
#include "lock.h" // MYSQL_OPEN_FORCE_SHARED_MDL
#include "sql_handler.h"
#include "transaction.h" // trans_rollback_implicit
#ifdef WITH_WSREP
#include "wsrep_mysqld.h"
#include "wsrep_trans_observer.h"
#endif /* WITH_WSREP */

/**
A result class used to send cursor rows using the binary protocol.
Expand Down Expand Up @@ -4414,6 +4417,23 @@ Prepared_statement::execute_bulk_loop(String *expanded_query,

thd->m_reprepare_observer= NULL;

#ifdef WITH_WSREP
if (!(sql_command_flags[lex->sql_command] & CF_PS_ARRAY_BINDING_OPTIMIZED) &&
WSREP(thd))
{
if (wsrep_after_statement(thd))
{
/*
Re-execution success is unlikely after an error from
wsrep_after_statement(), so retrun error immediately.
*/
thd->get_stmt_da()->reset_diagnostics_area();
wsrep_override_error(thd, thd->wsrep_cs().current_error(),
thd->wsrep_cs().current_error_status());
}
}
else
#endif /* WITH_WSREP */
if (unlikely(error) &&
(sql_command_flags[lex->sql_command] & CF_REEXECUTION_FRAGILE) &&
!thd->is_fatal_error && !thd->killed &&
Expand Down

0 comments on commit 4489b66

Please sign in to comment.