fix(Core/Shared/DB): recommit transactions on dead-lock error (#6069)

This commit is contained in:
UltraNix
2021-06-01 15:36:59 +02:00
committed by GitHub
parent 1889fffbde
commit beb4df9d3e
4 changed files with 20 additions and 12 deletions

View File

@@ -7,6 +7,8 @@
#include "DatabaseWorkerPool.h"
#include "DatabaseEnv.h"
#include <mysqld_error.h>
#define MIN_MYSQL_SERVER_VERSION 50700u
#define MIN_MYSQL_CLIENT_VERSION 50700u
@@ -318,7 +320,8 @@ template <class T>
void DatabaseWorkerPool<T>::DirectCommitTransaction(SQLTransaction& transaction)
{
T* con = GetFreeConnection();
if (con->ExecuteTransaction(transaction))
int errorCode = con->ExecuteTransaction(transaction);
if (!errorCode)
{
con->Unlock(); // OK, operation succesful
return;
@@ -326,12 +329,12 @@ void DatabaseWorkerPool<T>::DirectCommitTransaction(SQLTransaction& transaction)
//! Handle MySQL Errno 1213 without extending deadlock to the core itself
//! TODO: More elegant way
if (con->GetLastError() == 1213)
if (errorCode == ER_LOCK_DEADLOCK)
{
uint8 loopBreaker = 5;
for (uint8 i = 0; i < loopBreaker; ++i)
{
if (con->ExecuteTransaction(transaction))
if (!con->ExecuteTransaction(transaction))
break;
}
}