mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-12-11 11:41:33 +02:00
truncate restored files when necessary
This commit is contained in:
parent
07a1630a65
commit
ac195f47b6
24
src/data.c
24
src/data.c
@ -129,7 +129,7 @@ parse_page(Page page, XLogRecPtr *lsn)
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
read_page_from_file(pgFile *file, BlockNumber blknum,
|
read_page_from_file(pgFile *file, BlockNumber blknum,
|
||||||
FILE *in, FILE *out, Page page)
|
FILE *in, Page page)
|
||||||
{
|
{
|
||||||
off_t offset = blknum*BLCKSZ;
|
off_t offset = blknum*BLCKSZ;
|
||||||
size_t read_len = 0;
|
size_t read_len = 0;
|
||||||
@ -227,7 +227,7 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
|
|||||||
{
|
{
|
||||||
BackupPageHeader header;
|
BackupPageHeader header;
|
||||||
Page page = malloc(BLCKSZ);
|
Page page = malloc(BLCKSZ);
|
||||||
Page compressed_page;
|
Page compressed_page = NULL;
|
||||||
size_t write_buffer_size;
|
size_t write_buffer_size;
|
||||||
char write_buffer[BLCKSZ+sizeof(header)];
|
char write_buffer[BLCKSZ+sizeof(header)];
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
|
|||||||
while(!page_is_valid && try_again)
|
while(!page_is_valid && try_again)
|
||||||
{
|
{
|
||||||
int result = read_page_from_file(file, blknum,
|
int result = read_page_from_file(file, blknum,
|
||||||
in, out, page);
|
in, page);
|
||||||
|
|
||||||
try_again--;
|
try_again--;
|
||||||
/* This block was truncated.*/
|
/* This block was truncated.*/
|
||||||
@ -275,14 +275,17 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
|
|||||||
/* This block was truncated.*/
|
/* This block was truncated.*/
|
||||||
header.compressed_size = -1;
|
header.compressed_size = -1;
|
||||||
}
|
}
|
||||||
|
else if (page_size != BLCKSZ)
|
||||||
if (page_size != BLCKSZ)
|
{
|
||||||
elog(ERROR, "File: %s, block %u, expected block size %lu,"
|
elog(ERROR, "File: %s, block %u, expected block size %lu,"
|
||||||
"but read %d, try again",
|
"but read %d, try again",
|
||||||
file->path, absolute_blknum, page_size, BLCKSZ);
|
file->path, absolute_blknum, page_size, BLCKSZ);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
((PageHeader) page)->pd_checksum = pg_checksum_page(page, absolute_blknum);
|
((PageHeader) page)->pd_checksum = pg_checksum_page(page, absolute_blknum);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (header.compressed_size != -1)
|
if (header.compressed_size != -1)
|
||||||
{
|
{
|
||||||
@ -335,7 +338,9 @@ backup_data_page(pgFile *file, XLogRecPtr prev_backup_start_lsn,
|
|||||||
|
|
||||||
file->write_size += write_buffer_size;
|
file->write_size += write_buffer_size;
|
||||||
|
|
||||||
|
if (page != NULL)
|
||||||
free(page);
|
free(page);
|
||||||
|
if (compressed_page != NULL)
|
||||||
free(compressed_page);
|
free(compressed_page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,6 +568,8 @@ restore_data_file(const char *from_root,
|
|||||||
if (header.block < blknum)
|
if (header.block < blknum)
|
||||||
elog(ERROR, "backup is broken at block %u", blknum);
|
elog(ERROR, "backup is broken at block %u", blknum);
|
||||||
|
|
||||||
|
if (header.compressed_size != -1)
|
||||||
|
{
|
||||||
//elog(VERBOSE, "file %s, header compressed size %d", file->path, header.compressed_size);
|
//elog(VERBOSE, "file %s, header compressed size %d", file->path, header.compressed_size);
|
||||||
Assert(header.compressed_size <= BLCKSZ);
|
Assert(header.compressed_size <= BLCKSZ);
|
||||||
|
|
||||||
@ -572,7 +579,7 @@ restore_data_file(const char *from_root,
|
|||||||
elog(ERROR, "cannot read block %u of \"%s\" read %lu of %d",
|
elog(ERROR, "cannot read block %u of \"%s\" read %lu of %d",
|
||||||
blknum, file->path, read_len, header.compressed_size);
|
blknum, file->path, read_len, header.compressed_size);
|
||||||
|
|
||||||
if (header.compressed_size < BLCKSZ)
|
if (header.compressed_size != BLCKSZ)
|
||||||
{
|
{
|
||||||
size_t uncompressed_size = 0;
|
size_t uncompressed_size = 0;
|
||||||
|
|
||||||
@ -583,6 +590,7 @@ restore_data_file(const char *from_root,
|
|||||||
if (uncompressed_size != BLCKSZ)
|
if (uncompressed_size != BLCKSZ)
|
||||||
elog(ERROR, "page uncompressed to %ld bytes. != BLCKSZ", uncompressed_size);
|
elog(ERROR, "page uncompressed to %ld bytes. != BLCKSZ", uncompressed_size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Seek and write the restored page.
|
* Seek and write the restored page.
|
||||||
@ -598,7 +606,7 @@ restore_data_file(const char *from_root,
|
|||||||
* Backup contains information that this block was truncated.
|
* Backup contains information that this block was truncated.
|
||||||
* Truncate file to this length.
|
* Truncate file to this length.
|
||||||
*/
|
*/
|
||||||
ftruncate(out, blknum * BLCKSZ);
|
ftruncate(fileno(out), blknum * BLCKSZ);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (header.compressed_size < BLCKSZ)
|
else if (header.compressed_size < BLCKSZ)
|
||||||
|
Loading…
Reference in New Issue
Block a user