1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Improve efficiency of incremental manifest build.

Move the file.copy check before the manifest lookup to save a lookup and (probably) find for zero-length files when bundling.

This also removes a layer of indentation which helps with readability.
This commit is contained in:
David Steele
2024-06-08 13:00:53 +10:00
parent 48823b6cd3
commit cf478bc753

View File

@ -1686,35 +1686,32 @@ manifestBuildIncr(
{ {
ManifestFile file = manifestFile(this, fileIdx); ManifestFile file = manifestFile(this, fileIdx);
// Check if a prior file exists // Check if a prior file exists for files that will be copied (i.e. not zero-length files when bundling). If a prior
if (manifestFileExists(manifestPrior, file.name)) // file does exist it may be possible to reference it instead of copying the file.
if (file.copy && manifestFileExists(manifestPrior, file.name))
{ {
const ManifestFile filePrior = manifestFileFind(manifestPrior, file.name); const ManifestFile filePrior = manifestFileFind(manifestPrior, file.name);
// If the file will be copied then preserve values from the prior file when needed. Some files may have been // If file size is equal to prior size then the file can be referenced instead of copied if it has not changed (this
// designated not to be copied at manifest build time, e.g. zero-length files when bundling. // must be determined during the backup).
if (file.copy)
{
// If file size is equal to prior size then the file can be referenced instead of copied if it has not changed
// (this must be determined during the backup).
const bool fileSizeEqual = file.size == filePrior.size; const bool fileSizeEqual = file.size == filePrior.size;
// If prior file was stored with block incremental and file size is at least prior file block size then preserve // If prior file was stored with block incremental and file size is at least prior file block size then preserve
// prior values. If file size is less than prior file block size then the entire file will need to be stored and // prior values. If file size is less than prior file block size then the entire file will need to be stored and the
// the map will be useless as long as the file stays at this size. It is not possible to change the block size // map will be useless as long as the file stays at this size. It is not possible to change the block size in a
// in a backup set and the map info will be required to compare against the prior block incremental. // backup set and the map info will be required to compare against the prior block incremental.
const bool fileBlockIncrPreserve = filePrior.blockIncrMapSize > 0 && file.size >= filePrior.blockIncrSize; const bool fileBlockIncrPreserve = filePrior.blockIncrMapSize > 0 && file.size >= filePrior.blockIncrSize;
// Perform delta if enabled and file size is equal to prior but not zero. Files of unequal length are always // Perform delta if enabled and file size is equal to prior but not zero. Files of unequal length are always
// different while zero-length files are always the same, so it wastes time to check them. It is possible for // different while zero-length files are always the same, so it wastes time to check them. It is possible for a file
// a file to be truncated down to equal the prior file during backup, but the overhead of checking for such an // to be truncated down to equal the prior file during backup, but the overhead of checking for such an unlikely
// unlikely event does not seem worth the possible space saved. // event does not seem worth the possible space saved.
file.delta = delta && fileSizeEqual && file.size != 0; file.delta = delta && fileSizeEqual && file.size != 0;
// Do not copy if size and prior size are both zero. Zero-length files are always equal so the file can simply // Do not copy if size and prior size are both zero. Zero-length files are always equal so the file can simply be
// be referenced to the prior file. Note that this is only for the case where zero-length files are being // referenced to the prior file. Note that this is only for the case where zero-length files are being explicitly
// explicitly written to the repo. Bundled zero-length files disable copy at manifest build time and never // written to the repo. Bundled zero-length files disable copy at manifest build time and never reference the prior
// reference the prior file, even if it is also zero-length. // file, even if it is also zero-length.
if (file.size == 0 && filePrior.size == 0) if (file.size == 0 && filePrior.size == 0)
file.copy = false; file.copy = false;
@ -1726,9 +1723,9 @@ manifestBuildIncr(
ASSERT(file.copy || fileSizeEqual); ASSERT(file.copy || fileSizeEqual);
ASSERT(!file.delta || fileSizeEqual); ASSERT(!file.delta || fileSizeEqual);
// Preserve values if the file will not be copied, is possibly equal to the prior file, or will be stored with // Preserve values if the file will not be copied, is possibly equal to the prior file, or will be stored with block
// block incremental and the prior file is also stored with block incremental. If the file will not be copied // incremental and the prior file is also stored with block incremental. If the file will not be copied then the
// then the file size must be equal to the prior file so there is no need to check that condition separately. // file size must be equal to the prior file so there is no need to check that condition separately.
if (fileSizeEqual || fileBlockIncrPreserve) if (fileSizeEqual || fileBlockIncrPreserve)
{ {
file.sizePrior = filePrior.size; file.sizePrior = filePrior.size;
@ -1762,7 +1759,6 @@ manifestBuildIncr(
} }
} }
} }
}
MEM_CONTEXT_TEMP_END(); MEM_CONTEXT_TEMP_END();
FUNCTION_LOG_RETURN_VOID(); FUNCTION_LOG_RETURN_VOID();