@@ -89,7 +89,7 @@ do_compress(void* dst, size_t dst_size, void const* src, size_t src_size,
89
89
* Decompresses source into dest using algorithm. Returns the number of bytes
90
90
* decompressed in the destination buffer, or -1 if decompression fails.
91
91
*/
92
- static int32
92
+ int32
93
93
do_decompress (void * dst , size_t dst_size , void const * src , size_t src_size ,
94
94
CompressAlg alg , const char * * errormsg )
95
95
{
@@ -1047,9 +1047,9 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
1047
1047
{
1048
1048
off_t write_pos ;
1049
1049
size_t read_len ;
1050
- DataPage compressed_page ; /* used as read buffer */
1051
1050
DataPage page ;
1052
- int32 uncompressed_size = 0 ;
1051
+ int32 compressed_size = 0 ;
1052
+ bool is_compressed = false;
1053
1053
1054
1054
/* check for interrupt */
1055
1055
if (interrupted || thread_interrupted )
@@ -1090,14 +1090,16 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
1090
1090
* n_blocks attribute was available only in DELTA backups.
1091
1091
* File truncate in PAGE and PTRACK happened on the fly when
1092
1092
* special value PageIsTruncated is encountered.
1093
- * It is inefficient.
1093
+ * It was inefficient.
1094
1094
*
1095
1095
* Nowadays every backup type has n_blocks, so instead
1096
1096
* writing and then truncating redundant data, writing
1097
1097
* is not happening in the first place.
1098
1098
* TODO: remove in 3.0.0
1099
1099
*/
1100
- if (header .compressed_size == PageIsTruncated )
1100
+ compressed_size = header .compressed_size ;
1101
+
1102
+ if (compressed_size == PageIsTruncated )
1101
1103
{
1102
1104
/*
1103
1105
* Block header contains information that this block was truncated.
@@ -1124,16 +1126,15 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
1124
1126
if (nblocks > 0 && blknum >= nblocks )
1125
1127
break ;
1126
1128
1127
- if (header . compressed_size > BLCKSZ )
1129
+ if (compressed_size > BLCKSZ )
1128
1130
elog (ERROR , "Size of a blknum %i exceed BLCKSZ" , blknum );
1129
1131
1130
1132
/* read a page from file */
1131
- read_len = fread (compressed_page .data , 1 ,
1132
- MAXALIGN (header .compressed_size ), in );
1133
+ read_len = fread (page .data , 1 , MAXALIGN (compressed_size ), in );
1133
1134
1134
- if (read_len != MAXALIGN (header . compressed_size ))
1135
+ if (read_len != MAXALIGN (compressed_size ))
1135
1136
elog (ERROR , "Cannot read block %u of \"%s\", read %zu of %d" ,
1136
- blknum , from_fullpath , read_len , header . compressed_size );
1137
+ blknum , from_fullpath , read_len , compressed_size );
1137
1138
1138
1139
/*
1139
1140
* if page size is smaller than BLCKSZ, decompress the page.
@@ -1142,23 +1143,10 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
1142
1143
* page_may_be_compressed() function.
1143
1144
*/
1144
1145
if (header .compressed_size != BLCKSZ
1145
- || page_may_be_compressed (compressed_page .data , file -> compress_alg ,
1146
+ || page_may_be_compressed (page .data , file -> compress_alg ,
1146
1147
backup_version ))
1147
1148
{
1148
- const char * errormsg = NULL ;
1149
-
1150
- uncompressed_size = do_decompress (page .data , BLCKSZ ,
1151
- compressed_page .data ,
1152
- header .compressed_size ,
1153
- file -> compress_alg , & errormsg );
1154
-
1155
- if (uncompressed_size < 0 && errormsg != NULL )
1156
- elog (WARNING , "An error occured during decompressing block %u of file \"%s\": %s" ,
1157
- blknum , from_fullpath , errormsg );
1158
-
1159
- if (uncompressed_size != BLCKSZ )
1160
- elog (ERROR , "Page of file \"%s\" uncompressed to %d bytes. != BLCKSZ" ,
1161
- from_fullpath , uncompressed_size );
1149
+ is_compressed = true;
1162
1150
}
1163
1151
1164
1152
write_pos = blknum * BLCKSZ ;
@@ -1170,19 +1158,21 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
1170
1158
elog (ERROR , "Cannot seek block %u of \"%s\": %s" ,
1171
1159
blknum , to_fullpath , strerror (errno ));
1172
1160
1173
- /* if we uncompressed the page - write page.data,
1174
- * if page wasn't compressed -
1175
- * write what we've read - compressed_page.data
1161
+ /* If page is compressed and restore is in remote mode, send compressed
1162
+ * page to the remote side.
1176
1163
*/
1177
- if (uncompressed_size == BLCKSZ )
1164
+ if (is_compressed )
1178
1165
{
1179
- if (fio_fwrite (out , page .data , BLCKSZ ) != BLCKSZ )
1180
- elog (ERROR , "Cannot write block %u of \"%s\": %s" ,
1181
- blknum , to_fullpath , strerror (errno ));
1166
+ ssize_t rc ;
1167
+ rc = fio_fwrite_compressed (out , page .data , compressed_size , file -> compress_alg );
1168
+
1169
+ if (!fio_is_remote_file (out ) && rc != BLCKSZ )
1170
+ elog (ERROR , "Cannot write block %u of \"%s\": %s, size: %u" ,
1171
+ blknum , to_fullpath , strerror (errno ), compressed_size );
1182
1172
}
1183
1173
else
1184
1174
{
1185
- if (fio_fwrite (out , compressed_page .data , BLCKSZ ) != BLCKSZ )
1175
+ if (fio_fwrite (out , page .data , BLCKSZ ) != BLCKSZ )
1186
1176
elog (ERROR , "Cannot write block %u of \"%s\": %s" ,
1187
1177
blknum , to_fullpath , strerror (errno ));
1188
1178
}
0 commit comments