diff options
author | jackpoz <giacomopoz@gmail.com> | 2020-07-09 22:37:23 +0200 |
---|---|---|
committer | jackpoz <giacomopoz@gmail.com> | 2020-07-09 22:37:23 +0200 |
commit | f10b9d617abc8589d2cfc4671b2d44293abbf44f (patch) | |
tree | 20493219fbc5580bf5400da8043648b4557c6e55 /src/server/database/Database/Transaction.cpp | |
parent | b4adaa838c2e44f4008152cc955410d25ff4d8b0 (diff) |
Core/Database: Apply 54b0b8f5ead41f936b12e97d1b4fbacd9b89ab53 to 141ada19b00fb9d0dd1a260d86d97bbb709a0f5e
Diffstat (limited to 'src/server/database/Database/Transaction.cpp')
-rw-r--r-- | src/server/database/Database/Transaction.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/server/database/Database/Transaction.cpp b/src/server/database/Database/Transaction.cpp index 9b2178d2c4b..609ae0b9588 100644 --- a/src/server/database/Database/Transaction.cpp +++ b/src/server/database/Database/Transaction.cpp @@ -122,17 +122,24 @@ bool TransactionWithResultTask::Execute() if (errorCode == ER_LOCK_DEADLOCK) { + std::ostringstream threadIdStream; + threadIdStream << std::this_thread::get_id(); + std::string threadId = threadIdStream.str(); + // Make sure only 1 async thread retries a transaction so they don't keep dead-locking each other std::lock_guard<std::mutex> lock(_deadlockLock); - uint8 loopBreaker = 5; // Handle MySQL Errno 1213 without extending deadlock to the core itself - for (uint8 i = 0; i < loopBreaker; ++i) + for (uint32 loopDuration = 0, startMSTime = getMSTime(); loopDuration <= DEADLOCK_MAX_RETRY_TIME_MS; loopDuration = GetMSTimeDiffToNow(startMSTime)) { if (!TryExecute()) { m_result.set_value(true); return true; } + + TC_LOG_WARN("sql.sql", "Deadlocked SQL Transaction, retrying. Loop timer: %u ms, Thread Id: %s", loopDuration, threadId.c_str()); } + + TC_LOG_ERROR("sql.sql", "Fatal deadlocked SQL Transaction, it will not be retried anymore. Thread Id: %s", threadId.c_str()); } // Clean up now. |