mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Merge pull request #2623 from Zwelf/pr-mysql-enhance-unreachable-server-situation
MySQL enhance unreachable server situation
This commit is contained in:
commit
b2ebcb4f3c
|
@ -133,6 +133,9 @@ void CDbConnectionPool::Worker(void *pUser)
|
|||
|
||||
void CDbConnectionPool::Worker()
|
||||
{
|
||||
// remember last working server and try to connect to it first
|
||||
int ReadServer = 0;
|
||||
int WriteServer = 0;
|
||||
while(1)
|
||||
{
|
||||
m_NumElem.wait();
|
||||
|
@ -151,8 +154,11 @@ void CDbConnectionPool::Worker()
|
|||
{
|
||||
for(int i = 0; i < (int)m_aapDbConnections[Mode::READ].size(); i++)
|
||||
{
|
||||
if(ExecSqlFunc(m_aapDbConnections[Mode::READ][i].get(), pThreadData.get(), false))
|
||||
int CurServer = (ReadServer + i) % (int)m_aapDbConnections[Mode::READ].size();
|
||||
if(ExecSqlFunc(m_aapDbConnections[Mode::READ][CurServer].get(), pThreadData.get(), false))
|
||||
{
|
||||
ReadServer = CurServer;
|
||||
dbg_msg("sql", "%s done on read database %d", pThreadData->m_pName, CurServer);
|
||||
Success = true;
|
||||
break;
|
||||
}
|
||||
|
@ -162,8 +168,11 @@ void CDbConnectionPool::Worker()
|
|||
{
|
||||
for(int i = 0; i < (int)m_aapDbConnections[Mode::WRITE].size(); i++)
|
||||
{
|
||||
int CurServer = (WriteServer + i) % (int)m_aapDbConnections[Mode::READ].size();
|
||||
if(ExecSqlFunc(m_aapDbConnections[Mode::WRITE][i].get(), pThreadData.get(), false))
|
||||
{
|
||||
WriteServer = CurServer;
|
||||
dbg_msg("sql", "%s done on write database %d", pThreadData->m_pName, CurServer);
|
||||
Success = true;
|
||||
break;
|
||||
}
|
||||
|
@ -174,6 +183,7 @@ void CDbConnectionPool::Worker()
|
|||
{
|
||||
if(ExecSqlFunc(m_aapDbConnections[Mode::WRITE_BACKUP][i].get(), pThreadData.get(), true))
|
||||
{
|
||||
dbg_msg("sql", "%s done on write backup database %d", pThreadData->m_pName, i);
|
||||
Success = true;
|
||||
break;
|
||||
}
|
||||
|
@ -181,8 +191,8 @@ void CDbConnectionPool::Worker()
|
|||
}
|
||||
} break;
|
||||
}
|
||||
if(Success)
|
||||
dbg_msg("sql", "%s done", pThreadData->m_pName);
|
||||
if(!Success)
|
||||
dbg_msg("sql", "%s failed on all databases", pThreadData->m_pName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,18 +218,35 @@ bool CDbConnectionPool::ExecSqlFunc(IDbConnection *pConnection, CSqlExecData *pD
|
|||
#if defined(CONF_SQL)
|
||||
catch (sql::SQLException &e)
|
||||
{
|
||||
dbg_msg("sql", "MySQL Error: %s", e.what());
|
||||
dbg_msg("sql", "%s MySQL Error: %s", pData->m_pName, e.what());
|
||||
}
|
||||
#endif
|
||||
catch (std::runtime_error &e)
|
||||
{
|
||||
dbg_msg("sql", "SQLite Error: %s", e.what());
|
||||
dbg_msg("sql", "%s SQLite Error: %s", pData->m_pName, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
dbg_msg("sql", "Unexpected exception caught");
|
||||
dbg_msg("sql", "%s Unexpected exception caught", pData->m_pName);
|
||||
}
|
||||
try
|
||||
{
|
||||
pConnection->Unlock();
|
||||
}
|
||||
#if defined(CONF_SQL)
|
||||
catch (sql::SQLException &e)
|
||||
{
|
||||
dbg_msg("sql", "%s MySQL Error during unlock: %s", pData->m_pName, e.what());
|
||||
}
|
||||
#endif
|
||||
catch (std::runtime_error &e)
|
||||
{
|
||||
dbg_msg("sql", "%s SQLite Error during unlock: %s", pData->m_pName, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
dbg_msg("sql", "%s Unexpected exception caught during unlock", pData->m_pName);
|
||||
}
|
||||
pConnection->Unlock();
|
||||
pConnection->Disconnect();
|
||||
if(!Success)
|
||||
dbg_msg("sql", "%s failed", pData->m_pName);
|
||||
|
|
Loading…
Reference in a new issue