db: log SQL worker shutdown state
Some checks failed
build / Linux asan (push) Has been cancelled
build / Linux release (push) Has been cancelled
build / FreeBSD build (push) Has been cancelled

This commit is contained in:
server
2026-04-14 11:22:30 +02:00
parent 719440575f
commit aa862d829d
4 changed files with 76 additions and 1 deletions

View File

@@ -4,6 +4,26 @@
extern std::string g_stLocale; 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() CDBManager::CDBManager()
{ {
Initialize(); Initialize();
@@ -45,6 +65,16 @@ void CDBManager::Quit()
{ {
for (int i = 0; i < SQL_MAX_NUM; ++i) 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]) if (m_mainSQL[i])
m_mainSQL[i]->Quit(); m_mainSQL[i]->Quit();
@@ -53,6 +83,8 @@ void CDBManager::Quit()
if (m_directSQL[i]) if (m_directSQL[i])
m_directSQL[i]->Quit(); 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(); m_asyncSQL[n]->QueryLocaleSet();
} }
} }

View File

@@ -243,7 +243,9 @@ int main()
signal_timer_disable(); signal_timer_disable();
sys_log(0, "[SHUTDOWN] DB main loop finished, quitting SQL workers");
DBManager.Quit(); DBManager.Quit();
sys_log(0, "[SHUTDOWN] DB SQL workers stopped");
int iCount; int iCount;
while (1) while (1)
@@ -260,6 +262,8 @@ int main()
sys_log(0, "WAITING_QUERY_COUNT %d", iCount); sys_log(0, "WAITING_QUERY_COUNT %d", iCount);
} }
sys_log(0, "[SHUTDOWN] DB process exiting cleanly");
log_destroy(); log_destroy();
return 0; return 0;
} }

View File

@@ -138,6 +138,16 @@ bool CAsyncSQL::Setup(const char* c_pszHost, const char* c_pszUser, const char*
void CAsyncSQL::Quit() 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_bEnd.store(true, std::memory_order_release);
m_cvQuery.notify_all(); m_cvQuery.notify_all();
@@ -146,6 +156,14 @@ void CAsyncSQL::Quit()
m_thread->join(); m_thread->join();
m_thread.reset(); 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) 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()); 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 // Modern profiler using chrono
class cProfiler class cProfiler
{ {
@@ -528,6 +557,15 @@ void CAsyncSQL::ChildLoop()
m_iQueryFinished.fetch_add(1, std::memory_order_acq_rel); 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 int CAsyncSQL::CountQueryFinished() const

View File

@@ -175,6 +175,8 @@ class CAsyncSQL
DWORD CountQuery(); DWORD CountQuery();
DWORD CountResult(); DWORD CountResult();
DWORD CountCopiedQueryQueue();
bool HasWorkerThread() const;
void PushResult(std::unique_ptr<SQLMsg> p); void PushResult(std::unique_ptr<SQLMsg> p);
bool PopResult(std::unique_ptr<SQLMsg>& p); bool PopResult(std::unique_ptr<SQLMsg>& p);