Skip to content

Commit 0e24b62

Browse files
committed
[PBCKP-345] more consistent use of int64_t for file sizes
1 parent e905500 commit 0e24b62

File tree

10 files changed

+32
-26
lines changed

10 files changed

+32
-26
lines changed

src/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ push_file_internal(const char *wal_file_name, const char *pg_xlog_dir,
390390
/* partial handling */
391391
pio_stat_t st;
392392
int partial_try_count = 0;
393-
ssize_t partial_file_size = 0;
393+
int64_t partial_file_size = 0;
394394
bool partial_is_stale = true;
395395
size_t len;
396396
err_i err = $noerr();

src/catchup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ catchup_thread_runner(void *arg)
439439

440440
if (file->write_size == BYTES_INVALID)
441441
{
442-
elog(LOG, "Skipping the unchanged file: \"%s\", read %zu bytes", from_fullpath, file->read_size);
442+
elog(LOG, "Skipping the unchanged file: \"%s\", read %lld bytes", from_fullpath, (long long)file->read_size);
443443
continue;
444444
}
445445

@@ -630,8 +630,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
630630

631631
/* for fancy reporting */
632632
time_t start_time, end_time;
633-
ssize_t transfered_datafiles_bytes = 0;
634-
ssize_t transfered_walfiles_bytes = 0;
633+
int64_t transfered_datafiles_bytes = 0;
634+
int64_t transfered_walfiles_bytes = 0;
635635
char pretty_source_bytes[20];
636636
err_i err = $noerr();
637637

src/data.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat
507507
* NOTE This is a normal situation, if the file size has changed
508508
* since the moment we computed it.
509509
*/
510-
file->n_blocks = file->size/BLCKSZ;
510+
file->n_blocks = (typeof(file->n_blocks))(file->size/BLCKSZ);
511+
Assert((int64_t)file->n_blocks * BLCKSZ == file->size);
511512

512513
/*
513514
* 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
611612
elog(ERROR, "Cannot read file \"%s\"", from_fullpath);
612613
}
613614

614-
file->read_size = rc * BLCKSZ;
615+
file->read_size = (int64_t)rc * BLCKSZ;
615616

616617
/* refresh n_blocks for FULL and DELTA */
617618
if (backup_mode == BACKUP_MODE_FULL ||
618619
backup_mode == BACKUP_MODE_DIFF_DELTA)
619-
file->n_blocks = file->read_size / BLCKSZ;
620+
{
621+
file->n_blocks = (typeof(file->n_blocks))(file->read_size / BLCKSZ);
622+
Assert((int64_t)file->n_blocks * BLCKSZ == file->read_size);
623+
}
620624

621625
/* Determine that file didn`t changed in case of incremental backup */
622626
if (backup_mode != BACKUP_MODE_FULL &&
@@ -650,7 +654,7 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat
650654
void
651655
catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpath,
652656
XLogRecPtr sync_lsn, BackupMode backup_mode,
653-
uint32 checksum_version, size_t prev_size)
657+
uint32 checksum_version, int64_t prev_size)
654658
{
655659
int rc;
656660
bool use_pagemap;
@@ -760,7 +764,7 @@ catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpa
760764
elog(ERROR, "Cannot read file \"%s\"", from_fullpath);
761765
}
762766

763-
file->read_size = rc * BLCKSZ;
767+
file->read_size = (int64_t)rc * BLCKSZ;
764768

