@@ -418,43 +418,55 @@ prepare_page(ConnectionArgs *conn_arg,
418418 && (ptrack_version_num >= 15 && ptrack_version_num < 20 ))
419419 || !page_is_valid )
420420 {
421+ int rc = 0 ;
421422 size_t page_size = 0 ;
422423 Page ptrack_page = NULL ;
423- ptrack_page = (Page ) pg_ptrack_get_block (conn_arg , file -> dbOid , file -> tblspcOid ,
424+ page = (Page ) pg_ptrack_get_block (conn_arg , file -> dbOid , file -> tblspcOid ,
424425 file -> relOid , absolute_blknum , & page_size ,
425426 ptrack_version_num , ptrack_schema );
426427
427428 if (ptrack_page == NULL )
428- {
429429 /* This block was truncated.*/
430430 return PageIsTruncated ;
431- }
432- else if (page_size != BLCKSZ )
433- {
434- free (ptrack_page );
431+
432+ if (page_size != BLCKSZ )
435433 elog (ERROR , "File: \"%s\", block %u, expected block size %d, but read %zu" ,
436434 from_fullpath , absolute_blknum , BLCKSZ , page_size );
437- }
438- else
435+
436+ /*
437+ * We need to copy the page that was successfully
438+ * retrieved from ptrack into our output "page" parameter.
439+ */
440+ memcpy (page , ptrack_page , BLCKSZ );
441+ pg_free (ptrack_page );
442+
443+ /* UPD: It apprears that is possible to get zeroed page or page with invalid header
444+ * from shared buffer.
445+ * Note, that getting page with wrong checksumm from shared buffer is
446+ * acceptable.
447+ */
448+ rc = validate_one_page (page , absolute_blknum ,
449+ InvalidXLogRecPtr , & page_lsn ,
450+ checksum_version );
451+
452+ /* It is ok to get zeroed page */
453+ if (rc == PAGE_IS_ZEROED )
454+ return PageIsOk ;
455+
456+ /* Getting page with invalid header from shared buffers is unacceptable */
457+ if (PAGE_HEADER_IS_INVALID )
439458 {
440- /*
441- * We need to copy the page that was successfully
442- * retrieved from ptrack into our output "page" parameter.
443- * We must set checksum here, because it is outdated
444- * in the block recieved from shared buffers.
445- */
446- memcpy (page , ptrack_page , BLCKSZ );
447- free (ptrack_page );
448- if (checksum_version )
449- ((PageHeader ) page )-> pd_checksum = pg_checksum_page (page , absolute_blknum );
459+ char * errormsg = NULL ;
460+ get_header_errormsg (page , & errormsg );
461+ elog (ERROR , "Corruption detected in file \"%s\", block %u: %s" ,
462+ from_fullpath , blknum , errormsg );
450463 }
451464
452- /* get lsn from page, provided by pg_ptrack_get_block() */
453- if (backup_mode == BACKUP_MODE_DIFF_DELTA &&
454- file -> exists_in_prev &&
455- !parse_page (page , & page_lsn ))
456- elog (ERROR , "Cannot parse page after pg_ptrack_get_block. "
457- "Possible risk of a memory corruption" );
465+ /* We must set checksum here, because it is outdated
466+ * in the block recieved from shared buffers.
467+ */
468+ if (checksum_version )
469+ ((PageHeader ) page )-> pd_checksum = pg_checksum_page (page , absolute_blknum );
458470 }
459471
460472 /*
0 commit comments