From 701865eca1c8896a913e05f41a748c225b84af11 Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 21 Dec 2023 15:20:03 -0300 Subject: [PATCH] Refactor backupFile() to remove backupCopyResultReCopy. Having two enum values for file copy makes things a bit more complicated than they need to be (especially in an upcoming commit). Instead add a flag to indicate that the repository file was invalid since the only purpose is to trigger a warning message. --- src/command/backup/backup.c | 5 ++++- src/command/backup/file.c | 6 +++--- src/command/backup/file.h | 2 +- src/command/backup/protocol.c | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/command/backup/backup.c b/src/command/backup/backup.c index a9365ac8e..c798f21c5 100644 --- a/src/command/backup/backup.c +++ b/src/command/backup/backup.c @@ -1421,6 +1421,7 @@ backupJobResult( { ManifestFile file = manifestFileFind(manifest, pckReadStrP(jobResult)); const BackupCopyResult copyResult = (BackupCopyResult)pckReadU32P(jobResult); + const bool repoInvalid = pckReadBoolP(jobResult); const uint64_t copySize = pckReadU64P(jobResult); const uint64_t bundleOffset = pckReadU64P(jobResult); const uint64_t blockIncrMapSize = pckReadU64P(jobResult); @@ -1482,8 +1483,10 @@ backupJobResult( // If the file had to be recopied then warn that there may be an issue with corruption in the repository // ??? This should really be below the message below for more context -- can be moved after the migration // ??? The name should be a pg path not manifest name -- can be fixed after the migration - if (copyResult == backupCopyResultReCopy) + if (repoInvalid) { + ASSERT(copyResult == backupCopyResultCopy); + LOG_WARN_FMT( "resumed backup file %s does not have expected checksum %s. The file will be recopied and backup will" " continue but this may be an issue unless the resumed backup path in the repository is known to be" diff --git a/src/command/backup/file.c b/src/command/backup/file.c index 97ff2c7c6..0969cdf38 100644 --- a/src/command/backup/file.c +++ b/src/command/backup/file.c @@ -168,9 +168,9 @@ backupFile( } MEM_CONTEXT_END(); } - // Else recopy when repo file is not as expected + // Else copy when repo file is invalid else - fileResult->backupCopyResult = backupCopyResultReCopy; + fileResult->repoInvalid = true; } } } @@ -192,7 +192,7 @@ backupFile( const BackupFile *const file = lstGet(fileList, fileIdx); BackupFileResult *const fileResult = lstGet(result, fileIdx); - if (fileResult->backupCopyResult == backupCopyResultCopy || fileResult->backupCopyResult == backupCopyResultReCopy) + if (fileResult->backupCopyResult == backupCopyResultCopy) { // Setup pg file for read. Only read as many bytes as passed in pgFileSize. If the file is growing it does no // good to copy data past the end of the size recorded in the manifest since those blocks will need to be diff --git a/src/command/backup/file.h b/src/command/backup/file.h index 68e50fd66..08a0438fe 100644 --- a/src/command/backup/file.h +++ b/src/command/backup/file.h @@ -16,7 +16,6 @@ typedef enum { backupCopyResultChecksum, backupCopyResultCopy, - backupCopyResultReCopy, backupCopyResultSkip, backupCopyResultNoOp, backupCopyResultTruncate, @@ -53,6 +52,7 @@ typedef struct BackupFileResult { const String *manifestFile; // Manifest file BackupCopyResult backupCopyResult; + bool repoInvalid; // File was recopied because repo file was invalid uint64_t copySize; Buffer *copyChecksum; Buffer *repoChecksum; // Checksum repo file (including compression, etc.) diff --git a/src/command/backup/protocol.c b/src/command/backup/protocol.c index 7e0db4b83..5b5cbcd3f 100644 --- a/src/command/backup/protocol.c +++ b/src/command/backup/protocol.c @@ -90,6 +90,7 @@ backupFileProtocol(PackRead *const param, ProtocolServer *const server) pckWriteStrP(resultPack, fileResult->manifestFile); pckWriteU32P(resultPack, fileResult->backupCopyResult); + pckWriteBoolP(resultPack, fileResult->repoInvalid); pckWriteU64P(resultPack, fileResult->copySize); pckWriteU64P(resultPack, fileResult->bundleOffset); pckWriteU64P(resultPack, fileResult->blockIncrMapSize);