@@ -823,10 +823,11 @@ restore_data_file(parray *parent_chain, pgFile *dest_file, FILE *out,
823
823
/* get headers for this file */
824
824
if (use_headers && tmp_file -> n_headers > 0 )
825
825
headers = get_data_file_headers (& (backup -> hdr_map ), tmp_file ,
826
- parse_program_version (backup -> program_version ));
826
+ parse_program_version (backup -> program_version ),
827
+ true);
827
828
828
829
if (use_headers && !headers && tmp_file -> n_headers > 0 )
829
- elog (ERROR , "Failed to get headers for file \"%s\"" , from_fullpath );
830
+ elog (ERROR , "Failed to get page headers for file \"%s\"" , from_fullpath );
830
831
831
832
/*
832
833
* Restore the file.
@@ -1599,10 +1600,13 @@ validate_file_pages(pgFile *file, const char *fullpath, XLogRecPtr stop_lsn,
1599
1600
elog (ERROR , "Cannot open file \"%s\": %s" ,
1600
1601
fullpath , strerror (errno ));
1601
1602
1602
- headers = get_data_file_headers (hdr_map , file , backup_version );
1603
+ headers = get_data_file_headers (hdr_map , file , backup_version , false );
1603
1604
1604
1605
if (!headers && file -> n_headers > 0 )
1605
- elog (ERROR , "Failed to get headers for file \"%s\"" , fullpath );
1606
+ {
1607
+ elog (WARNING , "Cannot get page headers for file \"%s\"" , fullpath );
1608
+ return false;
1609
+ }
1606
1610
1607
1611
/* calc CRC of backup file */
1608
1612
INIT_FILE_CRC32 (use_crc32c , crc );
@@ -2124,8 +2128,9 @@ send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const char *from_f
2124
2128
* array of headers.
2125
2129
*/
2126
2130
BackupPageHeader2 *
2127
- get_data_file_headers (HeaderMap * hdr_map , pgFile * file , uint32 backup_version )
2131
+ get_data_file_headers (HeaderMap * hdr_map , pgFile * file , uint32 backup_version , bool strict )
2128
2132
{
2133
+ bool success = false;
2129
2134
FILE * in = NULL ;
2130
2135
size_t read_len = 0 ;
2131
2136
pg_crc32 hdr_crc ;
@@ -2145,42 +2150,55 @@ get_data_file_headers(HeaderMap *hdr_map, pgFile *file, uint32 backup_version)
2145
2150
in = fopen (hdr_map -> path , PG_BINARY_R );
2146
2151
2147
2152
if (!in )
2148
- elog (ERROR , "Cannot open header file \"%s\": %s" , hdr_map -> path , strerror (errno ));
2153
+ {
2154
+ elog (strict ? ERROR : WARNING , "Cannot open header file \"%s\": %s" , hdr_map -> path , strerror (errno ));
2155
+ return NULL ;
2156
+ }
2149
2157
/* disable buffering for header file */
2150
2158
setvbuf (in , NULL , _IONBF , BUFSIZ );
2151
2159
2152
2160
if (fseek (in , file -> hdr_off , SEEK_SET ))
2153
- elog (ERROR , "Cannot seek to position %lu in page header map \"%s\": %s" ,
2161
+ {
2162
+ elog (strict ? ERROR : WARNING , "Cannot seek to position %lu in page header map \"%s\": %s" ,
2154
2163
file -> hdr_off , hdr_map -> path , strerror (errno ));
2164
+ goto cleanup ;
2165
+ }
2155
2166
2156
2167
/*
2157
2168
* The actual number of headers in header file is n+1, last one is a dummy header,
2158
2169
* used for calculation of read_len for actual last header.
2159
2170
*/
2160
2171
read_len = (file -> n_headers + 1 ) * sizeof (BackupPageHeader2 );
2161
2172
2162
- /* allocate memory for compressed and uncompressed headers */
2163
- headers = pgut_malloc (read_len );
2164
- memset (headers , 0 , read_len );
2173
+ /* allocate memory for compressed headers */
2165
2174
zheaders = pgut_malloc (file -> hdr_size );
2166
2175
memset (zheaders , 0 , file -> hdr_size );
2167
2176
2168
2177
if (fread (zheaders , 1 , file -> hdr_size , in ) != file -> hdr_size )
2169
- elog (ERROR , "Cannot read header file at offset: %li len: %i \"%s\": %s" ,
2178
+ {
2179
+ elog (strict ? ERROR : WARNING , "Cannot read header file at offset: %li len: %i \"%s\": %s" ,
2170
2180
file -> hdr_off , file -> hdr_size , hdr_map -> path , strerror (errno ));
2181
+ goto cleanup ;
2182
+ }
2171
2183
2172
2184
// elog(INFO, "zsize: %i, size: %i", file->hdr_size, read_len);
2173
2185
2186
+ /* allocate memory for uncompressed headers */
2187
+ headers = pgut_malloc (read_len );
2188
+ memset (headers , 0 , read_len );
2189
+
2174
2190
z_len = do_decompress (headers , read_len , zheaders , file -> hdr_size ,
2175
2191
ZLIB_COMPRESS , & errormsg );
2176
2192
if (z_len <= 0 )
2177
2193
{
2178
2194
if (errormsg )
2179
- elog (ERROR , "An error occured during metadata decompression for file \"%s\": %s" ,
2195
+ elog (strict ? ERROR : WARNING , "An error occured during metadata decompression for file \"%s\": %s" ,
2180
2196
file -> rel_path , errormsg );
2181
2197
else
2182
- elog (ERROR , "An error occured during metadata decompression for file \"%s\": %i" ,
2198
+ elog (strict ? ERROR : WARNING , "An error occured during metadata decompression for file \"%s\": %i" ,
2183
2199
file -> rel_path , z_len );
2200
+
2201
+ goto cleanup ;
2184
2202
}
2185
2203
2186
2204
/* validate checksum */
@@ -2189,13 +2207,26 @@ get_data_file_headers(HeaderMap *hdr_map, pgFile *file, uint32 backup_version)
2189
2207
FIN_FILE_CRC32 (true, hdr_crc );
2190
2208
2191
2209
if (hdr_crc != file -> hdr_crc )
2192
- elog (ERROR , "Header map for file \"%s\" crc mismatch \"%s\" offset: %lu, len: %lu, current: %u, expected: %u" ,
2210
+ {
2211
+ elog (strict ? ERROR : WARNING , "Header map for file \"%s\" crc mismatch \"%s\" "
2212
+ "offset: %lu, len: %lu, current: %u, expected: %u" ,
2193
2213
file -> rel_path , hdr_map -> path , file -> hdr_off , read_len , hdr_crc , file -> hdr_crc );
2214
+ goto cleanup ;
2215
+ }
2194
2216
2195
- if (fclose (in ))
2196
- elog (ERROR , "Cannot close file \"%s\"" , hdr_map -> path );
2217
+ success = true;
2218
+
2219
+ cleanup :
2197
2220
2198
2221
pg_free (zheaders );
2222
+ if (in && fclose (in ))
2223
+ elog (ERROR , "Cannot close file \"%s\"" , hdr_map -> path );
2224
+
2225
+ if (!success )
2226
+ {
2227
+ pg_free (headers );
2228
+ headers = NULL ;
2229
+ }
2199
2230
2200
2231
return headers ;
2201
2232
}
0 commit comments