mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08: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()
|
void CDbConnectionPool::Worker()
|
||||||
{
|
{
|
||||||
|
// remember last working server and try to connect to it first
|
||||||
|
int ReadServer = 0;
|
||||||
|
int WriteServer = 0;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
m_NumElem.wait();
|
m_NumElem.wait();
|
||||||
|
@ -151,8 +154,11 @@ void CDbConnectionPool::Worker()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)m_aapDbConnections[Mode::READ].size(); i++)
|
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;
|
Success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -162,8 +168,11 @@ void CDbConnectionPool::Worker()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)m_aapDbConnections[Mode::WRITE].size(); i++)
|
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))
|
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;
|
Success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -174,6 +183,7 @@ void CDbConnectionPool::Worker()
|
||||||
{
|
{
|
||||||
if(ExecSqlFunc(m_aapDbConnections[Mode::WRITE_BACKUP][i].get(), pThreadData.get(), true))
|
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;
|
Success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -181,8 +191,8 @@ void CDbConnectionPool::Worker()
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
if(Success)
|
if(!Success)
|
||||||
dbg_msg("sql", "%s done", pThreadData->m_pName);
|
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)
|
#if defined(CONF_SQL)
|
||||||
catch (sql::SQLException &e)
|
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
|
#endif
|
||||||
catch (std::runtime_error &e)
|
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 (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
dbg_msg("sql", "Unexpected exception caught");
|
dbg_msg("sql", "%s Unexpected exception caught", pData->m_pName);
|
||||||
}
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
pConnection->Unlock();
|
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->Disconnect();
|
pConnection->Disconnect();
|
||||||
if(!Success)
|
if(!Success)
|
||||||
dbg_msg("sql", "%s failed", pData->m_pName);
|
dbg_msg("sql", "%s failed", pData->m_pName);
|
||||||
|
|
Loading…
Reference in a new issue