diff options
author | unknown <evgen@moonbone.local> | 2007-07-30 17:14:34 +0400 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2007-07-30 17:14:34 +0400 |
commit | 9246c3720103caa421d5e0c5d7ad81bf570e071d (patch) | |
tree | dc7b91c527bfb6365e1346469426291cfcaae04e /sql/sp_rcontext.cc | |
parent | f7f593ae7dde682e449fe81d946a83f74f0deb6a (diff) | |
download | mariadb-git-9246c3720103caa421d5e0c5d7ad81bf570e071d.tar.gz |
Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
When innodb detects a deadlock it calls ha_rollback_trans() to rollback the
main transaction. But such action isn't allowed from inside of triggers and
functions. When it happen the 'Explicit or implicit commit' error is thrown
even if there is no commit/rollback statements in the trigger/function. This
leads to the user confusion.
Now the convert_error_code_to_mysql() function doesn't call the
ha_rollback_trans() function directly but rather calls the
mark_transaction_to_rollback function and returns an error.
The sp_rcontext::find_handler() now doesn't allow errors to be caught by the
trigger/function error handlers when the thd->is_fatal_sub_stmt_error flag
is set. Procedures are still allowed to catch such errors.
The sp_rcontext::find_handler function now accepts a THD handle as a parameter.
The transaction_rollback_request and the is_fatal_sub_stmt_error flags are
added to the THD class. The are initialized by the THD class constructor.
Now the ha_autocommit_or_rollback function rolls back main transaction
when not in a sub statement and the thd->transaction_rollback_request
is set.
The THD::restore_sub_statement_state function now resets the
thd->is_fatal_sub_stmt_error flag on exit from a sub-statement.
sql/ha_innodb.cc:
Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
Now the convert_error_code_to_mysql() function doesn't call the
ha_rollback_trans() function directly but rather calls the
mark_transaction_to_rollback function and returns an error.
sql/handler.cc:
Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
Now the ha_autocommit_or_rollback function rolls back main transaction
when not in a sub statement and the thd->transaction_rollback_request
is set.
mysql-test/r/innodb-big.result:
Added a test case for the bug#24989: The DEADLOCK error is improperly handled by
InnoDB.
mysql-test/t/innodb-big.test:
Added a test case for the bug#24989: The DEADLOCK error is improperly handled by
InnoDB.
sql/sql_class.h:
Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
The transaction_rollback_request and the is_fatal_sub_stmt_error flags are
added to the THD class.
sql/sql_class.cc:
Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
Initialization of the transaction_rollback_request and the
is_fatal_sub_stmt_error flags are added to the THD class constructor.
The mark_transaction_to_rollback function is added.
The THD::restore_sub_statement_state function now resets the
thd->is_fatal_sub_stmt_error flag on exit from a sub-statement.
sql/sp_rcontext.h:
Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
The sp_rcontext::find_handler function now accepts a THD handle as a parameter.
The in_sub_stmt flag is added to the sp_rcontext class.
sql/sp_rcontext.cc:
Bug#24989: The DEADLOCK error is improperly handled by InnoDB.
The sp_rcontext::find_handler() now doesn't allow errors to be caught by the
trigger/function error handlers when the thd->is_fatal_sub_stmt_error flag
is set. Instead it tries to find a most inner procedure that isn't called
directly or indirectly from any function/trigger.
Procedures are still allowed to catch such errors.
The sp_rcontext::find_handler function now accepts a THD handle as a parameter.
Diffstat (limited to 'sql/sp_rcontext.cc')
-rw-r--r-- | sql/sp_rcontext.cc | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index e49c4eb1240..ac7c46c9fe5 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -37,6 +37,7 @@ sp_rcontext::sp_rcontext(sp_pcontext *root_parsing_ctx, m_var_items(0), m_return_value_fld(return_value_fld), m_return_value_set(FALSE), + in_sub_stmt(FALSE), m_hcount(0), m_hsp(0), m_ihsp(0), @@ -67,6 +68,8 @@ sp_rcontext::~sp_rcontext() bool sp_rcontext::init(THD *thd) { + in_sub_stmt= thd->in_sub_stmt; + if (init_var_table(thd) || init_var_items()) return TRUE; @@ -191,7 +194,7 @@ sp_rcontext::set_return_value(THD *thd, Item **return_value_item) */ bool -sp_rcontext::find_handler(uint sql_errno, +sp_rcontext::find_handler(THD *thd, uint sql_errno, MYSQL_ERROR::enum_warning_level level) { if (m_hfound >= 0) @@ -200,6 +203,15 @@ sp_rcontext::find_handler(uint sql_errno, const char *sqlstate= mysql_errno_to_sqlstate(sql_errno); int i= m_hcount, found= -1; + /* + If this is a fatal sub-statement error, and this runtime + context corresponds to a sub-statement, no CONTINUE/EXIT + handlers from this context are applicable: try to locate one + in the outer scope. + */ + if (thd->is_fatal_sub_stmt_error && in_sub_stmt) + i= 0; + /* Search handlers from the latest (innermost) to the oldest (outermost) */ while (i--) { @@ -252,7 +264,7 @@ sp_rcontext::find_handler(uint sql_errno, */ if (m_prev_runtime_ctx && IS_EXCEPTION_CONDITION(sqlstate) && level == MYSQL_ERROR::WARN_LEVEL_ERROR) - return m_prev_runtime_ctx->find_handler(sql_errno, level); + return m_prev_runtime_ctx->find_handler(thd, sql_errno, level); return FALSE; } m_hfound= found; @@ -298,7 +310,7 @@ sp_rcontext::handle_error(uint sql_errno, elevated_level= MYSQL_ERROR::WARN_LEVEL_ERROR; } - if (find_handler(sql_errno, elevated_level)) + if (find_handler(thd, sql_errno, elevated_level)) { if (elevated_level == MYSQL_ERROR::WARN_LEVEL_ERROR) { |