@@ -290,6 +290,7 @@ prepare_page(ConnectionArgs *conn_arg,
290290int try_again = PAGE_READ_ATTEMPTS ;
291291bool page_is_valid = false;
292292BlockNumber absolute_blknum = file -> segno * RELSEG_SIZE + blknum ;
293+ int rc = 0 ;
293294
294295/* check for interrupt */
295296if (interrupted || thread_interrupted )
@@ -300,161 +301,97 @@ prepare_page(ConnectionArgs *conn_arg,
300301 * Under high write load it's possible that we've read partly
301302 * flushed page, so try several times before throwing an error.
302303 */
303- if ( backup_mode != BACKUP_MODE_DIFF_PTRACK || ptrack_version_num >= 200 )
304+ while (! page_is_valid && try_again -- )
304305{
305- int rc = 0 ;
306- while (!page_is_valid && try_again -- )
307- {
308- /* read the block */
309- int read_len = fio_pread (in ,page ,blknum * BLCKSZ );
306+ /* read the block */
307+ int read_len = fio_pread (in ,page ,blknum * BLCKSZ );
310308
311- /* The block could have been truncated. It is fine. */
312- if (read_len == 0 )
313- {
314- elog (VERBOSE ,"Cannot read block %u of \"%s\": "
315- "block truncated" ,blknum ,from_fullpath );
316- return PageIsTruncated ;
317- }
318- else if (read_len < 0 )
319- elog (ERROR ,"Cannot read block %u of \"%s\": %s" ,
320- blknum ,from_fullpath ,strerror (errno ));
321- else if (read_len != BLCKSZ )
322- elog (WARNING ,"Cannot read block %u of \"%s\": "
323- "read %i of %d, try again" ,
324- blknum ,from_fullpath ,read_len ,BLCKSZ );
325- else
309+ /* The block could have been truncated. It is fine. */
310+ if (read_len == 0 )
311+ {
312+ elog (VERBOSE ,"Cannot read block %u of \"%s\": "
313+ "block truncated" ,blknum ,from_fullpath );
314+ return PageIsTruncated ;
315+ }
316+ else if (read_len < 0 )
317+ elog (ERROR ,"Cannot read block %u of \"%s\": %s" ,
318+ blknum ,from_fullpath ,strerror (errno ));
319+ else if (read_len != BLCKSZ )
320+ elog (WARNING ,"Cannot read block %u of \"%s\": "
321+ "read %i of %d, try again" ,
322+ blknum ,from_fullpath ,read_len ,BLCKSZ );
323+ else
324+ {
325+ /* We have BLCKSZ of raw data, validate it */
326+ rc = validate_one_page (page ,absolute_blknum ,
327+ InvalidXLogRecPtr ,page_st ,
328+ checksum_version );
329+ switch (rc )
326330{
327- /* We have BLCKSZ of raw data, validate it */
328- rc = validate_one_page (page ,absolute_blknum ,
329- InvalidXLogRecPtr ,page_st ,
330- checksum_version );
331- switch (rc )
332- {
333- case PAGE_IS_ZEROED :
334- elog (VERBOSE ,"File: \"%s\" blknum %u, empty page" ,from_fullpath ,blknum );
331+ case PAGE_IS_ZEROED :
332+ elog (VERBOSE ,"File: \"%s\" blknum %u, empty page" ,from_fullpath ,blknum );
333+ return PageIsOk ;
334+
335+ case PAGE_IS_VALID :
336+ /* in DELTA or PTRACK modes we must compare lsn */
337+ if (backup_mode == BACKUP_MODE_DIFF_DELTA || backup_mode == BACKUP_MODE_DIFF_PTRACK )
338+ page_is_valid = true;
339+ else
335340return PageIsOk ;
336-
337- case PAGE_IS_VALID :
338- /* in DELTA or PTRACK modes we must compare lsn */
339- if (backup_mode == BACKUP_MODE_DIFF_DELTA || backup_mode == BACKUP_MODE_DIFF_PTRACK )
340- page_is_valid = true;
341- else
342- return PageIsOk ;
343- break ;
344-
345- case PAGE_HEADER_IS_INVALID :
346- elog (VERBOSE ,"File: \"%s\" blknum %u have wrong page header, try again" ,
347- from_fullpath ,blknum );
348- break ;
349-
350- case PAGE_CHECKSUM_MISMATCH :
351- elog (VERBOSE ,"File: \"%s\" blknum %u have wrong checksum, try again" ,
352- from_fullpath ,blknum );
353- break ;
354- default :
355- Assert (false);
356- }
341+ break ;
342+
343+ case PAGE_HEADER_IS_INVALID :
344+ elog (VERBOSE ,"File: \"%s\" blknum %u have wrong page header, try again" ,
345+ from_fullpath ,blknum );
346+ break ;
347+
348+ case PAGE_CHECKSUM_MISMATCH :
349+ elog (VERBOSE ,"File: \"%s\" blknum %u have wrong checksum, try again" ,
350+ from_fullpath ,blknum );
351+ break ;
352+ default :
353+ Assert (false);
357354}
358355}
359-
360- /*
361- * If page is not valid after 100 attempts to read it
362- * throw an error.
363- */
364- if (!page_is_valid )
365- {
366- int elevel = ERROR ;
367- char * errormsg = NULL ;
368-
369- /* Get the details of corruption */
370- if (rc == PAGE_HEADER_IS_INVALID )
371- get_header_errormsg (page ,& errormsg );
372- else if (rc == PAGE_CHECKSUM_MISMATCH )
373- get_checksum_errormsg (page ,& errormsg ,
374- file -> segno * RELSEG_SIZE + blknum );
375-
376- /* Error out in case of merge or backup without ptrack support;
377- * issue warning in case of checkdb or backup with ptrack support
378- */
379- if (!strict )
380- elevel = WARNING ;
381-
382- if (errormsg )
383- elog (elevel ,"Corruption detected in file \"%s\", block %u: %s" ,
384- from_fullpath ,blknum ,errormsg );
385- else
386- elog (elevel ,"Corruption detected in file \"%s\", block %u" ,
387- from_fullpath ,blknum );
388-
389- pg_free (errormsg );
390- return PageIsCorrupted ;
391- }
392-
393- /* Checkdb not going futher */
394- if (!strict )
395- return PageIsOk ;
396356}
397357
398358/*
399- *Get pagevia ptrack interface from PostgreSQL shared buffer.
400- *We do this only in the cases of PTRACK 1.x versions backup
359+ *If pageis not valid after 100 attempts to read it
360+ *throw an error.
401361 */
402- if (backup_mode == BACKUP_MODE_DIFF_PTRACK
403- && (ptrack_version_num >=105 && ptrack_version_num < 200 ))
362+ if (!page_is_valid )
404363{
405- int rc = 0 ;
406- size_t page_size = 0 ;
407- Page ptrack_page = NULL ;
408- ptrack_page = (Page )pg_ptrack_get_block (conn_arg ,file -> dbOid ,file -> tblspcOid ,
409- file -> relOid ,absolute_blknum ,& page_size ,
410- ptrack_version_num ,ptrack_schema );
411-
412- if (ptrack_page == NULL )
413- /* This block was truncated.*/
414- return PageIsTruncated ;
415-
416- if (page_size != BLCKSZ )
417- elog (ERROR ,"File: \"%s\", block %u, expected block size %d, but read %zu" ,
418- from_fullpath ,blknum ,BLCKSZ ,page_size );
419-
420- /*
421- * We need to copy the page that was successfully
422- * retrieved from ptrack into our output "page" parameter.
423- */
424- memcpy (page ,ptrack_page ,BLCKSZ );
425- pg_free (ptrack_page );
426-
427- /*
428- * UPD: It apprears that is possible to get zeroed page or page with invalid header
429- * from shared buffer.
430- * Note, that getting page with wrong checksumm from shared buffer is
431- * acceptable.
432- */
433- rc = validate_one_page (page ,absolute_blknum ,
434- InvalidXLogRecPtr ,page_st ,
435- checksum_version );
364+ int elevel = ERROR ;
365+ char * errormsg = NULL ;
436366
437- /* It is ok to get zeroed page */
438- if (rc == PAGE_IS_ZEROED )
439- return PageIsOk ;
440-
441- /* Getting page with invalid header from shared buffers is unacceptable */
367+ /* Get the details of corruption */
442368if (rc == PAGE_HEADER_IS_INVALID )
443- {
444- char * errormsg = NULL ;
445369get_header_errormsg (page ,& errormsg );
446- elog ( ERROR , "Corruption detected in file \"%s\", block %u: %s" ,
447- from_fullpath , blknum , errormsg );
448- }
370+ else if ( rc == PAGE_CHECKSUM_MISMATCH )
371+ get_checksum_errormsg ( page , & errormsg ,
372+ file -> segno * RELSEG_SIZE + blknum );
449373
450- /*
451- * We must set checksum here, because it is outdated
452- * in the block recieved from shared buffers.
374+ /* Error out in case of merge or backup without ptrack support;
375+ * issue warning in case of checkdb or backup with ptrack support
453376 */
454- if (checksum_version )
455- page_st -> checksum = ((PageHeader )page )-> pd_checksum = pg_checksum_page (page ,absolute_blknum );
377+ if (!strict )
378+ elevel = WARNING ;
379+
380+ if (errormsg )
381+ elog (elevel ,"Corruption detected in file \"%s\", block %u: %s" ,
382+ from_fullpath ,blknum ,errormsg );
383+ else
384+ elog (elevel ,"Corruption detected in file \"%s\", block %u" ,
385+ from_fullpath ,blknum );
386+
387+ pg_free (errormsg );
388+ return PageIsCorrupted ;
456389}
457390
391+ /* Checkdb not going futher */
392+ if (!strict )
393+ return PageIsOk ;
394+
458395/*
459396 * Skip page if page lsn is less than START_LSN of parent backup.
460397 * Nullified pages must be copied by DELTA backup, just to be safe.