Skip to content

Commit c6c6053

Browse files
committed
[Issue #159] pgdata_bytes for FULL and DELTA remote backups was calculated incorrectly
1 parent 1f4dc1b commit c6c6053

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/backup.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo)
155155

156156
/* for fancy reporting */
157157
time_t start_time, end_time;
158+
char pretty_bytes[20];
158159

159160
elog(LOG, "Database backup start");
160161
if(current.external_dir_str)
@@ -330,6 +331,20 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo)
330331
elog(ERROR, "PGDATA is almost empty. Either it was concurrently deleted or "
331332
"pg_probackup do not possess sufficient permissions to list PGDATA content");
332333

334+
/* Calculate pgdata_bytes */
335+
for (i = 0; i < parray_num(backup_files_list); i++)
336+
{
337+
pgFile *file = (pgFile *) parray_get(backup_files_list, i);
338+
339+
if (file->external_dir_num != 0)
340+
continue;
341+
342+
current.pgdata_bytes += file->size;
343+
}
344+
345+
pretty_size(current.pgdata_bytes, pretty_bytes, lengthof(pretty_bytes));
346+
elog(INFO, "PGDATA size: %s", pretty_bytes);
347+
333348
/*
334349
* Sort pathname ascending. It is necessary to create intermediate
335350
* directories sequentially.
@@ -547,22 +562,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo)
547562
/* close ssh session in main thread */
548563
fio_disconnect();
549564

550-
/* Calculate pgdata_bytes */
551-
for (i = 0; i < parray_num(backup_files_list); i++)
552-
{
553-
pgFile *file = (pgFile *) parray_get(backup_files_list, i);
554-
555-
/* In case of FULL or DELTA backup we can trust read_size.
556-
* In case of PAGE or PTRACK we are forced to trust datafile size,
557-
* taken at the start of backup.
558-
*/
559-
if (current.backup_mode == BACKUP_MODE_FULL ||
560-
current.backup_mode == BACKUP_MODE_DIFF_DELTA)
561-
current.pgdata_bytes += file->read_size;
562-
else
563-
current.pgdata_bytes += file->size;
564-
}
565-
566565
/* Add archived xlog files into the list of files of this backup */
567566
if (stream_wal)
568567
{
@@ -699,9 +698,9 @@ int
699698
do_backup(time_t start_time, bool no_validate,
700699
pgSetBackupParams *set_backup_params)
701700
{
702-
PGconn *backup_conn = NULL;
703-
PGNodeInfo nodeInfo;
704-
char pretty_data_bytes[20];
701+
PGconn *backup_conn = NULL;
702+
PGNodeInfo nodeInfo;
703+
char pretty_bytes[20];
705704

706705
/* Initialize PGInfonode */
707706
pgNodeInit(&nodeInfo);
@@ -836,10 +835,10 @@ do_backup(time_t start_time, bool no_validate,
836835

837836
/* Notify user about backup size */
838837
if (current.stream)
839-
pretty_size(current.data_bytes + current.wal_bytes, pretty_data_bytes, lengthof(pretty_data_bytes));
838+
pretty_size(current.data_bytes + current.wal_bytes, pretty_bytes, lengthof(pretty_bytes));
840839
else
841-
pretty_size(current.data_bytes, pretty_data_bytes, lengthof(pretty_data_bytes));
842-
elog(INFO, "Backup %s resident size: %s", base36enc(current.start_time), pretty_data_bytes);
840+
pretty_size(current.data_bytes, pretty_bytes, lengthof(pretty_bytes));
841+
elog(INFO, "Backup %s resident size: %s", base36enc(current.start_time), pretty_bytes);
843842

844843
if (current.status == BACKUP_STATUS_OK ||
845844
current.status == BACKUP_STATUS_DONE)

src/data.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ compress_and_backup_page(pgFile *file, BlockNumber blknum,
453453
char write_buffer[BLCKSZ+sizeof(header)];
454454
char compressed_page[BLCKSZ*2]; /* compressed page may require more space than uncompressed */
455455

456-
if(page_state == SkipCurrentPage)
456+
if (page_state == SkipCurrentPage)
457457
return;
458458

459459
header.block = blknum;
@@ -641,6 +641,7 @@ backup_data_file(backup_files_arg* arguments,
641641
file->path, rc == PAGE_CHECKSUM_MISMATCH ? "data file checksum mismatch" : strerror(-rc));
642642
n_blocks_read = rc;
643643

644+
file->read_size = n_blocks_read * BLCKSZ;
644645
file->uncompressed_size = (n_blocks_read - n_blocks_skipped)*BLCKSZ;
645646
}
646647
else
@@ -658,6 +659,8 @@ backup_data_file(backup_files_arg* arguments,
658659
n_blocks_read++;
659660
if (page_state == PageIsTruncated)
660661
break;
662+
663+
file->read_size += BLCKSZ;
661664
}
662665
}
663666
if (backup_mode == BACKUP_MODE_DIFF_DELTA)

src/utils/file.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,6 @@ int fio_send_pages(FILE* in, FILE* out, pgFile *file,
12361236
blknum += 1;
12371237
break;
12381238
}
1239-
file->read_size += BLCKSZ;
12401239
}
12411240
*nBlocksSkipped = blknum - n_blocks_read;
12421241
return blknum;

0 commit comments

Comments
 (0)