summaryrefslogtreecommitdiff
path: root/src/backend/backup/basebackup_incremental.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/backup/basebackup_incremental.c')
-rw-r--r--src/backend/backup/basebackup_incremental.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c
index 2970dfe6031..131598badef 100644
--- a/src/backend/backup/basebackup_incremental.c
+++ b/src/backend/backup/basebackup_incremental.c
@@ -929,6 +929,36 @@ GetFileBackupMethod(IncrementalBackupInfo *ib, const char *path,
}
/*
+ * Compute the size for a header of an incremental file containing a given
+ * number of blocks. The header is rounded to a multiple of BLCKSZ, but
+ * only if the file will store some block data.
+ */
+extern size_t
+GetIncrementalHeaderSize(unsigned num_blocks_required)
+{
+ size_t result;
+
+ /* Make sure we're not going to overflow. */
+ Assert(num_blocks_required <= RELSEG_SIZE);
+
+ /*
+ * Three four byte quantities (magic number, truncation block length,
+ * block count) followed by block numbers.
+ */
+ result = 3 * sizeof(uint32) + (sizeof(BlockNumber) * num_blocks_required);
+
+ /*
+ * Round the header size to a multiple of BLCKSZ - when not a multiple of
+ * BLCKSZ, add the missing fraction of a block. But do this only if the
+ * file will store data for some blocks, otherwise keep it small.
+ */
+ if ((num_blocks_required > 0) && (result % BLCKSZ != 0))
+ result += BLCKSZ - (result % BLCKSZ);
+
+ return result;
+}
+
+/*
* Compute the size for an incremental file containing a given number of blocks.
*/
extern size_t
@@ -940,11 +970,12 @@ GetIncrementalFileSize(unsigned num_blocks_required)
Assert(num_blocks_required <= RELSEG_SIZE);
/*
- * Three four byte quantities (magic number, truncation block length,
- * block count) followed by block numbers followed by block contents.
+ * Header with three four byte quantities (magic number, truncation block
+ * length, block count) followed by block numbers, rounded to a multiple
+ * of BLCKSZ (for files with block data), followed by block contents.
*/
- result = 3 * sizeof(uint32);
- result += (BLCKSZ + sizeof(BlockNumber)) * num_blocks_required;
+ result = GetIncrementalHeaderSize(num_blocks_required);
+ result += BLCKSZ * num_blocks_required;
return result;
}