mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 09:17:36 +01:00
Core/DBLayer:
- Implement DatabaseWorkerPool::DirectCommitTransaction for synchronous transaction execution (as opposed to asynchronous/enqueued). - Add MySQL errno 1213 "Deadlock found when trying to get lock; try restarting transaction" handler. If 1213 is called the core will retry to directly execute the transaction a maximum of 5 times.
This commit is contained in:
@@ -67,45 +67,16 @@ void Transaction::Cleanup()
|
||||
|
||||
bool TransactionTask::Execute()
|
||||
{
|
||||
std::queue<SQLElementData> &queries = m_trans->m_queries;
|
||||
if (queries.empty())
|
||||
return false;
|
||||
if (m_conn->ExecuteTransaction(m_trans))
|
||||
return true;
|
||||
|
||||
m_conn->BeginTransaction();
|
||||
while (!queries.empty())
|
||||
if (m_conn->GetLastError() == 1213)
|
||||
{
|
||||
SQLElementData data = queries.front();
|
||||
switch (data.type)
|
||||
{
|
||||
case SQL_ELEMENT_PREPARED:
|
||||
{
|
||||
PreparedStatement* stmt = data.element.stmt;
|
||||
ASSERT(stmt);
|
||||
if (!m_conn->Execute(stmt))
|
||||
{
|
||||
sLog->outSQLDriver("[Warning] Transaction aborted. %u queries not executed.", (uint32)queries.size());
|
||||
m_conn->RollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
delete data.element.stmt;
|
||||
}
|
||||
break;
|
||||
case SQL_ELEMENT_RAW:
|
||||
{
|
||||
const char* sql = data.element.query;
|
||||
ASSERT(sql);
|
||||
if (!m_conn->Execute(sql))
|
||||
{
|
||||
sLog->outSQLDriver("[Warning] Transaction aborted. %u queries not executed.", (uint32)queries.size());
|
||||
m_conn->RollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
free((void*)const_cast<char*>(sql));
|
||||
}
|
||||
break;
|
||||
}
|
||||
queries.pop();
|
||||
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))
|
||||
return true;
|
||||
}
|
||||
m_conn->CommitTransaction();
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user