From 2d41ce35273878d4c1f1905650219752f4e08ebc Mon Sep 17 00:00:00 2001 From: H-M-H Date: Sun, 6 Dec 2015 00:58:20 +0100 Subject: [PATCH] try next sqlmaster also if the current write fails --- src/game/server/score/sql_score.cpp | 30 +++++++++++++++++++++++++++-- src/game/server/score/sql_score.h | 10 +++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index 4069a48e4..7b6543792 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -137,8 +137,17 @@ void CSqlScore::SaveTeamScoreThread(void *pUser) { CSqlTeamScoreData *pData = (CSqlTeamScoreData *)pUser; + for (int skipCount = 0; skipCount < MAX_SQLMASTERS; skipCount++) + { + // Connect to database - pData->ConnectSqlServer(g_Config.m_SvUseSQLMasters); + pData->ConnectSqlServer(g_Config.m_SvUseSQLMasters, skipCount); + + if (pData->ActiveMasterID() == -1) + { + dbg_msg("SQL", "ERROR: Could not connect to ANY SQLMASTER-Server"); + return; + } if(pData->SqlServer()) { @@ -247,9 +256,13 @@ void CSqlScore::SaveTeamScoreThread(void *pUser) // disconnect from database pData->SqlServer()->Disconnect(); + + // no errors and everything updated --> break fallback loop + break; } else dbg_msg("SQL", "ERROR: Could not connect to SQL-Server"); + } delete pData; } @@ -446,8 +459,17 @@ void CSqlScore::SaveScoreThread(void *pUser) { CSqlScoreData *pData = (CSqlScoreData *)pUser; + for (int skipCount = 0; skipCount < MAX_SQLMASTERS; skipCount++) + { + // Connect to database - pData->ConnectSqlServer(g_Config.m_SvUseSQLMasters); + pData->ConnectSqlServer(g_Config.m_SvUseSQLMasters, skipCount); + + if (pData->ActiveMasterID() == -1) + { + dbg_msg("SQL", "ERROR: Could not connect to ANY SQLMASTER-Server"); + return; + } if(pData->SqlServer()) { @@ -497,9 +519,13 @@ void CSqlScore::SaveScoreThread(void *pUser) // disconnect from database pData->SqlServer()->Disconnect(); + + // no errors and everything updated --> break fallback loop + break; } else dbg_msg("SQL", "ERROR: Could not connect to SQL-Server"); + } delete pData; } diff --git a/src/game/server/score/sql_score.h b/src/game/server/score/sql_score.h index 664538b0e..e4afed014 100644 --- a/src/game/server/score/sql_score.h +++ b/src/game/server/score/sql_score.h @@ -71,7 +71,7 @@ public: // generic implementation to provide sqlserver, gameserver and server struct CSqlData { - CSqlData() : m_pSqlServer(ms_pSqlServer) {} + CSqlData() : m_pSqlServer(ms_pSqlServer), m_ActiveMaster(-1) {} CGameContext* GameServer() { return ms_pGameServer; } IServer* Server() { return ms_pServer; } @@ -79,23 +79,26 @@ struct CSqlData const char* MapName() { return ms_pMap; } CSqlServer* SqlMasterServer(int i) { return ms_pMasterSqlServers[i]; } CSqlServer* SqlServer() { return m_pSqlServer; } + int ActiveMasterID() { return m_ActiveMaster; } - void ConnectSqlServer(bool useMasters = false) + void ConnectSqlServer(bool useMasters = false, int skipCount = 0) { if (useMasters) { m_pSqlServer = 0; - for (int i = 0; i < MAX_SQLMASTERS; i++) + for (int i = skipCount; i < MAX_SQLMASTERS; i++) { if (SqlMasterServer(i) && SqlMasterServer(i)->Connect()) { m_pSqlServer = SqlMasterServer(i); + m_ActiveMaster = 0; return; } if (SqlMasterServer(i)) dbg_msg("SQL", "Warning: Unable to connect to sqlmaster %d ('%s'), trying next...", i, SqlMasterServer(i)->GetIP()); } dbg_msg("SQL", "ERROR: No sqlmasterservers available"); + m_ActiveMaster = -1; } else if (!SqlServer()->Connect()) m_pSqlServer = 0; @@ -109,6 +112,7 @@ struct CSqlData static CSqlServer **ms_pMasterSqlServers; CSqlServer *m_pSqlServer; + int m_ActiveMaster; }; struct CSqlMapData : CSqlData