Skip to content

Commit 4995652

Browse files
committed
fix decompression of BLCKSZ pages
1 parent 12a6dcd commit 4995652

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/data.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
722722
size_t read_len;
723723
DataPage compressed_page; /* used as read buffer */
724724
DataPage page;
725+
int32 uncompressed_size = 0;
725726

726727
/* File didn`t changed. Nothig to copy */
727728
if (file->write_size == BYTES_INVALID)
@@ -777,17 +778,23 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
777778

778779
Assert(header.compressed_size <= BLCKSZ);
779780

781+
/* read a page from file */
780782
read_len = fread(compressed_page.data, 1,
781783
MAXALIGN(header.compressed_size), in);
782784
if (read_len != MAXALIGN(header.compressed_size))
783785
elog(ERROR, "cannot read block %u of \"%s\" read %lu of %d",
784786
blknum, file->path, read_len, header.compressed_size);
785787

788+
/*
789+
* if page size is smaller than BLCKSZ, decompress the page.
790+
* BUGFIX for versions < 2.0.23: if page size is equal to BLCKSZ.
791+
* we have to check, whether it is compressed or not using
792+
* page_may_be_compressed() function.
793+
*/
786794
if (header.compressed_size != BLCKSZ
787795
|| page_may_be_compressed(compressed_page.data, file->compress_alg,
788796
backup_version))
789797
{
790-
int32 uncompressed_size = 0;
791798
const char *errormsg = NULL;
792799

793800
uncompressed_size = do_decompress(page.data, BLCKSZ,
@@ -820,15 +827,19 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
820827
blknum, file->path, strerror(errno));
821828
}
822829

823-
if (header.compressed_size < BLCKSZ)
830+
/* if we uncompressed the page - write page.data,
831+
* if page wasn't compressed -
832+
* write what we've read - compressed_page.data
833+
*/
834+
if (uncompressed_size == BLCKSZ)
824835
{
825836
if (fwrite(page.data, 1, BLCKSZ, out) != BLCKSZ)
826837
elog(ERROR, "cannot write block %u of \"%s\": %s",
827838
blknum, file->path, strerror(errno));
828839
}
829840
else
830841
{
831-
/* if page wasn't compressed, we've read full block */
842+
/* */
832843
if (fwrite(compressed_page.data, 1, BLCKSZ, out) != BLCKSZ)
833844
elog(ERROR, "cannot write block %u of \"%s\": %s",
834845
blknum, file->path, strerror(errno));

0 commit comments

Comments
 (0)