1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Refactor skip files truncated during backup when bundling.

Refactor 02eea555 to always close the file immediately on EOF and use backupCopyResultCopy to continue processing. Closing the file immediately saves a later EOF check and is friendlier to added logic in this area. Using backupCopyResultCopy to continue is clearer also makes it easier to add new logic.

Also store zero checksum so the bulk of results collection can be moved within the copy block.
This commit is contained in:
David Steele 2023-12-22 13:16:45 -03:00
parent c8795094d4
commit 9049fec2c0
2 changed files with 31 additions and 19 deletions

View File

@ -42,6 +42,7 @@
<github-pull-request id="2227"/>
</commit>
<commit subject="Allow const checksum buffers to be returned from backupFile()."/>
<commit subject="Refactor skip files truncated during backup when bundling."/>
<release-item-contributor-list>
<release-item-contributor id="georgy.shelkovy"/>

View File

@ -305,19 +305,33 @@ backupFile(
// bundling is enabled as otherwise the file will be stored anyway.
ioRead(readIo, buffer);
if (ioReadEof(readIo) && bundleId != 0)
if (ioReadEof(readIo))
{
// Close the source and set eof
ioReadClose(readIo);
readEof = true;
// If the file is zero-length then it was truncated during the backup
if (pckReadU64P(ioFilterGroupResultP(ioReadFilterGroup(readIo), SIZE_FILTER_TYPE, .idx = 0)) == 0)
// Get file size
fileResult->copySize = pckReadU64P(
ioFilterGroupResultP(ioReadFilterGroup(readIo), SIZE_FILTER_TYPE, .idx = 0));
// If file is zero-length then it was truncated during the backup. When bundling we can simply mark it
// as truncated since no file needs to be stored.
if (bundleId != 0 && fileResult->copySize == 0)
{
fileResult->backupCopyResult = backupCopyResultTruncate;
fileResult->copyChecksum = HASH_TYPE_SHA1_ZERO_BUF;
ASSERT(
bufEq(
fileResult->copyChecksum,
pckReadBinP(
ioFilterGroupResultP(ioReadFilterGroup(readIo), CRYPTO_HASH_FILTER_TYPE, .idx = 0))));
}
}
// Copy the file in non-bundling mode or if the file is not zero-length
if (fileResult->backupCopyResult != backupCopyResultTruncate)
// Copy the file
if (fileResult->backupCopyResult == backupCopyResultCopy)
{
// Setup the repo file for write. There is no need to write the file atomically (e.g. via a temp file on
// Posix) because checksums are tested on resume after a failed backup. The path does not need to be
@ -348,19 +362,16 @@ backupFile(
// Close the source
ioReadClose(readIo);
}
}
MEM_CONTEXT_BEGIN(lstMemContext(result))
{
// Get size and checksum
fileResult->copySize = pckReadU64P(
ioFilterGroupResultP(ioReadFilterGroup(readIo), SIZE_FILTER_TYPE, .idx = 0));
fileResult->copyChecksum = pckReadBinP(
ioFilterGroupResultP(ioReadFilterGroup(readIo), CRYPTO_HASH_FILTER_TYPE, .idx = 0));
// If the file is not bundled or not zero-length then it was copied
if (fileResult->backupCopyResult != backupCopyResultTruncate)
// Get copy results
MEM_CONTEXT_BEGIN(lstMemContext(result))
{
// Get size and checksum
fileResult->copySize = pckReadU64P(
ioFilterGroupResultP(ioReadFilterGroup(readIo), SIZE_FILTER_TYPE, .idx = 0));
fileResult->copyChecksum = pckReadBinP(
ioFilterGroupResultP(ioReadFilterGroup(readIo), CRYPTO_HASH_FILTER_TYPE, .idx = 0));
// Get bundle offset
fileResult->bundleOffset = bundleOffset;
@ -389,10 +400,10 @@ backupFile(
ioFilterGroupResultP(ioReadFilterGroup(readIo), CRYPTO_HASH_FILTER_TYPE, .idx = 1));
}
}
}
MEM_CONTEXT_END();
MEM_CONTEXT_END();
bundleOffset += fileResult->repoSize;
bundleOffset += fileResult->repoSize;
}
}
// Else if source file is missing and the read setup indicated ignore a missing file, the database removed it so
// skip it