24#include <mysqld_error.h>
31#define DEADLOCK_MAX_RETRY_TIME_MS 60000
37 m_queries.emplace_back(std::in_place_type<std::string>, sql);
44 m_queries.emplace_back(std::in_place_type<std::unique_ptr<PreparedStatementBase>>, stmt);
63 if (errorCode == ER_LOCK_DEADLOCK)
65 std::string threadId = []()
68 std::ostringstream threadIdStream;
69 threadIdStream << std::this_thread::get_id();
70 return threadIdStream.str();
81 TC_LOG_WARN(
"sql.sql",
"Deadlocked SQL Transaction, retrying. Loop timer: {} ms, Thread Id: {}", loopDuration, threadId);
84 TC_LOG_ERROR(
"sql.sql",
"Fatal deadlocked SQL Transaction, it will not be retried anymore. Thread Id: {}", threadId);
100 if (
m_future.valid() &&
m_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
#define TC_LOG_WARN(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
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)
TransactionFuture 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)