mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 16:38:42 +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:
@@ -369,6 +369,52 @@ void MySQLConnection::CommitTransaction()
|
||||
Execute("COMMIT");
|
||||
}
|
||||
|
||||
bool MySQLConnection::ExecuteTransaction(SQLTransaction& transaction)
|
||||
{
|
||||
std::queue<SQLElementData> &queries = transaction->m_queries;
|
||||
if (queries.empty())
|
||||
return false;
|
||||
|
||||
BeginTransaction();
|
||||
while (!queries.empty())
|
||||
{
|
||||
SQLElementData data = queries.front();
|
||||
switch (data.type)
|
||||
{
|
||||
case SQL_ELEMENT_PREPARED:
|
||||
{
|
||||
PreparedStatement* stmt = data.element.stmt;
|
||||
ASSERT(stmt);
|
||||
if (!Execute(stmt))
|
||||
{
|
||||
sLog->outSQLDriver("[Warning] Transaction aborted. %u queries not executed.", (uint32)queries.size());
|
||||
RollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
delete data.element.stmt;
|
||||
}
|
||||
break;
|
||||
case SQL_ELEMENT_RAW:
|
||||
{
|
||||
const char* sql = data.element.query;
|
||||
ASSERT(sql);
|
||||
if (!Execute(sql))
|
||||
{
|
||||
sLog->outSQLDriver("[Warning] Transaction aborted. %u queries not executed.", (uint32)queries.size());
|
||||
RollbackTransaction();
|
||||
return false;
|
||||
}
|
||||
free((void*)const_cast<char*>(sql));
|
||||
}
|
||||
break;
|
||||
}
|
||||
queries.pop();
|
||||
}
|
||||
|
||||
CommitTransaction();
|
||||
return true;
|
||||
}
|
||||
|
||||
MySQLPreparedStatement* MySQLConnection::GetPreparedStatement(uint32 index)
|
||||
{
|
||||
ASSERT(index < m_stmts.size());
|
||||
@@ -462,6 +508,9 @@ bool MySQLConnection::_HandleMySQLErrno(uint32 errNo)
|
||||
return _HandleMySQLErrno(lErrno); // Call self (recursive)
|
||||
}
|
||||
|
||||
case 1213: // "Deadlock found when trying to get lock; try restarting transaction"
|
||||
return true; // Implemented in TransactionTask::Execute and DatabaseWorkerPool<T>::DirectCommitTransaction
|
||||
|
||||
// Query related errors - skip query
|
||||
case 1058: // "Column count doesn't match value count"
|
||||
case 1062: // "Duplicate entry '%s' for key '%d'"
|
||||
|
||||
Reference in New Issue
Block a user