Skip to content

Commit 0b16fc0

Browse files
committed
[Issue #169] fix merge of 0 sized files
1 parent 2d3f19e commit 0b16fc0

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/data.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
646646
if (file->pagemap.bitmapsize == PageBitmapIsEmpty ||
647647
file->pagemap_isabsent || !file->exists_in_prev)
648648
{
649+
/* remote FULL and DELTA */
649650
if (fio_is_remote_file(in))
650651
{
651652
int rc = fio_send_pages(in, out, file,
@@ -669,6 +670,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
669670
}
670671
else
671672
{
673+
/* local FULL and DELTA */
672674
RetryUsingPtrack:
673675
for (blknum = 0; blknum < nblocks; blknum++)
674676
{
@@ -689,7 +691,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
689691
page_state, curr_page, calg, clevel,
690692
from_fullpath, to_fullpath);
691693
else
692-
elog(ERROR, "Illegal page state: %i, file: %s, blknum %i",
694+
elog(ERROR, "Invalid page state: %i, file: %s, blknum %i",
693695
page_state, file->rel_path, blknum);
694696

695697
n_blocks_read++;
@@ -718,6 +720,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
718720
if (page_state == PageIsTruncated)
719721
break;
720722

723+
/* TODO: PAGE and PTRACK should never get SkipCurrentPage */
721724
else if (page_state == SkipCurrentPage)
722725
n_blocks_skipped++;
723726

@@ -726,7 +729,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
726729
page_state, curr_page, calg, clevel,
727730
from_fullpath, to_fullpath);
728731
else
729-
elog(ERROR, "Illegal page state: %i, file: %s, blknum %i",
732+
elog(ERROR, "Invalid page state: %i, file: %s, blknum %i",
730733
page_state, file->rel_path, blknum);
731734

732735
n_blocks_read++;

src/merge.c

+18-4
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ merge_files(void *arg)
849849
goto done;
850850

851851
if (progress)
852-
elog(INFO, "Progress: (%d/%lu). Process file \"%s\"",
852+
elog(INFO, "Progress: (%d/%lu). Merging file \"%s\"",
853853
i + 1, (unsigned long) parray_num(arguments->dest_backup->files), dest_file->rel_path);
854854

855855
if (dest_file->is_datafile && !dest_file->is_cfs)
@@ -1111,14 +1111,28 @@ merge_data_file(parray *parent_chain, pgBackup *full_backup,
11111111
dest_backup->compress_alg, dest_backup->compress_level,
11121112
dest_backup->checksum_version, 0, NULL, false);
11131113

1114+
/* drop restored temp file */
1115+
if (unlink(to_fullpath_tmp1) == -1)
1116+
elog(ERROR, "Cannot remove file \"%s\": %s", to_fullpath_tmp1,
1117+
strerror(errno));
1118+
11141119
/*
11151120
* In old (=<2.2.7) versions of pg_probackup n_blocks attribute of files
11161121
* in PAGE and PTRACK wasn`t filled.
11171122
*/
1118-
// Assert(tmp_file->n_blocks == dest_file->n_blocks);
1123+
//Assert(tmp_file->n_blocks == dest_file->n_blocks);
1124+
1125+
/* Backward compatibility kludge:
1126+
* When merging old backups, it is possible that
1127+
* to_fullpath_tmp2 size will be 0, and so it will be
1128+
* truncated in backup_data_file().
1129+
* TODO: remove in 3.0.0
1130+
*/
1131+
if (tmp_file->write_size == 0)
1132+
return;
11191133

11201134
if (fio_sync(to_fullpath_tmp2, FIO_BACKUP_HOST) != 0)
1121-
elog(ERROR, "Cannot fsync merge temp file \"%s\": %s",
1135+
elog(ERROR, "Cannot sync merge temp file \"%s\": %s",
11221136
to_fullpath_tmp2, strerror(errno));
11231137

11241138
/* Do atomic rename from second temp file to destination file */
@@ -1223,7 +1237,7 @@ merge_non_data_file(parray *parent_chain, pgBackup *full_backup,
12231237

12241238
/* TODO: --no-sync support */
12251239
if (fio_sync(to_fullpath_tmp, FIO_BACKUP_HOST) != 0)
1226-
elog(ERROR, "Cannot fsync merge temp file \"%s\": %s",
1240+
elog(ERROR, "Cannot sync merge temp file \"%s\": %s",
12271241
to_fullpath_tmp, strerror(errno));
12281242

12291243
/* Do atomic rename from second temp file to destination file */

0 commit comments

Comments
 (0)