mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
try next sqlmaster also if the current write fails
This commit is contained in:
parent
7199ae3f22
commit
2d41ce3527
|
@ -137,8 +137,17 @@ void CSqlScore::SaveTeamScoreThread(void *pUser)
|
||||||
{
|
{
|
||||||
CSqlTeamScoreData *pData = (CSqlTeamScoreData *)pUser;
|
CSqlTeamScoreData *pData = (CSqlTeamScoreData *)pUser;
|
||||||
|
|
||||||
|
for (int skipCount = 0; skipCount < MAX_SQLMASTERS; skipCount++)
|
||||||
|
{
|
||||||
|
|
||||||
// Connect to database
|
// 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())
|
if(pData->SqlServer())
|
||||||
{
|
{
|
||||||
|
@ -247,9 +256,13 @@ void CSqlScore::SaveTeamScoreThread(void *pUser)
|
||||||
|
|
||||||
// disconnect from database
|
// disconnect from database
|
||||||
pData->SqlServer()->Disconnect();
|
pData->SqlServer()->Disconnect();
|
||||||
|
|
||||||
|
// no errors and everything updated --> break fallback loop
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dbg_msg("SQL", "ERROR: Could not connect to SQL-Server");
|
dbg_msg("SQL", "ERROR: Could not connect to SQL-Server");
|
||||||
|
}
|
||||||
|
|
||||||
delete pData;
|
delete pData;
|
||||||
}
|
}
|
||||||
|
@ -446,8 +459,17 @@ void CSqlScore::SaveScoreThread(void *pUser)
|
||||||
{
|
{
|
||||||
CSqlScoreData *pData = (CSqlScoreData *)pUser;
|
CSqlScoreData *pData = (CSqlScoreData *)pUser;
|
||||||
|
|
||||||
|
for (int skipCount = 0; skipCount < MAX_SQLMASTERS; skipCount++)
|
||||||
|
{
|
||||||
|
|
||||||
// Connect to database
|
// 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())
|
if(pData->SqlServer())
|
||||||
{
|
{
|
||||||
|
@ -497,9 +519,13 @@ void CSqlScore::SaveScoreThread(void *pUser)
|
||||||
|
|
||||||
// disconnect from database
|
// disconnect from database
|
||||||
pData->SqlServer()->Disconnect();
|
pData->SqlServer()->Disconnect();
|
||||||
|
|
||||||
|
// no errors and everything updated --> break fallback loop
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dbg_msg("SQL", "ERROR: Could not connect to SQL-Server");
|
dbg_msg("SQL", "ERROR: Could not connect to SQL-Server");
|
||||||
|
}
|
||||||
|
|
||||||
delete pData;
|
delete pData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
// generic implementation to provide sqlserver, gameserver and server
|
// generic implementation to provide sqlserver, gameserver and server
|
||||||
struct CSqlData
|
struct CSqlData
|
||||||
{
|
{
|
||||||
CSqlData() : m_pSqlServer(ms_pSqlServer) {}
|
CSqlData() : m_pSqlServer(ms_pSqlServer), m_ActiveMaster(-1) {}
|
||||||
|
|
||||||
CGameContext* GameServer() { return ms_pGameServer; }
|
CGameContext* GameServer() { return ms_pGameServer; }
|
||||||
IServer* Server() { return ms_pServer; }
|
IServer* Server() { return ms_pServer; }
|
||||||
|
@ -79,23 +79,26 @@ struct CSqlData
|
||||||
const char* MapName() { return ms_pMap; }
|
const char* MapName() { return ms_pMap; }
|
||||||
CSqlServer* SqlMasterServer(int i) { return ms_pMasterSqlServers[i]; }
|
CSqlServer* SqlMasterServer(int i) { return ms_pMasterSqlServers[i]; }
|
||||||
CSqlServer* SqlServer() { return m_pSqlServer; }
|
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)
|
if (useMasters)
|
||||||
{
|
{
|
||||||
m_pSqlServer = 0;
|
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())
|
if (SqlMasterServer(i) && SqlMasterServer(i)->Connect())
|
||||||
{
|
{
|
||||||
m_pSqlServer = SqlMasterServer(i);
|
m_pSqlServer = SqlMasterServer(i);
|
||||||
|
m_ActiveMaster = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SqlMasterServer(i))
|
if (SqlMasterServer(i))
|
||||||
dbg_msg("SQL", "Warning: Unable to connect to sqlmaster %d ('%s'), trying next...", i, SqlMasterServer(i)->GetIP());
|
dbg_msg("SQL", "Warning: Unable to connect to sqlmaster %d ('%s'), trying next...", i, SqlMasterServer(i)->GetIP());
|
||||||
}
|
}
|
||||||
dbg_msg("SQL", "ERROR: No sqlmasterservers available");
|
dbg_msg("SQL", "ERROR: No sqlmasterservers available");
|
||||||
|
m_ActiveMaster = -1;
|
||||||
}
|
}
|
||||||
else if (!SqlServer()->Connect())
|
else if (!SqlServer()->Connect())
|
||||||
m_pSqlServer = 0;
|
m_pSqlServer = 0;
|
||||||
|
@ -109,6 +112,7 @@ struct CSqlData
|
||||||
static CSqlServer **ms_pMasterSqlServers;
|
static CSqlServer **ms_pMasterSqlServers;
|
||||||
|
|
||||||
CSqlServer *m_pSqlServer;
|
CSqlServer *m_pSqlServer;
|
||||||
|
int m_ActiveMaster;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CSqlMapData : CSqlData
|
struct CSqlMapData : CSqlData
|
||||||
|
|
Loading…
Reference in a new issue