diff --git a/doc/xml/release/2024/2.51.xml b/doc/xml/release/2024/2.51.xml index ced19c88e..17c9d220e 100644 --- a/doc/xml/release/2024/2.51.xml +++ b/doc/xml/release/2024/2.51.xml @@ -30,6 +30,17 @@ + + + + + + + + +

Improve archive-push WAL segment queue handling.

+
+ diff --git a/src/command/archive/push/push.c b/src/command/archive/push/push.c index 4e29c5610..6f19d2541 100644 --- a/src/command/archive/push/push.c +++ b/src/command/archive/push/push.c @@ -60,37 +60,30 @@ archivePushDropWarning(const String *const walFile, const uint64_t queueMax) Determine if the WAL process list has become large enough to drop ***********************************************************************************************************************************/ static bool -archivePushDrop(const String *walPath, const StringList *const processList) +archivePushDrop(const String *const walPath, const StringList *const processList) { FUNCTION_LOG_BEGIN(logLevelDebug); FUNCTION_LOG_PARAM(STRING, walPath); FUNCTION_LOG_PARAM(STRING_LIST, processList); FUNCTION_LOG_END(); + ASSERT(walPath != NULL); + ASSERT(processList != NULL); + const uint64_t queueMax = cfgOptionUInt64(cfgOptArchivePushQueueMax); uint64_t queueSize = 0; - bool result = false; - MEM_CONTEXT_TEMP_RESET_BEGIN() + MEM_CONTEXT_TEMP_BEGIN() { - for (unsigned int processIdx = 0; processIdx < strLstSize(processList); processIdx++) + if (!strLstEmpty(processList)) { - queueSize += storageInfoP( - storagePg(), strNewFmt("%s/%s", strZ(walPath), strZ(strLstGet(processList, processIdx)))).size; - - if (queueSize > queueMax) - { - result = true; - break; - } - - // Reset the memory context occasionally so we don't use too much memory or slow down processing - MEM_CONTEXT_TEMP_RESET(1000); + queueSize = storageInfoP( + storagePg(), strNewFmt("%s/%s", strZ(walPath), strZ(strLstGet(processList, 0)))).size * strLstSize(processList); } } MEM_CONTEXT_TEMP_END(); - FUNCTION_LOG_RETURN(BOOL, result); + FUNCTION_LOG_RETURN(BOOL, queueSize > queueMax); } /*********************************************************************************************************************************** diff --git a/test/src/module/command/archivePushTest.c b/test/src/module/command/archivePushTest.c index 320f795fe..8eae4fc3b 100644 --- a/test/src/module/command/archivePushTest.c +++ b/test/src/module/command/archivePushTest.c @@ -90,6 +90,9 @@ testRun(void) TEST_RESULT_BOOL( archivePushDrop(STRDEF("pg_wal"), archivePushProcessList(STRDEF(TEST_PATH "/db/pg_wal"))), true, "wal is dropped"); + + // No WAL to be processed + TEST_RESULT_BOOL(archivePushDrop(STRDEF("pg_wal"), strLstNew()), false, "no WAL to be processed"); } // *****************************************************************************************************************************