db: log SQL worker shutdown state
This commit is contained in:
@@ -4,6 +4,26 @@
|
||||
|
||||
extern std::string g_stLocale;
|
||||
|
||||
namespace
|
||||
{
|
||||
const char* SQLSlotName(int slot)
|
||||
{
|
||||
switch (slot)
|
||||
{
|
||||
case SQL_PLAYER:
|
||||
return "player";
|
||||
case SQL_ACCOUNT:
|
||||
return "account";
|
||||
case SQL_COMMON:
|
||||
return "common";
|
||||
case SQL_HOTBACKUP:
|
||||
return "hotbackup";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CDBManager::CDBManager()
|
||||
{
|
||||
Initialize();
|
||||
@@ -45,6 +65,16 @@ void CDBManager::Quit()
|
||||
{
|
||||
for (int i = 0; i < SQL_MAX_NUM; ++i)
|
||||
{
|
||||
sys_log(0,
|
||||
"[SHUTDOWN] DBManager slot=%s begin main_pending=%u main_copied=%u main_results=%u async_pending=%u async_copied=%u async_results=%u",
|
||||
SQLSlotName(i),
|
||||
m_mainSQL[i] ? m_mainSQL[i]->CountQuery() : 0,
|
||||
m_mainSQL[i] ? m_mainSQL[i]->CountCopiedQueryQueue() : 0,
|
||||
m_mainSQL[i] ? m_mainSQL[i]->CountResult() : 0,
|
||||
m_asyncSQL[i] ? m_asyncSQL[i]->CountQuery() : 0,
|
||||
m_asyncSQL[i] ? m_asyncSQL[i]->CountCopiedQueryQueue() : 0,
|
||||
m_asyncSQL[i] ? m_asyncSQL[i]->CountResult() : 0);
|
||||
|
||||
if (m_mainSQL[i])
|
||||
m_mainSQL[i]->Quit();
|
||||
|
||||
@@ -53,6 +83,8 @@ void CDBManager::Quit()
|
||||
|
||||
if (m_directSQL[i])
|
||||
m_directSQL[i]->Quit();
|
||||
|
||||
sys_log(0, "[SHUTDOWN] DBManager slot=%s done", SQLSlotName(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,4 +214,3 @@ void CDBManager::QueryLocaleSet()
|
||||
m_asyncSQL[n]->QueryLocaleSet();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,9 @@ int main()
|
||||
|
||||
signal_timer_disable();
|
||||
|
||||
sys_log(0, "[SHUTDOWN] DB main loop finished, quitting SQL workers");
|
||||
DBManager.Quit();
|
||||
sys_log(0, "[SHUTDOWN] DB SQL workers stopped");
|
||||
int iCount;
|
||||
|
||||
while (1)
|
||||
@@ -260,6 +262,8 @@ int main()
|
||||
sys_log(0, "WAITING_QUERY_COUNT %d", iCount);
|
||||
}
|
||||
|
||||
sys_log(0, "[SHUTDOWN] DB process exiting cleanly");
|
||||
|
||||
log_destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -138,6 +138,16 @@ bool CAsyncSQL::Setup(const char* c_pszHost, const char* c_pszUser, const char*
|
||||
|
||||
void CAsyncSQL::Quit()
|
||||
{
|
||||
sys_log(0,
|
||||
"[SHUTDOWN] AsyncSQL quit begin db=%s host=%s worker=%s pending=%u copied=%u results=%u connected=%d",
|
||||
m_stDB.c_str(),
|
||||
m_stHost.c_str(),
|
||||
HasWorkerThread() ? "yes" : "no",
|
||||
CountQuery(),
|
||||
CountCopiedQueryQueue(),
|
||||
CountResult(),
|
||||
IsConnected() ? 1 : 0);
|
||||
|
||||
m_bEnd.store(true, std::memory_order_release);
|
||||
m_cvQuery.notify_all();
|
||||
|
||||
@@ -146,6 +156,14 @@ void CAsyncSQL::Quit()
|
||||
m_thread->join();
|
||||
m_thread.reset();
|
||||
}
|
||||
|
||||
sys_log(0,
|
||||
"[SHUTDOWN] AsyncSQL quit done db=%s host=%s pending=%u copied=%u results=%u",
|
||||
m_stDB.c_str(),
|
||||
m_stHost.c_str(),
|
||||
CountQuery(),
|
||||
CountCopiedQueryQueue(),
|
||||
CountResult());
|
||||
}
|
||||
|
||||
std::unique_ptr<SQLMsg> CAsyncSQL::DirectQuery(const char* c_pszQuery)
|
||||
@@ -323,6 +341,17 @@ DWORD CAsyncSQL::CountResult()
|
||||
return static_cast<DWORD>(m_queue_result.size());
|
||||
}
|
||||
|
||||
DWORD CAsyncSQL::CountCopiedQueryQueue()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mtxQuery);
|
||||
return static_cast<DWORD>(m_queue_query_copy.size());
|
||||
}
|
||||
|
||||
bool CAsyncSQL::HasWorkerThread() const
|
||||
{
|
||||
return m_thread && m_thread->joinable();
|
||||
}
|
||||
|
||||
// Modern profiler using chrono
|
||||
class cProfiler
|
||||
{
|
||||
@@ -528,6 +557,15 @@ void CAsyncSQL::ChildLoop()
|
||||
m_iQueryFinished.fetch_add(1, std::memory_order_acq_rel);
|
||||
}
|
||||
}
|
||||
|
||||
sys_log(0,
|
||||
"[SHUTDOWN] AsyncSQL worker exit db=%s host=%s pending=%u copied=%u results=%u finished=%d",
|
||||
m_stDB.c_str(),
|
||||
m_stHost.c_str(),
|
||||
CountQuery(),
|
||||
CountCopiedQueryQueue(),
|
||||
CountResult(),
|
||||
CountQueryFinished());
|
||||
}
|
||||
|
||||
int CAsyncSQL::CountQueryFinished() const
|
||||
|
||||
@@ -175,6 +175,8 @@ class CAsyncSQL
|
||||
|
||||
DWORD CountQuery();
|
||||
DWORD CountResult();
|
||||
DWORD CountCopiedQueryQueue();
|
||||
bool HasWorkerThread() const;
|
||||
|
||||
void PushResult(std::unique_ptr<SQLMsg> p);
|
||||
bool PopResult(std::unique_ptr<SQLMsg>& p);
|
||||
|
||||
Reference in New Issue
Block a user