mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Skip over read queries and write into backup database in FailMode
This commit is contained in:
parent
d8258fcda9
commit
8c8b4e5bb4
|
@ -133,8 +133,15 @@ void CDbConnectionPool::Worker()
|
|||
// remember last working server and try to connect to it first
|
||||
int ReadServer = 0;
|
||||
int WriteServer = 0;
|
||||
// enter fail mode when a sql request fails, skip read request during it and
|
||||
// write to the backup database until all requests are handled
|
||||
bool FailMode = false;
|
||||
while(1)
|
||||
{
|
||||
if(FailMode && m_NumElem.GetApproximateValue() == 0)
|
||||
{
|
||||
FailMode = false;
|
||||
}
|
||||
m_NumElem.Wait();
|
||||
auto pThreadData = std::move(m_aTasks[LastElem++]);
|
||||
// work through all database jobs after OnShutdown is called before exiting the thread
|
||||
|
@ -156,6 +163,11 @@ void CDbConnectionPool::Worker()
|
|||
dbg_msg("sql", "%s dismissed read request during shutdown", pThreadData->m_pName);
|
||||
break;
|
||||
}
|
||||
if(FailMode)
|
||||
{
|
||||
dbg_msg("sql", "%s dismissed read request during FailMode", pThreadData->m_pName);
|
||||
break;
|
||||
}
|
||||
int CurServer = (ReadServer + i) % (int)m_aapDbConnections[Mode::READ].size();
|
||||
if(ExecSqlFunc(m_aapDbConnections[Mode::READ][CurServer].get(), pThreadData.get(), false))
|
||||
{
|
||||
|
@ -164,6 +176,10 @@ void CDbConnectionPool::Worker()
|
|||
Success = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
FailMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -171,10 +187,16 @@ void CDbConnectionPool::Worker()
|
|||
{
|
||||
for(int i = 0; i < (int)m_aapDbConnections[Mode::WRITE].size(); i++)
|
||||
{
|
||||
if(m_Shutdown && !m_aapDbConnections[Mode::WRITE_BACKUP].empty()) {
|
||||
if(m_Shutdown && !m_aapDbConnections[Mode::WRITE_BACKUP].empty())
|
||||
{
|
||||
dbg_msg("sql", "%s skipped to backup database during shutdown", pThreadData->m_pName);
|
||||
break;
|
||||
}
|
||||
if(FailMode && !m_aapDbConnections[Mode::WRITE_BACKUP].empty())
|
||||
{
|
||||
dbg_msg("sql", "%s skipped to backup database during FailMode", pThreadData->m_pName);
|
||||
break;
|
||||
}
|
||||
int CurServer = (WriteServer + i) % (int)m_aapDbConnections[Mode::WRITE].size();
|
||||
if(ExecSqlFunc(m_aapDbConnections[Mode::WRITE][i].get(), pThreadData.get(), false))
|
||||
{
|
||||
|
@ -183,6 +205,10 @@ void CDbConnectionPool::Worker()
|
|||
Success = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
FailMode = true;
|
||||
}
|
||||
}
|
||||
if(!Success)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue