From 03a3fb8a14558698e4646ea14acaf44f15697b06 Mon Sep 17 00:00:00 2001 From: Arthur Zakirov Date: Sat, 9 Jun 2018 15:14:44 +0300 Subject: [PATCH] PGPRO-1646: Use int64 for write_size --- src/backup.c | 6 +++--- src/data.c | 2 +- src/dir.c | 7 ++++--- src/pg_probackup.h | 3 ++- src/restore.c | 2 +- src/validate.c | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/backup.c b/src/backup.c index c96d8f17..e58da8b8 100644 --- a/src/backup.c +++ b/src/backup.c @@ -357,7 +357,7 @@ remote_copy_file(PGconn *conn, pgFile* file) elog(ERROR, "final receive failed: status %d ; %s",PQresultStatus(res), PQerrorMessage(conn)); } - file->write_size = (int) file->read_size; + file->write_size = (int64) file->read_size; FIN_CRC32C(file->crc); fclose(out); @@ -438,7 +438,7 @@ remote_backup_files(void *arg) /* receive the data from stream and write to backup file */ remote_copy_file(file_backup_conn, file); - elog(VERBOSE, "File \"%s\". Copied %d bytes", + elog(VERBOSE, "File \"%s\". Copied " INT64_FORMAT " bytes", file->path, file->write_size); PQfinish(file_backup_conn); } @@ -2115,7 +2115,7 @@ backup_files(void *arg) continue; } - elog(VERBOSE, "File \"%s\". Copied %d bytes", + elog(VERBOSE, "File \"%s\". Copied "INT64_FORMAT " bytes", file->path, file->write_size); } else diff --git a/src/data.c b/src/data.c index 4605b275..4ab8a1c0 100644 --- a/src/data.c +++ b/src/data.c @@ -843,7 +843,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file) file->read_size += read_len; } - file->write_size = (int) file->read_size; + file->write_size = (int64) file->read_size; /* finish CRC calculation and store into pgFile */ FIN_CRC32C(crc); file->crc = crc; diff --git a/src/dir.c b/src/dir.c index 6cbd5f2e..64058b62 100644 --- a/src/dir.c +++ b/src/dir.c @@ -821,8 +821,9 @@ print_file_list(FILE *out, const parray *files, const char *root) if (root && strstr(path, root) == path) path = GetRelativePath(path, root); - fprintf(out, "{\"path\":\"%s\", \"size\":\"%d\",\"mode\":\"%u\"," - "\"is_datafile\":\"%u\", \"is_cfs\":\"%u\", \"crc\":\"%u\"," + fprintf(out, "{\"path\":\"%s\", \"size\":\"" INT64_FORMAT "\", " + "\"mode\":\"%u\", \"is_datafile\":\"%u\", " + "\"is_cfs\":\"%u\", \"crc\":\"%u\", " "\"compress_alg\":\"%s\"", path, file->write_size, file->mode, file->is_datafile ? 1 : 0, file->is_cfs ? 1 : 0, file->crc, @@ -1032,7 +1033,7 @@ dir_read_file_list(const char *root, const char *file_txt) file = pgFileInit(filepath); - file->write_size = (int) write_size; + file->write_size = (int64) write_size; file->mode = (mode_t) mode; file->is_datafile = is_datafile ? true : false; file->is_cfs = is_cfs ? true : false; diff --git a/src/pg_probackup.h b/src/pg_probackup.h index b01094e3..b4ebfb98 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -88,9 +88,10 @@ typedef struct pgFile size_t size; /* size of the file */ size_t read_size; /* size of the portion read (if only some pages are backed up, it's different from size) */ - int write_size; /* size of the backed-up file. BYTES_INVALID means + int64 write_size; /* size of the backed-up file. BYTES_INVALID means that the file existed but was not backed up because not modified since last backup. */ + /* we need int64 here to store '-1' value */ pg_crc32 crc; /* CRC value of the file, regular file only */ char *linked; /* path of the linked file */ bool is_datafile; /* true if the file is PostgreSQL data file */ diff --git a/src/restore.c b/src/restore.c index 3bf87d7c..a35d50b2 100644 --- a/src/restore.c +++ b/src/restore.c @@ -777,7 +777,7 @@ restore_files(void *arg) /* print size of restored file */ if (file->write_size != BYTES_INVALID) - elog(LOG, "Restored file %s : %d bytes", + elog(LOG, "Restored file %s : " INT64_FORMAT " bytes", file->path, file->write_size); } diff --git a/src/validate.c b/src/validate.c index 97a248ec..41467f25 100644 --- a/src/validate.c +++ b/src/validate.c @@ -189,7 +189,7 @@ pgBackupValidateFiles(void *arg) if (file->write_size != st.st_size) { - elog(WARNING, "Invalid size of backup file \"%s\" : %d. Expected %lu", + elog(WARNING, "Invalid size of backup file \"%s\" : " INT64_FORMAT ". Expected %lu", file->path, file->write_size, (unsigned long) st.st_size); arguments->corrupted = true; break;