diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2019-01-30 13:10:38 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2019-01-30 17:36:49 +0200 |
commit | e45e0b3aa3127f4ab8e588b255215432ffc2a5e8 (patch) | |
tree | c98cc65ba5e1cb192c6dcc41295d9abdfc71f9a2 | |
parent | 5aeaba11c7dcbda40fd9cd68ab060a446ab6eb77 (diff) | |
download | mariadb-git-e45e0b3aa3127f4ab8e588b255215432ffc2a5e8.tar.gz |
Report deadlocks to the error log if log_warnings>2
To trace down the cause of a deadlock, ensure that for every
instance of reporting ER_LOCK_DEADLOCK, a message will be output
to the server error log if the log_warnings level is more than 2.
To enable the output: SET GLOBAL log_warnings=3;
-rw-r--r-- | sql/handler.cc | 1 | ||||
-rw-r--r-- | sql/mdl.cc | 2 | ||||
-rw-r--r-- | sql/rpl_parallel.cc | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 7 | ||||
-rw-r--r-- | sql/sql_parse.cc | 3 | ||||
-rw-r--r-- | sql/table.cc | 2 | ||||
-rw-r--r-- | sql/transaction.cc | 3 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 8 |
8 files changed, 25 insertions, 3 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index 79ccf272a1a..e2ad605bf77 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3669,6 +3669,7 @@ void handler::print_error(int error, myf errflag) get_error_message(error, &str); full_err_msg.append(str); my_printf_error(ER_LOCK_DEADLOCK, "%s", errflag, full_err_msg.c_ptr_safe()); + if (global_system_variables.log_warnings > 2) errflag|= MYF(ME_ERROR_LOG); DBUG_VOID_RETURN; } case HA_ERR_READ_ONLY_TRANSACTION: diff --git a/sql/mdl.cc b/sql/mdl.cc index ce2e29bc66f..671943299ef 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -2172,6 +2172,8 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout) { case MDL_wait::VICTIM: my_error(ER_LOCK_DEADLOCK, MYF(0)); + if (global_system_variables.log_warnings > 2) + sql_print_information("MDL deadlock victim killed"); break; case MDL_wait::TIMEOUT: my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0)); diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index 34f9113f7fe..9f279433bc1 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -629,6 +629,8 @@ convert_kill_to_deadlock_error(rpl_group_info *rgi) { thd->clear_error(); my_error(ER_LOCK_DEADLOCK, MYF(0)); + if (global_system_variables.log_warnings > 2) + sql_print_information("convert_kill_to_deadlock_error"); thd->reset_killed(); } } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 986064129d6..70c1f11ffd4 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2401,8 +2401,11 @@ Locked_tables_list::reopen_tables(THD *thd) mysql_lock_merge(thd->lock, lock)) == NULL) { unlink_all_closed_tables(thd, lock, reopen_count); - if (! thd->killed) + if (! thd->killed) { my_error(ER_LOCK_DEADLOCK, MYF(0)); + if (global_system_variables.log_warnings > 2) + sql_print_information("deadlock in Locked_tables_list"); + } DBUG_RETURN(TRUE); } thd->lock= merged_lock; @@ -2825,6 +2828,8 @@ request_backoff_action(enum_open_table_action action_arg, if (action_arg == OT_BACKOFF_AND_RETRY && m_has_locks) { my_error(ER_LOCK_DEADLOCK, MYF(0)); + if (global_system_variables.log_warnings > 2) + sql_print_information("deadlock in request_backoff_action"); m_thd->mark_transaction_to_rollback(true); return TRUE; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 09bb628ea8b..060d1e2005d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7841,7 +7841,8 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, thd->wsrep_retry_counter, thd->variables.wsrep_retry_autocommit, thd->query()); my_message(ER_LOCK_DEADLOCK, "Deadlock: wsrep aborted transaction", - MYF(0)); + global_system_variables.log_warnings > 2 + ? MYF(ME_ERROR_LOG) : MYF(0)); thd->reset_killed(); thd->wsrep_conflict_state= NO_CONFLICT; if (thd->wsrep_conflict_state != REPLAYING) diff --git a/sql/table.cc b/sql/table.cc index ce6c7d4ddb8..72e9707ea6d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4459,6 +4459,8 @@ bool TABLE_SHARE::wait_for_old_version(THD *thd, struct timespec *abstime, return FALSE; case MDL_wait::VICTIM: my_error(ER_LOCK_DEADLOCK, MYF(0)); + if (global_system_variables.log_warnings > 2) + sql_print_information("deadlock in wait_for_old_version"); return TRUE; case MDL_wait::TIMEOUT: my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0)); diff --git a/sql/transaction.cc b/sql/transaction.cc index a6db204c45b..d89b4d5c18b 100644 --- a/sql/transaction.cc +++ b/sql/transaction.cc @@ -106,7 +106,8 @@ static bool xa_trans_rolled_back(XID_STATE *xid_state) my_error(ER_XA_RBTIMEOUT, MYF(0)); break; case ER_LOCK_DEADLOCK: - my_error(ER_XA_RBDEADLOCK, MYF(0)); + my_error(ER_XA_RBDEADLOCK, global_system_variables.log_warnings > 2 + ? MYF(ME_ERROR_LOG) : MYF(0)); break; default: my_error(ER_XA_RBROLLBACK, MYF(0)); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 0e5af0b1f6a..ece8dda6fb5 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -2023,6 +2023,14 @@ convert_error_code_to_mysql( if (thd != NULL) { thd_mark_transaction_to_rollback(thd, 1); + if (global_system_variables.log_warnings > 2) { + size_t len; + const char* q = innobase_get_stmt_unsafe( + thd, &len); + sql_print_information( + "InnoDB deadlock for %s", + q ? q : "(unknown)"); + } } return(HA_ERR_LOCK_DEADLOCK); |