Shared/Database: Improve dead-lock error handling

Improve dead-lock error handling by making sure only 1 thread at time retries to execute a transaction so they don't keep dead-locking each other.

(cherry picked from commit 62001360dd)
This commit is contained in:
jackpoz
2015-02-11 22:42:46 +01:00
committed by Duarte Duarte
parent a7c8caf2ef
commit e36fb12359
2 changed files with 5 additions and 0 deletions

View File

@@ -19,6 +19,8 @@
#include "Transaction.h"
#include <mysqld_error.h>
std::mutex TransactionTask::_deadlockLock;
//- Append a raw ad-hoc query to the transaction
void Transaction::Append(const char* sql)
{
@@ -81,6 +83,8 @@ bool TransactionTask::Execute()
if (errorCode == ER_LOCK_DEADLOCK)
{
// Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other
std::lock_guard<std::mutex> lock(_deadlockLock);
uint8 loopBreaker = 5; // Handle MySQL Errno 1213 without extending deadlock to the core itself
for (uint8 i = 0; i < loopBreaker; ++i)
if (!m_conn->ExecuteTransaction(m_trans))