diff --git a/src/engine/server/databases/connection_pool.cpp b/src/engine/server/databases/connection_pool.cpp index 2d8f607d9..a7056e76c 100644 --- a/src/engine/server/databases/connection_pool.cpp +++ b/src/engine/server/databases/connection_pool.cpp @@ -1,5 +1,6 @@ #include "connection_pool.h" #include "connection.h" +#include #include #include @@ -186,11 +187,13 @@ void CDbConnectionPool::OnShutdown() class CBackup { public: - CBackup(std::shared_ptr pShared) : - m_pShared(std::move(pShared)) {} + CBackup(std::shared_ptr 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 m_pWriteBackup; @@ -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(); } @@ -241,14 +245,16 @@ void CBackup::ProcessQueries() class CWorker { public: - CWorker(std::shared_ptr pShared) : - m_pShared(std::move(pShared)) {} + CWorker(std::shared_ptr 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 @@ -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; } @@ -337,7 +344,8 @@ 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 @@ -345,7 +353,8 @@ void CWorker::ProcessQueries() 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; } } @@ -467,8 +476,8 @@ bool CDbConnectionPool::ExecSqlFunc(IDbConnection *pConnection, CSqlExecData *pD CDbConnectionPool::CDbConnectionPool() { m_pShared = std::make_shared(); - 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() diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index f41e2dfd5..355a4458a 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -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)")