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="Remove restore default repo from integration tests."/>
<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 id="cynthia.shang"/>

View File

@ -17,7 +17,7 @@ Archive Push File
#include "storage/helper.h"
/**********************************************************************************************************************************/
String *
ArchivePushFileResult
archivePushFile(
const String *walSource, unsigned int pgVersion, uint64_t pgSystemId, const String *archiveFile, CompressType compressType,
int compressLevel, const ArchivePushFileRepoData *repoData)
@ -36,7 +36,7 @@ archivePushFile(
ASSERT(archiveFile != NULL);
ASSERT(repoData != NULL);
String *result = NULL;
ArchivePushFileResult result = {.warnList = strLstNew()};
MEM_CONTEXT_TEMP_BEGIN()
{
@ -99,18 +99,13 @@ archivePushFile(
{
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
strCatFmt(
result,
"WAL file '%s' already exists in the repo%u archive with the same checksum"
strLstAdd(
result.warnList,
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.",
strZ(archiveFile), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx));
strZ(archiveFile), cfgOptionGroupIdxToKey(cfgOptGrpRepo, repoIdx)));
}
MEM_CONTEXT_PRIOR_END();
@ -218,5 +213,5 @@ archivePushFile(
}
MEM_CONTEXT_TEMP_END();
FUNCTION_LOG_RETURN(STRING, result);
FUNCTION_LOG_RETURN_STRUCT(result);
}

View File

@ -23,8 +23,13 @@ typedef struct ArchivePushFileRepoData
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
typedef struct ArchivePushFileResult
{
StringList *warnList; // Warnings from a successful operation
} ArchivePushFileResult;
// 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,
int compressLevel, const ArchivePushFileRepoData *repoData);

View File

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

View File

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

View File

@ -449,8 +449,8 @@ testRun(void)
archivePushProtocol(PROTOCOL_COMMAND_ARCHIVE_PUSH_STR, paramList, server), true, "protocol archive put");
TEST_RESULT_STR_Z(
strNewBuf(serverWrite),
"{\"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",
"{\"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",
"check result");
bufUsedSet(serverWrite, 0);
@ -545,7 +545,7 @@ testRun(void)
harnessLogResult(
"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"
" 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"
"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"
"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"
" 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"
"P01 DETAIL: pushed WAL file '000000010000000100000002' to the archive");