Skip to content

Commit

Permalink
Merge pull request ddnet#9020 from ChillerDragon/pr_dbg_sql
Browse files Browse the repository at this point in the history
Add ``dbg_sql`` config to hide non error sql logs
  • Loading branch information
Zwelf authored Nov 7, 2024
2 parents 5d085ed + 12113c1 commit 73357a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/engine/server/databases/connection_pool.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "connection_pool.h"
#include "connection.h"
#include <engine/shared/config.h>

#include <base/system.h>
#include <cstring>
Expand Down Expand Up @@ -186,11 +187,13 @@ void CDbConnectionPool::OnShutdown()
class CBackup
{
public:
CBackup(std::shared_ptr<CDbConnectionPool::CSharedData> pShared) :
m_pShared(std::move(pShared)) {}
CBackup(std::shared_ptr<CDbConnectionPool::CSharedData> pShared, int DebugSql) :
m_DebugSql(DebugSql), m_pShared(std::move(pShared)) {}
static void Start(void *pUser);

private:
bool m_DebugSql;

void ProcessQueries();

std::unique_ptr<IDbConnection> m_pWriteBackup;
Expand Down Expand Up @@ -228,7 +231,8 @@ void CBackup::ProcessQueries()
else if(pThreadData->m_Mode == CSqlExecData::WRITE_ACCESS && m_pWriteBackup.get())
{
bool Success = CDbConnectionPool::ExecSqlFunc(m_pWriteBackup.get(), pThreadData, Write::BACKUP_FIRST);
dbg_msg("sql", "[%i] %s done on write backup database, Success=%i", JobNum, pThreadData->m_pName, Success);
if(m_DebugSql || !Success)
dbg_msg("sql", "[%i] %s done on write backup database, Success=%i", JobNum, pThreadData->m_pName, Success);
}
m_pShared->m_NumWorker.Signal();
}
Expand All @@ -241,14 +245,16 @@ void CBackup::ProcessQueries()
class CWorker
{
public:
CWorker(std::shared_ptr<CDbConnectionPool::CSharedData> pShared) :
m_pShared(std::move(pShared)) {}
CWorker(std::shared_ptr<CDbConnectionPool::CSharedData> pShared, int DebugSql) :
m_DebugSql(DebugSql), m_pShared(std::move(pShared)) {}
static void Start(void *pUser);
void ProcessQueries();

private:
void Print(IConsole *pConsole, CDbConnectionPool::Mode DatabaseMode);

bool m_DebugSql;

// There are two possible configurations
// * sqlite mode: There exists exactly one READ and the same WRITE server
// with no WRITE_BACKUP server
Expand Down Expand Up @@ -314,7 +320,8 @@ void CWorker::ProcessQueries()
if(CDbConnectionPool::ExecSqlFunc(m_vpReadConnections[CurServer].get(), pThreadData.get(), Write::NORMAL))
{
ReadServer = CurServer;
dbg_msg("sql", "[%i] %s done on read database %d", JobNum, pThreadData->m_pName, CurServer);
if(m_DebugSql)
dbg_msg("sql", "[%i] %s done on read database %d", JobNum, pThreadData->m_pName, CurServer);
Success = true;
break;
}
Expand All @@ -337,15 +344,17 @@ void CWorker::ProcessQueries()
}
else if(CDbConnectionPool::ExecSqlFunc(m_pWriteConnection.get(), pThreadData.get(), Write::NORMAL))
{
dbg_msg("sql", "[%i] %s done on write database", JobNum, pThreadData->m_pName);
if(m_DebugSql)
dbg_msg("sql", "[%i] %s done on write database", JobNum, pThreadData->m_pName);
Success = true;
}
// enter fail mode if not successful
FailMode = FailMode || !Success;
const Write w = Success ? Write::NORMAL_SUCCEEDED : Write::NORMAL_FAILED;
if(m_pWriteBackup && CDbConnectionPool::ExecSqlFunc(m_pWriteBackup.get(), pThreadData.get(), w))
{
dbg_msg("sql", "[%i] %s done move write on backup database to non-backup table", JobNum, pThreadData->m_pName);
if(m_DebugSql)
dbg_msg("sql", "[%i] %s done move write on backup database to non-backup table", JobNum, pThreadData->m_pName);
Success = true;
}
}
Expand Down Expand Up @@ -467,8 +476,8 @@ bool CDbConnectionPool::ExecSqlFunc(IDbConnection *pConnection, CSqlExecData *pD
CDbConnectionPool::CDbConnectionPool()
{
m_pShared = std::make_shared<CSharedData>();
m_pWorkerThread = thread_init(CWorker::Start, new CWorker(m_pShared), "database worker thread");
m_pBackupThread = thread_init(CBackup::Start, new CBackup(m_pShared), "database backup worker thread");
m_pWorkerThread = thread_init(CWorker::Start, new CWorker(m_pShared, g_Config.m_DbgSql), "database worker thread");
m_pBackupThread = thread_init(CBackup::Start, new CBackup(m_pShared, g_Config.m_DbgSql), "database backup worker thread");
}

CDbConnectionPool::~CDbConnectionPool()
Expand Down
1 change: 1 addition & 0 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ MACRO_CONFIG_INT(EcAuthTimeout, ec_auth_timeout, 30, 1, 120, CFGFLAG_ECON, "Time
MACRO_CONFIG_INT(EcOutputLevel, ec_output_level, 0, -3, 2, CFGFLAG_ECON, "Adjusts the amount of information in the external console (-3 = none, -2 = error only, -1 = warn, 0 = info, 1 = debug, 2 = trace)")

MACRO_CONFIG_INT(Debug, debug, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SERVER, "Debug mode")
MACRO_CONFIG_INT(DbgSql, dbg_sql, 1, 0, 1, CFGFLAG_SERVER, "Debug SQL")
MACRO_CONFIG_INT(DbgCurl, dbg_curl, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SERVER, "Debug curl")
MACRO_CONFIG_INT(DbgGraphs, dbg_graphs, 0, 0, 1, CFGFLAG_CLIENT, "Performance graphs")
MACRO_CONFIG_INT(DbgGfx, dbg_gfx, 0, 0, 4, CFGFLAG_CLIENT, "Show graphic library warnings and errors, if the GPU supports it (0: none, 1: minimal, 2: affects performance, 3: verbose, 4: all)")
Expand Down

0 comments on commit 73357a4

Please sign in to comment.