@@ -31,8 +31,6 @@ typedef struct DataPage
3131 char data [BLCKSZ ];
3232} DataPage ;
3333
34- static BackupPageHeader2 * get_data_file_headers (HeaderMap * hdr_map , pgFile * file , uint32 backup_version );
35- static void write_page_headers (BackupPageHeader2 * headers , pgFile * file , HeaderMap * hdr_map );
3634static bool get_compressed_page_meta (FILE * in , const char * fullpath , BackupPageHeader * bph ,
3735 pg_crc32 * crc , bool use_crc32c );
3836
@@ -538,7 +536,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
538536 XLogRecPtr prev_backup_start_lsn , BackupMode backup_mode ,
539537 CompressAlg calg , int clevel , uint32 checksum_version ,
540538 int ptrack_version_num , const char * ptrack_schema ,
541- HeaderMap * hdr_map , bool missing_ok )
539+ HeaderMap * hdr_map , bool is_merge )
542540{
543541 int rc ;
544542 bool use_pagemap ;
@@ -629,7 +627,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
629627 /* check for errors */
630628 if (rc == FILE_MISSING )
631629 {
632- elog (LOG , "File \"%s\" is not found " , from_fullpath );
630+ elog (is_merge ? ERROR : LOG , "File not found: \"%s\"" , from_fullpath );
633631 file -> write_size = FILE_NOT_FOUND ;
634632 goto cleanup ;
635633 }
@@ -685,7 +683,7 @@ backup_data_file(ConnectionArgs* conn_arg, pgFile *file,
685683 FIN_FILE_CRC32 (true, file -> crc );
686684
687685 /* dump page headers */
688- write_page_headers (headers , file , hdr_map );
686+ write_page_headers (headers , file , hdr_map , is_merge );
689687
690688 pg_free (errmsg );
691689 pg_free (file -> pagemap .bitmap );
@@ -818,8 +816,12 @@ restore_data_file(parray *parent_chain, pgFile *dest_file, FILE *out,
818816 /* set stdio buffering for input data file */
819817 setvbuf (in , in_buf , _IOFBF , STDIO_BUFSIZE );
820818
819+ // elog(INFO, "N_HEADERS: %i", tmp_file->n_headers);
820+ // elog(INFO, "File: %s", tmp_file->rel_path);
821+ // elog(INFO, "Backup: %s", base36enc(backup->start_time));
822+
821823 /* get headers for this file */
822- if (use_headers )
824+ if (use_headers && tmp_file -> n_headers > 0 )
823825 headers = get_data_file_headers (& (backup -> hdr_map ), tmp_file ,
824826 parse_program_version (backup -> program_version ));
825827
@@ -2163,8 +2165,8 @@ get_data_file_headers(HeaderMap *hdr_map, pgFile *file, uint32 backup_version)
21632165 FIN_FILE_CRC32 (true, hdr_crc );
21642166
21652167 if (hdr_crc != file -> hdr_crc )
2166- elog (ERROR , "Header file crc mismatch \"%s\", current: %u, expected: %u" ,
2167- hdr_map -> path , hdr_crc , file -> hdr_crc );
2168+ elog (ERROR , "Header map for file \"%s\" crc mismatch \"%s\" offset: %lu, len: %lu , current: %u, expected: %u" ,
2169+ file -> rel_path , hdr_map -> path , file -> hdr_off , read_len , hdr_crc , file -> hdr_crc );
21682170
21692171 if (fclose (in ))
21702172 elog (ERROR , "Cannot close header file \"%s\": %s" , hdr_map -> path , strerror (errno ));
@@ -2173,29 +2175,35 @@ get_data_file_headers(HeaderMap *hdr_map, pgFile *file, uint32 backup_version)
21732175}
21742176
21752177void
2176- write_page_headers (BackupPageHeader2 * headers , pgFile * file , HeaderMap * hdr_map )
2178+ write_page_headers (BackupPageHeader2 * headers , pgFile * file , HeaderMap * hdr_map , bool is_merge )
21772179{
2178- size_t read_len = 0 ;
2180+ size_t read_len = 0 ;
2181+ char * map_path = NULL ;
21792182
21802183 if (file -> n_headers <= 0 )
21812184 return ;
21822185
2186+ /* when running merge we must save headers into the temp map */
2187+ map_path = (is_merge ) ? hdr_map -> path_tmp : hdr_map -> path ;
2188+
21832189 /* writing to header map must be serialized */
21842190 pthread_lock (& (hdr_map -> mutex )); /* what if we crash while trying to obtain mutex? */
21852191
21862192 if (!hdr_map -> fp )
21872193 {
2188- hdr_map -> fp = fopen (hdr_map -> path , PG_BINARY_W );
2194+ elog (LOG , "Creating page header map \"%s\"" , map_path );
2195+
2196+ hdr_map -> fp = fopen (map_path , PG_BINARY_W );
21892197 if (hdr_map -> fp == NULL )
21902198 elog (ERROR , "Cannot open header file \"%s\": %s" ,
2191- hdr_map -> path , strerror (errno ));
2199+ map_path , strerror (errno ));
21922200
21932201 /* disable buffering for header file */
21942202 setvbuf (hdr_map -> fp , NULL , _IONBF , BUFSIZ );
21952203
21962204 /* update file permission */
2197- if (chmod (hdr_map -> path , FILE_PERMISSION ) == -1 )
2198- elog (ERROR , "Cannot change mode of \"%s\": %s" , hdr_map -> path ,
2205+ if (chmod (map_path , FILE_PERMISSION ) == -1 )
2206+ elog (ERROR , "Cannot change mode of \"%s\": %s" , map_path ,
21992207 strerror (errno ));
22002208
22012209 file -> hdr_off = 0 ;
@@ -2211,7 +2219,10 @@ write_page_headers(BackupPageHeader2 *headers, pgFile *file, HeaderMap *hdr_map)
22112219 FIN_FILE_CRC32 (true, file -> hdr_crc );
22122220
22132221 if (fwrite (headers , 1 , read_len , hdr_map -> fp ) != read_len )
2214- elog (ERROR , "Cannot write to file \"%s\": %s" , hdr_map -> path , strerror (errno ));
2222+ elog (ERROR , "Cannot write to file \"%s\": %s" , map_path , strerror (errno ));
2223+
2224+ elog (VERBOSE , "Writing header map for file \"%s\" offset: %lu, len: %lu, crc: %u" ,
2225+ file -> rel_path , file -> hdr_off , read_len , file -> hdr_crc );
22152226
22162227 pthread_mutex_unlock (& (hdr_map -> mutex ));
22172228}
0 commit comments