1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Refactor archive-push command warnings to work like archive-get.

Warnings are logged individually in the async log rather than all together.
This commit is contained in:
David Steele 2021-02-26 15:58:11 -05:00
parent 13dc8e68d7
commit a1280c41e5
6 changed files with 41 additions and 33 deletions

View File

@ -56,6 +56,7 @@
<commit subject="Refactor info command repoMin/Max."/> <commit subject="Refactor info command repoMin/Max."/>
<commit subject="Remove restore default repo from integration tests."/> <commit subject="Remove restore default repo from integration tests."/>
<commit subject="Make --repo optional for backup command."/> <commit subject="Make --repo optional for backup command."/>
<commit subject="Refactor archive-push command warnings to work like archive-get."/>
<release-item-contributor-list> <release-item-contributor-list>
<release-item-contributor id="cynthia.shang"/> <release-item-contributor id="cynthia.shang"/>

View File

@ -17,7 +17,7 @@ Archive Push File
#include "storage/helper.h" #include "storage/helper.h"
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
String * ArchivePushFileResult
archivePushFile( archivePushFile(
const String *walSource, unsigned int pgVersion, uint64_t pgSystemId, const String *archiveFile, CompressType compressType, const String *walSource, unsigned int pgVersion, uint64_t pgSystemId, const String *archiveFile, CompressType compressType,
int compressLevel, const ArchivePushFileRepoData *repoData) int compressLevel, const ArchivePushFileRepoData *repoData)
@ -36,7 +36,7 @@ archivePushFile(
ASSERT(archiveFile != NULL); ASSERT(archiveFile != NULL);
ASSERT(repoData != NULL); ASSERT(repoData != NULL);
String *result = NULL; ArchivePushFileResult result = {.warnList = strLstNew()};
MEM_CONTEXT_TEMP_BEGIN() MEM_CONTEXT_TEMP_BEGIN()
{ {
@ -99,18 +99,13 @@ archivePushFile(
{ {
MEM_CONTEXT_PRIOR_BEGIN() MEM_CONTEXT_PRIOR_BEGIN()
{ {
// Add LF if there has already been a warning
if (result == NULL)
result = strNew("");
else
strCatZ(result, "\n");
// Add warning to the result that will be returned to the main process // Add warning to the result that will be returned to the main process
strCatFmt( strLstAdd(
result, result.warnList,
"WAL file '%s' already exists in the repo%u archive with the same checksum" strNewFmt(
"WAL file '%s' already exists in the repo%u archive with the same checksum"
"\nHINT: this is valid in some recovery scenarios but may also indicate a problem.", "\nHINT: this is valid in some recovery scenarios but may also indicate a problem.",
strZ(archiveFile), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)); strZ(archiveFile), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)));
} }
MEM_CONTEXT_PRIOR_END(); MEM_CONTEXT_PRIOR_END();
@ -218,5 +213,5 @@ archivePushFile(
} }
MEM_CONTEXT_TEMP_END(); MEM_CONTEXT_TEMP_END();
FUNCTION_LOG_RETURN(STRING, result); FUNCTION_LOG_RETURN_STRUCT(result);
} }

View File

@ -23,8 +23,13 @@ typedef struct ArchivePushFileRepoData
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct ArchivePushFileResult
{
StringList *warnList; // Warnings from a successful operation
} ArchivePushFileResult;
// Copy a file from the source to the archive // Copy a file from the source to the archive
String *archivePushFile( ArchivePushFileResult archivePushFile(
const String *walSource, unsigned int pgVersion, uint64_t pgSystemId, const String *archiveFile, CompressType compressType, const String *walSource, unsigned int pgVersion, uint64_t pgSystemId, const String *archiveFile, CompressType compressType,
int compressLevel, const ArchivePushFileRepoData *repoData); int compressLevel, const ArchivePushFileRepoData *repoData);

View File

@ -54,13 +54,16 @@ archivePushProtocol(const String *command, const VariantList *paramList, Protoco
} }
// Push the file // Push the file
protocolServerResponse( ArchivePushFileResult fileResult = archivePushFile(
server, varStr(varLstGet(paramList, 0)), varUIntForce(varLstGet(paramList, 1)), varUInt64(varLstGet(paramList, 2)),
VARSTR( varStr(varLstGet(paramList, 3)), (CompressType)varUIntForce(varLstGet(paramList, 4)),
archivePushFile( varIntForce(varLstGet(paramList, 5)), repoData);
varStr(varLstGet(paramList, 0)), varUIntForce(varLstGet(paramList, 1)), varUInt64(varLstGet(paramList, 2)),
varStr(varLstGet(paramList, 3)), (CompressType)varUIntForce(varLstGet(paramList, 4)), // Return result
varIntForce(varLstGet(paramList, 5)), repoData))); VariantList *result = varLstNew();
varLstAdd(result, varNewVarLst(varLstNewStrLst(fileResult.warnList)));
protocolServerResponse(server, varNewVarLst(result));
} }
else else
found = false; found = false;

View File

