Skip to content

Commit 547470a

Browse files
committed
check size of the file if block reading has failed
1 parent be18e8d commit 547470a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

data.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ backup_data_page(pgFile *file, const XLogRecPtr *lsn,
6060
XLogRecPtr page_lsn;
6161
int ret;
6262
int try_checksum = 100;
63+
struct stat st;
6364

6465
header.block = blknum;
6566
offset = blknum * BLCKSZ;
@@ -72,9 +73,22 @@ backup_data_page(pgFile *file, const XLogRecPtr *lsn,
7273
(long long unsigned int) offset, ret);
7374

7475
read_len = fread(&page, 1, sizeof(page), in);
76+
7577
if (read_len != sizeof(page))
76-
elog(ERROR, "File: %s, block size of block %u of nblocks %u is incorrect %lu",
78+
{
79+
stat(file->path, &st);
80+
81+
if (st.st_size/BLCKSZ <= blknum)
82+
{
83+
elog(WARNING, "File: %s, file was truncated after backup start."
84+
"Expected nblocks %u. Real nblocks %ld. Cannot read block %u ",
85+
file->path, nblocks, st.st_size/BLCKSZ, blknum);
86+
return;
87+
}
88+
else
89+
elog(ERROR, "File: %s, block size of block %u of nblocks %u is incorrect %lu",
7790
file->path, blknum, nblocks, read_len);
91+
}
7892

7993
/*
8094
* If an invalid data page was found, fallback to simple copy to ensure
@@ -187,7 +201,7 @@ backup_data_file(const char *from_root, const char *to_root,
187201
stat(file->path, &st);
188202

189203
if (st.st_size < file->size)
190-
elog(ERROR, "File: %s, file was truncated after backup start. Expected size %lu",
204+
elog(WARNING, "File: %s, file was truncated after backup start. Expected size %lu",
191205
file->path, file->size);
192206

193207
if (file->size % BLCKSZ != 0)
@@ -456,8 +470,6 @@ restore_data_file(const char *from_root,
456470
{
457471
size_t read_len;
458472
DataPage page; /* used as read buffer */
459-
int upper_offset;
460-
int upper_length;
461473

462474
/* read BackupPageHeader */
463475
read_len = fread(&header, 1, sizeof(header), in);
@@ -502,8 +514,6 @@ restore_data_file(const char *from_root,
502514
((PageHeader) page.data)->pd_checksum = pg_checksum_page(page.data, file->segno * RELSEG_SIZE + header.block);
503515
}
504516

505-
skip_checksum:
506-
507517
/*
508518
* Seek and write the restored page. Backup might have holes in
509519
* differential backups.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy