Merge pull request #9020 from ChillerDragon/pr_dbg_sql

Add ``dbg_sql`` config to hide non error sql logs
This commit is contained in:
Zwelf 2024-11-07 22:28:49 +00:00 committed by GitHub
commit 73357a45dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 10 deletions

View file

@ -1,5 +1,6 @@
#include "connection_pool.h"
#include "connection.h"
#include <engine/shared/config.h>
#include <base/system.h>
#include <cstring>
@ -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;
@ -228,6 +231,7 @@ 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);
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<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
@ -314,6 +320,7 @@ void CWorker::ProcessQueries()
if(CDbConnectionPool::ExecSqlFunc(m_vpReadConnections[CurServer].get(), pThreadData.get(), Write::NORMAL))
{
ReadServer = CurServer;
if(m_DebugSql)
dbg_msg("sql", "[%i] %s done on read database %d", JobNum, pThreadData->m_pName, CurServer);
Success = true;
break;
@ -337,6 +344,7 @@ void CWorker::ProcessQueries()
}
else if(CDbConnectionPool::ExecSqlFunc(m_pWriteConnection.get(), pThreadData.get(), Write::NORMAL))
{
if(m_DebugSql)
dbg_msg("sql", "[%i] %s done on write database", JobNum, pThreadData->m_pName);
Success = true;
}
@ -345,6 +353,7 @@ void CWorker::ProcessQueries()
const Write w = Success ? Write::NORMAL_SUCCEEDED : Write::NORMAL_FAILED;
if(m_pWriteBackup && CDbConnectionPool::ExecSqlFunc(m_pWriteBackup.get(), pThreadData.get(), w))
{
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<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()

View file

@ -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)")