@@ -872,9 +872,10 @@ int fio_send_pages(FILE* in, FILE* out, pgFile *file,
872872req .arg .calg = calg ;
873873req .arg .clevel = clevel ;
874874
875- IO_CHECK (fio_write_all (fio_stdout ,& req ,sizeof (req )),sizeof (req ));
876875file -> compress_alg = calg ;
877876
877+ IO_CHECK (fio_write_all (fio_stdout ,& req ,sizeof (req )),sizeof (req ));
878+
878879while (true)
879880{
880881fio_header hdr ;
@@ -887,24 +888,7 @@ int fio_send_pages(FILE* in, FILE* out, pgFile *file,
887888
888889blknum = hdr .arg ;
889890if (hdr .size == 0 )/* end of segment */
890- {
891- if (n_blocks_read == 0 )
892- {
893- BackupPageHeader ph ;
894- ph .block = blknum ;
895- ph .compressed_size = 0 ;
896- if (fio_fwrite (out ,& ph ,sizeof ph )!= sizeof (ph ))
897- {
898- int errno_tmp = errno ;
899- fio_fclose (out );
900- elog (ERROR ,"File: %s, cannot write backup at block %u: %s" ,
901- file -> path ,blknum ,strerror (errno_tmp ));
902- }
903- n_blocks_read ++ ;
904- file -> write_size = sizeof (ph );
905- }
906891break ;
907- }
908892
909893Assert (hdr .size <=sizeof (buf ));
910894IO_CHECK (fio_read_all (fio_stdin ,buf ,hdr .size ),hdr .size );
@@ -918,9 +902,15 @@ int fio_send_pages(FILE* in, FILE* out, pgFile *file,
918902elog (ERROR ,"File: %s, cannot write backup at block %u: %s" ,
919903file -> path ,blknum ,strerror (errno_tmp ));
920904}
921- file -> read_size += BLCKSZ ;
922905file -> write_size += hdr .size ;
923906n_blocks_read ++ ;
907+
908+ if (((BackupPageHeader * )buf )-> compressed_size == PageIsTruncated )
909+ {
910+ blknum += 1 ;
911+ break ;
912+ }
913+ file -> read_size += BLCKSZ ;
924914}
925915* nBlocksSkipped = blknum - n_blocks_read ;
926916return blknum ;
@@ -939,25 +929,30 @@ static void fio_send_pages_impl(int fd, int out, fio_send_request* req)
939929{
940930int retry_attempts = PAGE_READ_ATTEMPTS ;
941931XLogRecPtr page_lsn = InvalidXLogRecPtr ;
942- bool is_empty_page = false;
943- do
932+
933+ while (true)
944934{
945935ssize_t rc = pread (fd ,read_buffer ,BLCKSZ ,blknum * BLCKSZ );
946936
947937if (rc <=0 )
948938{
949- hdr .size = 0 ;
950939if (rc < 0 )
951940{
952941hdr .arg = - errno ;
942+ hdr .size = 0 ;
953943Assert (hdr .arg < 0 );
944+ IO_CHECK (fio_write_all (out ,& hdr ,sizeof (hdr )),sizeof (hdr ));
954945}
955946else
956947{
957- /* This is the last page */
948+ BackupPageHeader bph ;
949+ bph .block = blknum ;
950+ bph .compressed_size = PageIsTruncated ;
958951hdr .arg = blknum ;
952+ hdr .size = sizeof (bph );
953+ IO_CHECK (fio_write_all (out ,& hdr ,sizeof (hdr )),sizeof (hdr ));
954+ IO_CHECK (fio_write_all (out ,& bph ,sizeof (bph )),sizeof (bph ));
959955}
960- IO_CHECK (fio_write_all (out ,& hdr ,sizeof (hdr )),sizeof (hdr ));
961956return ;
962957}
963958else if (rc == BLCKSZ )
@@ -969,53 +964,44 @@ static void fio_send_pages_impl(int fd, int out, fio_send_request* req)
969964
970965/* Page is zeroed. No need to check header and checksum. */
971966if (i == BLCKSZ )
972- {
973- is_empty_page = true;
974967break ;
975- }
976968}
977969else if (!req -> checksumVersion
978970|| pg_checksum_page (read_buffer ,req -> segBlockNum + blknum )== ((PageHeader )read_buffer )-> pd_checksum )
979971{
980972break ;
981973}
982974}
983- }while (-- retry_attempts != 0 );
984975
985- if (retry_attempts == 0 )
986- {
987- hdr .size = 0 ;
988- hdr .arg = PAGE_CHECKSUM_MISMATCH ;
989- IO_CHECK (fio_write_all (out ,& hdr ,sizeof (hdr )),sizeof (hdr ));
990- return ;
976+ if (-- retry_attempts == 0 )
977+ {
978+ hdr .size = 0 ;
979+ hdr .arg = PAGE_CHECKSUM_MISMATCH ;
980+ IO_CHECK (fio_write_all (out ,& hdr ,sizeof (hdr )),sizeof (hdr ));
981+ return ;
982+ }
991983}
992984/* horizonLsn is not 0 for delta backup. As far as unsigned number are always greater or equal than zero, there is no sense to add more checks */
993985if (page_lsn >=req -> horizonLsn )
994986{
995987char write_buffer [BLCKSZ * 2 ];
996988BackupPageHeader * bph = (BackupPageHeader * )write_buffer ;
989+ const char * errormsg = NULL ;
997990
998991hdr .arg = bph -> block = blknum ;
999992hdr .size = sizeof (BackupPageHeader );
1000993
1001- if (is_empty_page )
994+ bph -> compressed_size = do_compress (write_buffer + sizeof (BackupPageHeader ),sizeof (write_buffer )- sizeof (BackupPageHeader ),
995+ read_buffer ,BLCKSZ ,req -> calg ,req -> clevel ,
996+ & errormsg );
997+ if (bph -> compressed_size <=0 || bph -> compressed_size >=BLCKSZ )
1002998{
1003- bph -> compressed_size = PageIsTruncated ;
1004- }
1005- else
1006- {
1007- const char * errormsg = NULL ;
1008- bph -> compressed_size = do_compress (write_buffer + sizeof (BackupPageHeader ),sizeof (write_buffer )- sizeof (BackupPageHeader ),
1009- read_buffer ,BLCKSZ ,req -> calg ,req -> clevel ,
1010- & errormsg );
1011- if (bph -> compressed_size <=0 || bph -> compressed_size >=BLCKSZ )
1012- {
1013- /* Do not compress page */
1014- memcpy (write_buffer + sizeof (BackupPageHeader ),read_buffer ,BLCKSZ );
1015- bph -> compressed_size = BLCKSZ ;
1016- }
1017- hdr .size += MAXALIGN (bph -> compressed_size );
999+ /* Do not compress page */
1000+ memcpy (write_buffer + sizeof (BackupPageHeader ),read_buffer ,BLCKSZ );
1001+ bph -> compressed_size = BLCKSZ ;
10181002}
1003+ hdr .size += MAXALIGN (bph -> compressed_size );
1004+
10191005IO_CHECK (fio_write_all (out ,& hdr ,sizeof (hdr )),sizeof (hdr ));
10201006IO_CHECK (fio_write_all (out ,write_buffer ,hdr .size ),hdr .size );
10211007}