@ -377,13 +377,13 @@ cmdArchivePush(void)
ArchivePushCheckResult archiveInfo = archivePushCheck(cfgOptionTest(cfgOptPgPath)); ArchivePushCheckResult archiveInfo = archivePushCheck(cfgOptionTest(cfgOptPgPath));
// Push the file to the archive // Push the file to the archive
String *warning = archivePushFile( ArchivePushFileResult fileResult = archivePushFile(
walFile, archiveInfo.pgVersion, archiveInfo.pgSystemId, archiveFile, walFile, archiveInfo.pgVersion, archiveInfo.pgSystemId, archiveFile,
compressTypeEnum(cfgOptionStr(cfgOptCompressType)), cfgOptionInt(cfgOptCompressLevel), archiveInfo.repoData); compressTypeEnum(cfgOptionStr(cfgOptCompressType)), cfgOptionInt(cfgOptCompressLevel), archiveInfo.repoData);
// If a warning was returned then log it // If a warning was returned then log it
if (warning != NULL) for (unsigned int warnIdx = 0; warnIdx < strLstSize(fileResult.warnList); warnIdx++)
LOG_WARN(strZ(warning)); LOG_WARN(strZ(strLstGet(fileResult.warnList, warnIdx)));
// Log success // Log success
LOG_INFO_FMT("pushed WAL file '%s' to the archive", strZ(archiveFile)); LOG_INFO_FMT("pushed WAL file '%s' to the archive", strZ(archiveFile));
@ -531,17 +531,21 @@ cmdArchivePushAsync(void)
// The job was successful // The job was successful
if (protocolParallelJobErrorCode(job) == 0) if (protocolParallelJobErrorCode(job) == 0)
{ {
// If there was a warning then output it to the log // Get job result
const String *warning = varStr(protocolParallelJobResult(job)); const VariantList *fileResult = varVarLst(protocolParallelJobResult(job));
if (warning != NULL) // Output file warnings
LOG_WARN_PID(processId, strZ(warning)); StringList *fileWarnList = strLstNewVarLst(varVarLst(varLstGet(fileResult, 0)));
for (unsigned int warnIdx = 0; warnIdx < strLstSize(fileWarnList); warnIdx++)
LOG_WARN_PID(processId, strZ(strLstGet(fileWarnList, warnIdx)));
// Log success // Log success
LOG_DETAIL_PID_FMT(processId, "pushed WAL file '%s' to the archive", strZ(walFile)); LOG_DETAIL_PID_FMT(processId, "pushed WAL file '%s' to the archive", strZ(walFile));
// Write the status file // Write the status file
archiveAsyncStatusOkWrite(archiveModePush, walFile, warning); archiveAsyncStatusOkWrite(
archiveModePush, walFile, strLstEmpty(fileWarnList) ? NULL : strLstJoin(fileWarnList, "\n"));
} }
// Else the job errored // Else the job errored
else else

View File

@ -449,8 +449,8 @@ testRun(void)
archivePushProtocol(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR, paramList, server), true, "protocol archive put"); archivePushProtocol(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR, paramList, server), true, "protocol archive put");
TEST_RESULT_STR_Z( TEST_RESULT_STR_Z(
strNewBuf(serverWrite), strNewBuf(serverWrite),
"{\"out\":\"WAL file '000000010000000100000002' already exists in the repo1 archive with the same checksum" "{\"out\":[[\"WAL file '000000010000000100000002' already exists in the repo1 archive with the same checksum"
"\\nHINT: this is valid in some recovery scenarios but may also indicate a problem.\"}\n", "\\nHINT: this is valid in some recovery scenarios but may also indicate a problem.\"]]}\n",
"check result"); "check result");
bufUsedSet(serverWrite, 0); bufUsedSet(serverWrite, 0);
@ -545,7 +545,7 @@ testRun(void)
harnessLogResult( harnessLogResult(
"P00 WARN: WAL file '000000010000000100000002' already exists in the repo2 archive with the same checksum\n" "P00 WARN: WAL file '000000010000000100000002' already exists in the repo2 archive with the same checksum\n"
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n" " HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
" WAL file '000000010000000100000002' already exists in the repo3 archive with the same checksum\n" "P00 WARN: WAL file '000000010000000100000002' already exists in the repo3 archive with the same checksum\n"
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n" " HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
"P00 INFO: pushed WAL file '000000010000000100000002' to the archive"); "P00 INFO: pushed WAL file '000000010000000100000002' to the archive");
} }
@ -851,7 +851,7 @@ testRun(void)
"P00 INFO: push 1 WAL file(s) to archive: 000000010000000100000002\n" "P00 INFO: push 1 WAL file(s) to archive: 000000010000000100000002\n"
"P01 WARN: WAL file '000000010000000100000002' already exists in the repo1 archive with the same checksum\n" "P01 WARN: WAL file '000000010000000100000002' already exists in the repo1 archive with the same checksum\n"
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n" " HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
" WAL file '000000010000000100000002' already exists in the repo3 archive with the same checksum\n" "P01 WARN: WAL file '000000010000000100000002' already exists in the repo3 archive with the same checksum\n"
" HINT: this is valid in some recovery scenarios but may also indicate a problem.\n" " HINT: this is valid in some recovery scenarios but may also indicate a problem.\n"
"P01 DETAIL: pushed WAL file '000000010000000100000002' to the archive"); "P01 DETAIL: pushed WAL file '000000010000000100000002' to the archive");