24#include <mysqld_error.h>
31#define DEADLOCK_MAX_RETRY_TIME_MS 60000
39 m_queries.emplace_back(std::in_place_type<std::string>, sql);
46 m_queries.emplace_back(std::in_place_type<std::unique_ptr<PreparedStatementBase>>, stmt);
65 if (errorCode == ER_LOCK_DEADLOCK)
67 std::string threadId = []()
70 std::ostringstream threadIdStream;
71 threadIdStream << std::this_thread::get_id();
72 return threadIdStream.str();
83 TC_LOG_WARN(
"sql.sql",
"Deadlocked SQL Transaction, retrying. Loop timer: {} ms, Thread Id: {}", loopDuration, threadId);
86 TC_LOG_ERROR(
"sql.sql",
"Fatal deadlocked SQL Transaction, it will not be retried anymore. Thread Id: {}", threadId);
102 if (
m_future.valid() &&
m_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
#define TC_LOG_ERROR(filterType__, message__,...)
#define TC_LOG_WARN(filterType__, message__,...)
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
#define DEADLOCK_MAX_RETRY_TIME_MS
int ExecuteTransaction(std::shared_ptr< TransactionBase > transaction)
std::vector< TransactionData > m_queries
void AppendPreparedStatement(PreparedStatementBase *statement)
void Append(char const *sql)
std::future< bool > m_future
std::function< void(bool)> m_callback
static int TryExecute(MySQLConnection *conn, std::shared_ptr< TransactionBase > trans)
static std::mutex _deadlockLock
static bool Execute(MySQLConnection *conn, std::shared_ptr< TransactionBase > trans)