765769
/* Determine that file didn`t changed in case of incremental catchup */
766770
if (backup_mode != BACKUP_MODE_FULL &&
@@ -1595,7 +1599,8 @@ check_data_file(ConnectionArgs *arguments, pgFile *file,
15951599
* NOTE This is a normal situation, if the file size has changed
15961600
* since the moment we computed it.
15971601
*/
1598-
nblocks = file->size/BLCKSZ;
1602+
nblocks = (typeof(nblocks))(file->size/BLCKSZ);
1603+
Assert((int64_t)nblocks * BLCKSZ == file->size);
15991604

16001605
for (blknum = 0; blknum < nblocks; blknum++)
16011606
{
@@ -2275,7 +2280,7 @@ copy_pages(const char *to_fullpath, const char *from_fullpath,
22752280
elog(ERROR, "Cannot seek to end of file position in destination file \"%s\": %s",
22762281
to_fullpath, strerror(errno));
22772282
{
2278-
long pos = ftell(out);
2283+
int64_t pos = ftell(out);
22792284

22802285
if (pos < 0)
22812286
elog(ERROR, "Cannot get position in destination file \"%s\": %s",

src/delete.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ delete_walfiles_in_tli(InstanceState *instanceState, XLogRecPtr keep_lsn, timeli
794794
char first_to_del_str[MAXFNAMELEN];
795795
char oldest_to_keep_str[MAXFNAMELEN];
796796
int i;
797-
size_t wal_size_logical = 0;
798-
size_t wal_size_actual = 0;
797+
int64_t wal_size_logical = 0;
798+
int64_t wal_size_actual = 0;
799799
char wal_pretty_size[20];
800800
bool purge_all = false;
801801

@@ -837,7 +837,7 @@ delete_walfiles_in_tli(InstanceState *instanceState, XLogRecPtr keep_lsn, timeli
837837
/* sanity */
838838
if (OldestToKeepSegNo > FirstToDeleteSegNo)
839839
{
840-
wal_size_logical = (OldestToKeepSegNo - FirstToDeleteSegNo) * xlog_seg_size;
840+
wal_size_logical = (int64_t)(OldestToKeepSegNo - FirstToDeleteSegNo) * xlog_seg_size;
841841

842842
/* In case of 'purge all' scenario OldestToKeepSegNo will be deleted too */
843843
if (purge_all)

src/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ slurpFile(fio_location location, const char *datadir, const char *path, size_t *
5454
ft_logerr(FT_FATAL, $errmsg(err), "slurpFile");
5555
}
5656

57-
if (statbuf.pst_size > SIZE_MAX)
57+
if (statbuf.pst_size > SSIZE_MAX)
5858
ft_log(FT_FATAL, "file \"%s\" is too large: %lld",
5959
fullpath, (long long)statbuf.pst_size);
6060

src/pg_probackup.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ typedef struct pgFile
214214

215215
pio_file_kind_e kind; /* kind of file */
216216
uint32_t mode; /* protection (permission) */
217-
uint64_t size; /* size of the file */
217+
int64_t size; /* size of the file */
218218

219-
uint64_t read_size; /* size of the portion read (if only some pages are
219+
int64_t read_size; /* size of the portion read (if only some pages are
220220
backed up, it's different from size) */
221221
int64_t write_size; /* size of the backed-up file. BYTES_INVALID means
222222
that the file existed but was not backed up
223223
because not modified since last backup. */
224-
uint64_t uncompressed_size; /* size of the backed-up file before compression
224+
int64_t uncompressed_size; /* size of the backed-up file before compression
225225
* and adding block headers.
226226
*/
227227
time_t mtime; /* file st_mtime attribute, can be used only
@@ -593,7 +593,7 @@ struct timelineInfo {
593593
XLogSegNo end_segno; /* last present segment in this timeline */
594594
size_t n_xlog_files; /* number of segments (only really existing)
595595
* does not include lost segments */
596-
size_t size; /* space on disk taken by regular WAL files */
596+
int64_t size; /* space on disk taken by regular WAL files */
597597
parray *backups; /* array of pgBackup sturctures with info
598598
* about backups belonging to this timeline */
599599
parray *xlog_filelist; /* array of ordinary WAL segments, '.partial'
@@ -1055,7 +1055,7 @@ extern bool check_data_file(ConnectionArgs *arguments, pgFile *file,
10551055

10561056
extern void catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpath,
10571057
XLogRecPtr sync_lsn, BackupMode backup_mode,
1058-
uint32 checksum_version, size_t prev_size);
1058+
uint32 checksum_version, int64_t prev_size);
10591059
extern void backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpath,
10601060
XLogRecPtr prev_backup_start_lsn, BackupMode backup_mode,
10611061
CompressAlg calg, int clevel, uint32 checksum_version,

src/show.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ show_archive_json(const char *instance_name, uint32 xlog_seg_size,
10891089
appendPQExpBuffer(buf, "%zu", tlinfo->n_xlog_files);
10901090

10911091
json_add_key(buf, "size", json_level);
1092-
appendPQExpBuffer(buf, "%zu", tlinfo->size);
1092+
appendPQExpBuffer(buf, "%lld", (long long)tlinfo->size);
10931093

10941094
json_add_key(buf, "zratio", json_level);
10951095

src/util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ copy_pgcontrol_file(fio_location from_location, const char *from_fullpath,
403403
digestControlFile(&ControlFile, buffer, size);
404404

405405
file->crc = ControlFile.crc;
406-
file->read_size = size;
407-
file->write_size = size;
408-
file->uncompressed_size = size;
406+
file->read_size = (int64_t)size;
407+
file->write_size = (int64_t)size;
408+
file->uncompressed_size = (int64_t)size;
409409

410410
writeControlFile(to_location, to_fullpath, &ControlFile);
411411

src/utils/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef struct
5353
{
5454
pio_file_kind_e kind;
5555
mode_t mode;
56-
size_t size;
56+
int64_t size;
5757
time_t mtime;
5858
bool is_datafile;
5959
Oid tblspcOid;
@@ -1914,6 +1914,7 @@ fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file,
19141914
}
19151915

19161916
req.arg.nblocks = file->size/BLCKSZ;
1917+
Assert((int64_t)req.arg.nblocks * BLCKSZ == file->size);
19171918
req.arg.segmentno = file->segno * RELSEG_SIZE;
19181919
req.arg.horizonLsn = horizonLsn;
19191920
req.arg.checksumVersion = checksum_version;

src/utils/file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ typedef enum pio_file_kind {
105105
} pio_file_kind_e;
106106

107107
typedef struct pio_stat {
108-
uint64_t pst_size;
108+
int64_t pst_size;
109109
int64_t pst_mtime;
110110
uint32_t pst_mode;
111111
pio_file_kind_e pst_kind;

0 commit comments

Comments
 (0)