From 0e24b62a73c00277036e72f2870e175574e859c7 Mon Sep 17 00:00:00 2001 From: Yura Sokolov Date: Thu, 17 Nov 2022 01:45:21 +0300 Subject: [PATCH] [PBCKP-345] more consistent use of int64_t for file sizes --- src/archive.c | 2 +- src/catchup.c | 6 +++--- src/data.c | 19 ++++++++++++------- src/delete.c | 6 +++--- src/fetch.c | 2 +- src/pg_probackup.h | 10 +++++----- src/show.c | 2 +- src/util.c | 6 +++--- src/utils/file.c | 3 ++- src/utils/file.h | 2 +- 10 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/archive.c b/src/archive.c index abc04e86..1c1b5e41 100644 --- a/src/archive.c +++ b/src/archive.c @@ -390,7 +390,7 @@ push_file_internal(const char *wal_file_name, const char *pg_xlog_dir, /* partial handling */ pio_stat_t st; int partial_try_count = 0; - ssize_t partial_file_size = 0; + int64_t partial_file_size = 0; bool partial_is_stale = true; size_t len; err_i err = $noerr(); diff --git a/src/catchup.c b/src/catchup.c index 9f677930..03876747 100644 --- a/src/catchup.c +++ b/src/catchup.c @@ -439,7 +439,7 @@ catchup_thread_runner(void *arg) if (file->write_size == BYTES_INVALID) { - elog(LOG, "Skipping the unchanged file: \"%s\", read %zu bytes", from_fullpath, file->read_size); + elog(LOG, "Skipping the unchanged file: \"%s\", read %lld bytes", from_fullpath, (long long)file->read_size); continue; } @@ -630,8 +630,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, /* for fancy reporting */ time_t start_time, end_time; - ssize_t transfered_datafiles_bytes = 0; - ssize_t transfered_walfiles_bytes = 0; + int64_t transfered_datafiles_bytes = 0; + int64_t transfered_walfiles_bytes = 0; char pretty_source_bytes[20]; err_i err = $noerr(); diff --git a/src/data.c b/src/data.c index d9eaf080..bc1f1809 100644 --- a/src/data.c +++ b/src/data.c @@ -507,7 +507,8 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat * NOTE This is a normal situation, if the file size has changed * since the moment we computed it. */ - file->n_blocks = file->size/BLCKSZ; + file->n_blocks = (typeof(file->n_blocks))(file->size/BLCKSZ); + Assert((int64_t)file->n_blocks * BLCKSZ == file->size); /* * Skip unchanged file only if it exists in previous backup. @@ -611,12 +612,15 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat elog(ERROR, "Cannot read file \"%s\"", from_fullpath); } - file->read_size = rc * BLCKSZ; + file->read_size = (int64_t)rc * BLCKSZ; /* refresh n_blocks for FULL and DELTA */ if (backup_mode == BACKUP_MODE_FULL || backup_mode == BACKUP_MODE_DIFF_DELTA) - file->n_blocks = file->read_size / BLCKSZ; + { + file->n_blocks = (typeof(file->n_blocks))(file->read_size / BLCKSZ); + Assert((int64_t)file->n_blocks * BLCKSZ == file->read_size); + } /* Determine that file didn`t changed in case of incremental backup */ if (backup_mode != BACKUP_MODE_FULL && @@ -650,7 +654,7 @@ cleanup: void catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpath, XLogRecPtr sync_lsn, BackupMode backup_mode, - uint32 checksum_version, size_t prev_size) + uint32 checksum_version, int64_t prev_size) { int rc; bool use_pagemap; @@ -760,7 +764,7 @@ catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpa elog(ERROR, "Cannot read file \"%s\"", from_fullpath); } - file->read_size = rc * BLCKSZ; + file->read_size = (int64_t)rc * BLCKSZ; /* Determine that file didn`t changed in case of incremental catchup */ if (backup_mode != BACKUP_MODE_FULL && @@ -1595,7 +1599,8 @@ check_data_file(ConnectionArgs *arguments, pgFile *file, * NOTE This is a normal situation, if the file size has changed * since the moment we computed it. */ - nblocks = file->size/BLCKSZ; + nblocks = (typeof(nblocks))(file->size/BLCKSZ); + Assert((int64_t)nblocks * BLCKSZ == file->size); for (blknum = 0; blknum < nblocks; blknum++) { @@ -2275,7 +2280,7 @@ copy_pages(const char *to_fullpath, const char *from_fullpath, elog(ERROR, "Cannot seek to end of file position in destination file \"%s\": %s", to_fullpath, strerror(errno)); { - long pos = ftell(out); + int64_t pos = ftell(out); if (pos < 0) elog(ERROR, "Cannot get position in destination file \"%s\": %s", diff --git a/src/delete.c b/src/delete.c index b6ed2396..9873cb16 100644 --- a/src/delete.c +++ b/src/delete.c @@ -794,8 +794,8 @@ delete_walfiles_in_tli(InstanceState *instanceState, XLogRecPtr keep_lsn, timeli char first_to_del_str[MAXFNAMELEN]; char oldest_to_keep_str[MAXFNAMELEN]; int i; - size_t wal_size_logical = 0; - size_t wal_size_actual = 0; + int64_t wal_size_logical = 0; + int64_t wal_size_actual = 0; char wal_pretty_size[20]; bool purge_all = false; @@ -837,7 +837,7 @@ delete_walfiles_in_tli(InstanceState *instanceState, XLogRecPtr keep_lsn, timeli /* sanity */ if (OldestToKeepSegNo > FirstToDeleteSegNo) { - wal_size_logical = (OldestToKeepSegNo - FirstToDeleteSegNo) * xlog_seg_size; + wal_size_logical = (int64_t)(OldestToKeepSegNo - FirstToDeleteSegNo) * xlog_seg_size; /* In case of 'purge all' scenario OldestToKeepSegNo will be deleted too */ if (purge_all) diff --git a/src/fetch.c b/src/fetch.c index bce8dacc..d283af12 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -54,7 +54,7 @@ slurpFile(fio_location location, const char *datadir, const char *path, size_t * ft_logerr(FT_FATAL, $errmsg(err), "slurpFile"); } - if (statbuf.pst_size > SIZE_MAX) + if (statbuf.pst_size > SSIZE_MAX) ft_log(FT_FATAL, "file \"%s\" is too large: %lld", fullpath, (long long)statbuf.pst_size); diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 4f8ba737..f4571707 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -214,14 +214,14 @@ typedef struct pgFile pio_file_kind_e kind; /* kind of file */ uint32_t mode; /* protection (permission) */ - uint64_t size; /* size of the file */ + int64_t size; /* size of the file */ - uint64_t read_size; /* size of the portion read (if only some pages are + int64_t read_size; /* size of the portion read (if only some pages are backed up, it's different from size) */ int64_t 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. */ - uint64_t uncompressed_size; /* size of the backed-up file before compression + int64_t uncompressed_size; /* size of the backed-up file before compression * and adding block headers. */ time_t mtime; /* file st_mtime attribute, can be used only @@ -593,7 +593,7 @@ struct timelineInfo { XLogSegNo end_segno; /* last present segment in this timeline */ size_t n_xlog_files; /* number of segments (only really existing) * does not include lost segments */ - size_t size; /* space on disk taken by regular WAL files */ + int64_t size; /* space on disk taken by regular WAL files */ parray *backups; /* array of pgBackup sturctures with info * about backups belonging to this timeline */ parray *xlog_filelist; /* array of ordinary WAL segments, '.partial' @@ -1055,7 +1055,7 @@ extern bool check_data_file(ConnectionArgs *arguments, pgFile *file, extern void catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpath, XLogRecPtr sync_lsn, BackupMode backup_mode, - uint32 checksum_version, size_t prev_size); + uint32 checksum_version, int64_t prev_size); extern void backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpath, XLogRecPtr prev_backup_start_lsn, BackupMode backup_mode, CompressAlg calg, int clevel, uint32 checksum_version, diff --git a/src/show.c b/src/show.c index 5440e28a..c7d71406 100644 --- a/src/show.c +++ b/src/show.c @@ -1089,7 +1089,7 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size, appendPQExpBuffer(buf, "%zu", tlinfo->n_xlog_files); json_add_key(buf, "size", json_level); - appendPQExpBuffer(buf, "%zu", tlinfo->size); + appendPQExpBuffer(buf, "%lld", (long long)tlinfo->size); json_add_key(buf, "zratio", json_level); diff --git a/src/util.c b/src/util.c index 5b341fc2..a54e34e0 100644 --- a/src/util.c +++ b/src/util.c @@ -403,9 +403,9 @@ copy_pgcontrol_file(fio_location from_location, const char *from_fullpath, digestControlFile(&ControlFile, buffer, size); file->crc = ControlFile.crc; - file->read_size = size; - file->write_size = size; - file->uncompressed_size = size; + file->read_size = (int64_t)size; + file->write_size = (int64_t)size; + file->uncompressed_size = (int64_t)size; writeControlFile(to_location, to_fullpath, &ControlFile); diff --git a/src/utils/file.c b/src/utils/file.c index eae68201..2b37ad61 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -53,7 +53,7 @@ typedef struct { pio_file_kind_e kind; mode_t mode; - size_t size; + int64_t size; time_t mtime; bool is_datafile; Oid tblspcOid; @@ -1914,6 +1914,7 @@ fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file, } req.arg.nblocks = file->size/BLCKSZ; + Assert((int64_t)req.arg.nblocks * BLCKSZ == file->size); req.arg.segmentno = file->segno * RELSEG_SIZE; req.arg.horizonLsn = horizonLsn; req.arg.checksumVersion = checksum_version; diff --git a/src/utils/file.h b/src/utils/file.h index 991bfe24..4dd95c87 100644 --- a/src/utils/file.h +++ b/src/utils/file.h @@ -105,7 +105,7 @@ typedef enum pio_file_kind { } pio_file_kind_e; typedef struct pio_stat { - uint64_t pst_size; + int64_t pst_size; int64_t pst_mtime; uint32_t pst_mode; pio_file_kind_e pst_kind;