Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f217a14

Browse files
authored
Merge pull request #75 from postgrespro/issue_74
[Issue #74] strict behavior for copy_file and backup_data_file()
2 parents c594704 + db10096 commit f217a14

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

src/backup.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,8 @@ backup_files(void *arg)
24662466
arguments->prev_start_lsn,
24672467
current.backup_mode,
24682468
instance_config.compress_alg,
2469-
instance_config.compress_level))
2469+
instance_config.compress_level,
2470+
true))
24702471
{
24712472
/* disappeared file not to be confused with 'not changed' */
24722473
if (file->write_size != FILE_NOT_FOUND)
@@ -2508,7 +2509,7 @@ backup_files(void *arg)
25082509
else
25092510
dst = arguments->to_root;
25102511
if (skip ||
2511-
!copy_file(FIO_DB_HOST, dst, FIO_BACKUP_HOST, file))
2512+
!copy_file(FIO_DB_HOST, dst, FIO_BACKUP_HOST, file, true))
25122513
{
25132514
/* disappeared file not to be confused with 'not changed' */
25142515
if (file->write_size != FILE_NOT_FOUND)

src/data.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ bool
521521
backup_data_file(backup_files_arg* arguments,
522522
const char *to_path, pgFile *file,
523523
XLogRecPtr prev_backup_start_lsn, BackupMode backup_mode,
524-
CompressAlg calg, int clevel)
524+
CompressAlg calg, int clevel, bool missing_ok)
525525
{
526526
FILE *in;
527527
FILE *out;
@@ -567,9 +567,14 @@ backup_data_file(backup_files_arg* arguments,
567567
*/
568568
if (errno == ENOENT)
569569
{
570-
elog(LOG, "File \"%s\" is not found", file->path);
571-
file->write_size = FILE_NOT_FOUND;
572-
return false;
570+
if (missing_ok)
571+
{
572+
elog(LOG, "File \"%s\" is not found", file->path);
573+
file->write_size = FILE_NOT_FOUND;
574+
return false;
575+
}
576+
else
577+
elog(ERROR, "File \"%s\" is not found", file->path);
573578
}
574579

575580
elog(ERROR, "cannot open file \"%s\": %s",
@@ -754,7 +759,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
754759
break;
755760

756761
/*
757-
* We need to truncate result file if data file in a incremental backup
762+
* We need to truncate result file if data file in an incremental backup
758763
* less than data file in a full backup. We know it thanks to n_blocks.
759764
*
760765
* It may be equal to -1, then we don't want to truncate the result
@@ -939,7 +944,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
939944
*/
940945
bool
941946
copy_file(fio_location from_location, const char *to_root,
942-
fio_location to_location, pgFile *file)
947+
fio_location to_location, pgFile *file, bool missing_ok)
943948
{
944949
char to_path[MAXPGPATH];
945950
FILE *in;
@@ -963,12 +968,17 @@ copy_file(fio_location from_location, const char *to_root,
963968
FIN_FILE_CRC32(true, crc);
964969
file->crc = crc;
965970

966-
/* maybe deleted, it's not error */
971+
/* maybe deleted, it's not error in case of backup */
967972
if (errno == ENOENT)
968973
{
969-
elog(LOG, "File \"%s\" is not found", file->path);
970-
file->write_size = FILE_NOT_FOUND;
971-
return false;
974+
if (missing_ok)
975+
{
976+
elog(LOG, "File \"%s\" is not found", file->path);
977+
file->write_size = FILE_NOT_FOUND;
978+
return false;
979+
}
980+
else
981+
elog(ERROR, "File \"%s\" is not found", file->path);
972982
}
973983

974984
elog(ERROR, "cannot open source file \"%s\": %s", file->path,

src/merge.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ merge_files(void *arg)
489489
* of DELTA backup we should consider n_blocks to truncate the target
490490
* backup.
491491
*/
492-
if (file->write_size == BYTES_INVALID && file->n_blocks == -1)
492+
if (file->write_size == BYTES_INVALID && file->n_blocks == BLOCKNUM_INVALID)
493493
{
494494
elog(VERBOSE, "Skip merging file \"%s\", the file didn't change",
495495
file->path);
@@ -605,7 +605,8 @@ merge_files(void *arg)
605605
to_backup->start_lsn,
606606
to_backup->backup_mode,
607607
to_backup->compress_alg,
608-
to_backup->compress_level);
608+
to_backup->compress_level,
609+
false);
609610

610611
file->path = prev_path;
611612

@@ -645,12 +646,12 @@ merge_files(void *arg)
645646
argument->from_external);
646647
makeExternalDirPathByNum(to_root, argument->to_external_prefix,
647648
new_dir_num);
648-
copy_file(FIO_LOCAL_HOST, to_root, FIO_LOCAL_HOST, file);
649+
copy_file(FIO_LOCAL_HOST, to_root, FIO_LOCAL_HOST, file, false);
649650
}
650651
else if (strcmp(file->name, "pg_control") == 0)
651652
copy_pgcontrol_file(argument->from_root, FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file);
652653
else
653-
copy_file(FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file);
654+
copy_file(FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file, false);
654655

655656
/*
656657
* We need to save compression algorithm type of the target backup to be

src/pg_probackup.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,14 @@ extern bool backup_data_file(backup_files_arg* arguments,
629629
const char *to_path, pgFile *file,
630630
XLogRecPtr prev_backup_start_lsn,
631631
BackupMode backup_mode,
632-
CompressAlg calg, int clevel);
632+
CompressAlg calg, int clevel,
633+
bool missing_ok);
633634
extern void restore_data_file(const char *to_path,
634635
pgFile *file, bool allow_truncate,
635636
bool write_header,
636637
uint32 backup_version);
637638
extern bool copy_file(fio_location from_location, const char *to_root,
638-
fio_location to_location, pgFile *file);
639+
fio_location to_location, pgFile *file, bool missing_ok);
639640

640641
extern bool check_file_pages(pgFile *file, XLogRecPtr stop_lsn,
641642
uint32 checksum_version, uint32 backup_version);

src/restore.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ restore_files(void *arg)
742742
if (backup_contains_external(external_path,
743743
arguments->dest_external_dirs))
744744
copy_file(FIO_BACKUP_HOST,
745-
external_path, FIO_DB_HOST, file);
745+
external_path, FIO_DB_HOST, file, false);
746746
}
747747
else if (strcmp(file->name, "pg_control") == 0)
748748
copy_pgcontrol_file(from_root, FIO_BACKUP_HOST,
@@ -751,7 +751,7 @@ restore_files(void *arg)
751751
else
752752
copy_file(FIO_BACKUP_HOST,
753753
instance_config.pgdata, FIO_DB_HOST,
754-
file);
754+
file, false);
755755

756756
/* print size of restored file */
757757
if (file->write_size != BYTES_INVALID)

0 commit comments

Comments
 (0)