Skip to content

Commit 1b9311e

Browse files
author
wuyf41619
committed
Repair backup failed (the value of segment_size is greater than 2G)
1 parent 2f19f6d commit 1b9311e

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/catalog.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ get_backup_filelist(pgBackup *backup, bool strict)
11171117
file->segno = (int) segno;
11181118

11191119
if (get_control_value_int64(buf, "n_blocks", &n_blocks, false))
1120-
file->n_blocks = (int) n_blocks;
1120+
file->n_blocks = (int64) n_blocks;
11211121

11221122
if (get_control_value_int64(buf, "n_headers", &n_headers, false))
11231123
file->n_headers = (int) n_headers;
@@ -2568,7 +2568,7 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
25682568
len += sprintf(line+len, ",\"linked\":\"%s\"", file->linked);
25692569

25702570
if (file->n_blocks > 0)
2571-
len += sprintf(line+len, ",\"n_blocks\":\"%i\"", file->n_blocks);
2571+
len += sprintf(line+len, ",\"n_blocks\":\"%ld\"", file->n_blocks);
25722572

25732573
if (file->n_headers > 0)
25742574
{

src/data.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ prepare_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
300300
while (!page_is_valid && try_again--)
301301
{
302302
/* read the block */
303-
int read_len = fio_pread(in, page, blknum * BLCKSZ);
303+
int read_len = fio_pread(in, page, ((int64)blknum) * BLCKSZ);
304304

305305
/* The block could have been truncated. It is fine. */
306306
if (read_len == 0)
@@ -609,7 +609,7 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat
609609
elog(ERROR, "Cannot read file \"%s\"", from_fullpath);
610610
}
611611

612-
file->read_size = rc * BLCKSZ;
612+
file->read_size = ((int64)rc) * BLCKSZ;
613613

614614
/* refresh n_blocks for FULL and DELTA */
615615
if (backup_mode == BACKUP_MODE_FULL ||
@@ -758,7 +758,7 @@ catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpa
758758
elog(ERROR, "Cannot read file \"%s\"", from_fullpath);
759759
}
760760

761-
file->read_size = rc * BLCKSZ;
761+
file->read_size = ((int64)rc) * BLCKSZ;
762762

763763
/* Determine that file didn`t changed in case of incremental catchup */
764764
if (backup_mode != BACKUP_MODE_FULL &&
@@ -1072,7 +1072,7 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
10721072
if (fio_fseek(out, 0) < 0)
10731073
elog(ERROR, "Cannot seek to the start of file \"%s\": %s", to_fullpath, strerror(errno));
10741074

1075-
if (fio_ftruncate(out, blknum * BLCKSZ) != 0)
1075+
if (fio_ftruncate(out, ((int64)blknum) * BLCKSZ) != 0)
10761076
elog(ERROR, "Cannot truncate file \"%s\": %s", to_fullpath, strerror(errno));
10771077

10781078
break;
@@ -1123,7 +1123,7 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
11231123
cur_pos_in != headers[n_hdr].pos)
11241124
{
11251125
if (fseek(in, headers[n_hdr].pos, SEEK_SET) != 0)
1126-
elog(ERROR, "Cannot seek to offset %u of \"%s\": %s",
1126+
elog(ERROR, "Cannot seek to offset %ld of \"%s\": %s",
11271127
headers[n_hdr].pos, from_fullpath, strerror(errno));
11281128

11291129
cur_pos_in = headers[n_hdr].pos;
@@ -1158,7 +1158,7 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
11581158
* When restoring file from FULL backup, pages are written sequentially,
11591159
* so there is no need to issue fseek for every page.
11601160
*/
1161-
write_pos = blknum * BLCKSZ;
1161+
write_pos = ((int64)blknum) * BLCKSZ;
11621162

11631163
if (cur_pos_out != write_pos)
11641164
{
@@ -1742,7 +1742,7 @@ validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
17421742
elog(ERROR, "Cannot seek block %u of \"%s\": %s",
17431743
blknum, fullpath, strerror(errno));
17441744
else
1745-
elog(INFO, "Seek to %u", headers[n_hdr].pos);
1745+
elog(INFO, "Seek to %ld", headers[n_hdr].pos);
17461746

17471747
cur_pos_in = headers[n_hdr].pos;
17481748
}
@@ -1879,7 +1879,7 @@ validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
18791879
/* read local data file and construct map with block checksums */
18801880
PageState*
18811881
get_checksum_map(const char *fullpath, uint32 checksum_version,
1882-
int n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno)
1882+
int64 n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno)
18831883
{
18841884
PageState *checksum_map = NULL;
18851885
FILE *in = NULL;
@@ -1894,7 +1894,7 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
18941894

18951895
/* truncate up to blocks */
18961896
if (ftruncate(fileno(in), n_blocks * BLCKSZ) != 0)
1897-
elog(ERROR, "Cannot truncate file to blknum %u \"%s\": %s",
1897+
elog(ERROR, "Cannot truncate file to blknum %ld \"%s\": %s",
18981898
n_blocks, fullpath, strerror(errno));
18991899

19001900
setvbuf(in, in_buf, _IOFBF, STDIO_BUFSIZE);
@@ -1948,7 +1948,7 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
19481948
/* return bitmap of valid blocks, bitmap is empty, then NULL is returned */
19491949
datapagemap_t *
19501950
get_lsn_map(const char *fullpath, uint32 checksum_version,
1951-
int n_blocks, XLogRecPtr shift_lsn, BlockNumber segmentno)
1951+
int64 n_blocks, XLogRecPtr shift_lsn, BlockNumber segmentno)
19521952
{
19531953
FILE *in = NULL;
19541954
BlockNumber blknum = 0;
@@ -1965,7 +1965,7 @@ get_lsn_map(const char *fullpath, uint32 checksum_version,
19651965

19661966
/* truncate up to blocks */
19671967
if (ftruncate(fileno(in), n_blocks * BLCKSZ) != 0)
1968-
elog(ERROR, "Cannot truncate file to blknum %u \"%s\": %s",
1968+
elog(ERROR, "Cannot truncate file to blknum %ld \"%s\": %s",
19691969
n_blocks, fullpath, strerror(errno));
19701970

19711971
setvbuf(in, in_buf, _IOFBF, STDIO_BUFSIZE);
@@ -2296,9 +2296,9 @@ copy_pages(const char *to_fullpath, const char *from_fullpath,
22962296

22972297
else if (rc == PageIsOk)
22982298
{
2299-
if (fseek(out, blknum * BLCKSZ, SEEK_SET) != 0)
2300-
elog(ERROR, "Cannot seek to position %u in destination file \"%s\": %s",
2301-
blknum * BLCKSZ, to_fullpath, strerror(errno));
2299+
if (fseek(out, ((int64)blknum) * BLCKSZ, SEEK_SET) != 0)
2300+
elog(ERROR, "Cannot seek to position %ld in destination file \"%s\": %s",
2301+
((int64)blknum) * BLCKSZ, to_fullpath, strerror(errno));
23022302

23032303
if (write_page(file, out, curr_page) != BLCKSZ)
23042304
elog(ERROR, "File: \"%s\", cannot write at block %u: %s",

src/pg_probackup.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ typedef struct pgFile
267267
Oid relOid; /* relOid extracted from path, if applicable */
268268
ForkName forkName; /* forkName extracted from path, if applicable */
269269
int segno; /* Segment number for ptrack */
270-
int n_blocks; /* number of blocks in the data file in data directory */
270+
int64 n_blocks; /* number of blocks in the data file in data directory */
271271
bool is_cfs; /* Flag to distinguish files compressed by CFS*/
272272
int external_dir_num; /* Number of external directory. 0 if not external */
273273
bool exists_in_prev; /* Mark files, both data and regular, that exists in previous backup */
@@ -677,8 +677,8 @@ typedef struct BackupPageHeader
677677
typedef struct BackupPageHeader2
678678
{
679679
XLogRecPtr lsn;
680-
int32 block; /* block number */
681-
int32 pos; /* position in backup file */
680+
int64 block; /* block number */
681+
int64 pos; /* position in backup file */
682682
uint16 checksum;
683683
} BackupPageHeader2;
684684

@@ -1115,9 +1115,9 @@ extern bool create_empty_file(fio_location from_location, const char *to_root,
11151115
fio_location to_location, pgFile *file);
11161116

11171117
extern PageState *get_checksum_map(const char *fullpath, uint32 checksum_version,
1118-
int n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno);
1118+
int64 n_blocks, XLogRecPtr dest_stop_lsn, BlockNumber segmentno);
11191119
extern datapagemap_t *get_lsn_map(const char *fullpath, uint32 checksum_version,
1120-
int n_blocks, XLogRecPtr shift_lsn, BlockNumber segmentno);
1120+
int64 n_blocks, XLogRecPtr shift_lsn, BlockNumber segmentno);
11211121
extern bool validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
11221122
uint32 checksum_version, uint32 backup_version, HeaderMap *hdr_map);
11231123

src/utils/file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ fio_copy_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file,
21382138

21392139
COMP_FILE_CRC32(true, file->crc, buf, hdr.size);
21402140

2141-
if (fio_fseek(out, blknum * BLCKSZ) < 0)
2141+
if (fio_fseek(out, ((int64)blknum) * BLCKSZ) < 0)
21422142
{
21432143
elog(ERROR, "Cannot seek block %u of \"%s\": %s",
21442144
blknum, to_fullpath, strerror(errno));
@@ -2196,7 +2196,7 @@ fio_send_pages_impl(int out, char* buf)
21962196
datapagemap_iterator_t *iter = NULL;
21972197
/* page headers */
21982198
int32 hdr_num = -1;
2199-
int32 cur_pos_out = 0;
2199+
int64 cur_pos_out = 0;
22002200
BackupPageHeader2 *headers = NULL;
22012201

22022202
/* open source file */

0 commit comments

Comments
 (0)