You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-05 00:28:52 +02:00
Refactor logging functions to never allocate memory.
Allocating memory made these functions simpler but it meant that memory was leaking into the calling context when logging was enabled. It is not clear that this was an issue but it seems that trace level logging could result it a lot of memory usage depending on the use case. This also makes it possible to audit allocations returned to the calling context, which will be done in a followup commit. Also rename objToLog() to objNameToLog() since it seemed logical to name the new function objToLog().
This commit is contained in:
@ -377,10 +377,22 @@ pgClientClose(PgClient *this)
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN String *
|
||||
pgClientToLog(const PgClient *this)
|
||||
FN_EXTERN void
|
||||
pgClientToLog(const PgClient *const this, StringStatic *const debugLog)
|
||||
{
|
||||
return strNewFmt(
|
||||
"{host: %s, port: %u, database: %s, user: %s, queryTimeout %" PRIu64 "}", strZ(strToLog(pgClientHost(this))),
|
||||
pgClientPort(this), strZ(strToLog(pgClientDatabase(this))), strZ(strToLog(pgClientUser(this))), pgClientTimeout(this));
|
||||
strStcCat(debugLog, "{host: ");
|
||||
strStcResultSizeInc(
|
||||
debugLog,
|
||||
FUNCTION_LOG_OBJECT_FORMAT(pgClientHost(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
|
||||
|
||||
strStcCat(debugLog, ", database: ");
|
||||
strToLog(pgClientDatabase(this), debugLog);
|
||||
|
||||
strStcCat(debugLog, ", user: ");
|
||||
strStcResultSizeInc(
|
||||
debugLog,
|
||||
FUNCTION_LOG_OBJECT_FORMAT(pgClientUser(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
|
||||
|
||||
strStcFmt(
|
||||
debugLog, ", port: %u, queryTimeout %" PRIu64 "}", pgClientPort(this), pgClientTimeout(this));
|
||||
}
|
||||
|
@ -113,11 +113,11 @@ pgClientFree(PgClient *const this)
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
***********************************************************************************************************************************/
|
||||
FN_EXTERN String *pgClientToLog(const PgClient *this);
|
||||
FN_EXTERN void pgClientToLog(const PgClient *this, StringStatic *debugLog);
|
||||
|
||||
#define FUNCTION_LOG_PG_CLIENT_TYPE \
|
||||
PgClient *
|
||||
#define FUNCTION_LOG_PG_CLIENT_FORMAT(value, buffer, bufferSize) \
|
||||
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pgClientToLog, buffer, bufferSize)
|
||||
FUNCTION_LOG_OBJECT_FORMAT(value, pgClientToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -556,16 +556,16 @@ pgVersionToStr(unsigned int version)
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN String *
|
||||
pgControlToLog(const PgControl *pgControl)
|
||||
FN_EXTERN void
|
||||
pgControlToLog(const PgControl *const pgControl, StringStatic *const debugLog)
|
||||
{
|
||||
return strNewFmt(
|
||||
"{version: %u, systemId: %" PRIu64 ", walSegmentSize: %u, pageChecksum: %s}", pgControl->version, pgControl->systemId,
|
||||
pgControl->walSegmentSize, cvtBoolToConstZ(pgControl->pageChecksum));
|
||||
strStcFmt(
|
||||
debugLog, "{version: %u, systemId: %" PRIu64 ", walSegmentSize: %u, pageChecksum: %s}", pgControl->version,
|
||||
pgControl->systemId, pgControl->walSegmentSize, cvtBoolToConstZ(pgControl->pageChecksum));
|
||||
}
|
||||
|
||||
FN_EXTERN String *
|
||||
pgWalToLog(const PgWal *pgWal)
|
||||
FN_EXTERN void
|
||||
pgWalToLog(const PgWal *const pgWal, StringStatic *const debugLog)
|
||||
{
|
||||
return strNewFmt("{version: %u, systemId: %" PRIu64 "}", pgWal->version, pgWal->systemId);
|
||||
strStcFmt(debugLog, "{version: %u, systemId: %" PRIu64 "}", pgWal->version, pgWal->systemId);
|
||||
}
|
||||
|
@ -177,17 +177,17 @@ FN_EXTERN const String *pgXactPath(unsigned int pgVersion);
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
***********************************************************************************************************************************/
|
||||
FN_EXTERN String *pgControlToLog(const PgControl *pgControl);
|
||||
FN_EXTERN String *pgWalToLog(const PgWal *pgWal);
|
||||
FN_EXTERN void pgControlToLog(const PgControl *pgControl, StringStatic *debugLog);
|
||||
FN_EXTERN void pgWalToLog(const PgWal *pgWal, StringStatic *debugLog);
|
||||
|
||||
#define FUNCTION_LOG_PG_CONTROL_TYPE \
|
||||
PgControl
|
||||
#define FUNCTION_LOG_PG_CONTROL_FORMAT(value, buffer, bufferSize) \
|
||||
FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, pgControlToLog, buffer, bufferSize)
|
||||
FUNCTION_LOG_OBJECT_FORMAT(&value, pgControlToLog, buffer, bufferSize)
|
||||
|
||||
#define FUNCTION_LOG_PG_WAL_TYPE \
|
||||
PgWal
|
||||
#define FUNCTION_LOG_PG_WAL_FORMAT(value, buffer, bufferSize) \
|
||||
FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, pgWalToLog, buffer, bufferSize)
|
||||
FUNCTION_LOG_OBJECT_FORMAT(&value, pgWalToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user