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

Skip to content

Issue 74: copy_file and backup_data_file() lax behavior #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,8 @@ backup_files(void *arg)
arguments->prev_start_lsn,
current.backup_mode,
instance_config.compress_alg,
instance_config.compress_level))
instance_config.compress_level,
true))
{
/* disappeared file not to be confused with 'not changed' */
if (file->write_size != FILE_NOT_FOUND)
Expand Down Expand Up @@ -2508,7 +2509,7 @@ backup_files(void *arg)
else
dst = arguments->to_root;
if (skip ||
!copy_file(FIO_DB_HOST, dst, FIO_BACKUP_HOST, file))
!copy_file(FIO_DB_HOST, dst, FIO_BACKUP_HOST, file, true))
{
/* disappeared file not to be confused with 'not changed' */
if (file->write_size != FILE_NOT_FOUND)
Expand Down
30 changes: 20 additions & 10 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ bool
backup_data_file(backup_files_arg* arguments,
const char *to_path, pgFile *file,
XLogRecPtr prev_backup_start_lsn, BackupMode backup_mode,
CompressAlg calg, int clevel)
CompressAlg calg, int clevel, bool missing_ok)
{
FILE *in;
FILE *out;
Expand Down Expand Up @@ -567,9 +567,14 @@ backup_data_file(backup_files_arg* arguments,
*/
if (errno == ENOENT)
{
elog(LOG, "File \"%s\" is not found", file->path);
file->write_size = FILE_NOT_FOUND;
return false;
if (missing_ok)
{
elog(LOG, "File \"%s\" is not found", file->path);
file->write_size = FILE_NOT_FOUND;
return false;
}
else
elog(ERROR, "File \"%s\" is not found", file->path);
}

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

/*
* We need to truncate result file if data file in a incremental backup
* We need to truncate result file if data file in an incremental backup
* less than data file in a full backup. We know it thanks to n_blocks.
*
* It may be equal to -1, then we don't want to truncate the result
Expand Down Expand Up @@ -939,7 +944,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
*/
bool
copy_file(fio_location from_location, const char *to_root,
fio_location to_location, pgFile *file)
fio_location to_location, pgFile *file, bool missing_ok)
{
char to_path[MAXPGPATH];
FILE *in;
Expand All @@ -963,12 +968,17 @@ copy_file(fio_location from_location, const char *to_root,
FIN_FILE_CRC32(true, crc);
file->crc = crc;

/* maybe deleted, it's not error */
/* maybe deleted, it's not error in case of backup */
if (errno == ENOENT)
{
elog(LOG, "File \"%s\" is not found", file->path);
file->write_size = FILE_NOT_FOUND;
return false;
if (missing_ok)
{
elog(LOG, "File \"%s\" is not found", file->path);
file->write_size = FILE_NOT_FOUND;
return false;
}
else
elog(ERROR, "File \"%s\" is not found", file->path);
}

elog(ERROR, "cannot open source file \"%s\": %s", file->path,
Expand Down
9 changes: 5 additions & 4 deletions src/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ merge_files(void *arg)
* of DELTA backup we should consider n_blocks to truncate the target
* backup.
*/
if (file->write_size == BYTES_INVALID && file->n_blocks == -1)
if (file->write_size == BYTES_INVALID && file->n_blocks == BLOCKNUM_INVALID)
{
elog(VERBOSE, "Skip merging file \"%s\", the file didn't change",
file->path);
Expand Down Expand Up @@ -605,7 +605,8 @@ merge_files(void *arg)
to_backup->start_lsn,
to_backup->backup_mode,
to_backup->compress_alg,
to_backup->compress_level);
to_backup->compress_level,
false);

file->path = prev_path;

Expand Down Expand Up @@ -645,12 +646,12 @@ merge_files(void *arg)
argument->from_external);
makeExternalDirPathByNum(to_root, argument->to_external_prefix,
new_dir_num);
copy_file(FIO_LOCAL_HOST, to_root, FIO_LOCAL_HOST, file);
copy_file(FIO_LOCAL_HOST, to_root, FIO_LOCAL_HOST, file, false);
}
else if (strcmp(file->name, "pg_control") == 0)
copy_pgcontrol_file(argument->from_root, FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file);
else
copy_file(FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file);
copy_file(FIO_LOCAL_HOST, argument->to_root, FIO_LOCAL_HOST, file, false);

/*
* We need to save compression algorithm type of the target backup to be
Expand Down
5 changes: 3 additions & 2 deletions src/pg_probackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,14 @@ extern bool backup_data_file(backup_files_arg* arguments,
const char *to_path, pgFile *file,
XLogRecPtr prev_backup_start_lsn,
BackupMode backup_mode,
CompressAlg calg, int clevel);
CompressAlg calg, int clevel,
bool missing_ok);
extern void restore_data_file(const char *to_path,
pgFile *file, bool allow_truncate,
bool write_header,
uint32 backup_version);
extern bool copy_file(fio_location from_location, const char *to_root,
fio_location to_location, pgFile *file);
fio_location to_location, pgFile *file, bool missing_ok);

extern bool check_file_pages(pgFile *file, XLogRecPtr stop_lsn,
uint32 checksum_version, uint32 backup_version);
Expand Down
4 changes: 2 additions & 2 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ restore_files(void *arg)
if (backup_contains_external(external_path,
arguments->dest_external_dirs))
copy_file(FIO_BACKUP_HOST,
external_path, FIO_DB_HOST, file);
external_path, FIO_DB_HOST, file, false);
}
else if (strcmp(file->name, "pg_control") == 0)
copy_pgcontrol_file(from_root, FIO_BACKUP_HOST,
Expand All @@ -751,7 +751,7 @@ restore_files(void *arg)
else
copy_file(FIO_BACKUP_HOST,
instance_config.pgdata, FIO_DB_HOST,
file);
file, false);

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