Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a879544

Browse files
committed
Extend PageIsVerified() to handle more custom options
This is useful for checks of relation pages without having to load the pages into the shared buffers, and two cases can make use of that: page verification in base backups and the online, lock-safe, flavor. Compatibility is kept with past versions using a routine that calls the new extended routine with the set of options compatible with the original version. Contrary to d401c57, a macro cannot be used as there may be external code relying on the presence of the original routine. This is applied down to 11, where this will be used by a follow-up commit addressing a set of issues with page verification in base backups. Extracted from a larger patch by the same author. Author: Anastasia Lubennikova Reviewed-by: Michael Paquier, Julien Rouhaud Discussion: https://postgr.es/m/608f3476-0598-2514-2c03-e05c7d2b0cbd@postgrespro.ru Backpatch-through: 11
1 parent 7d72fd9 commit a879544

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

src/backend/catalog/storage.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
338338

339339
smgrread(src, forkNum, blkno, buf.data);
340340

341-
if (!PageIsVerified(page, blkno))
341+
if (!PageIsVerifiedExtended(page, blkno,
342+
PIV_LOG_WARNING | PIV_REPORT_STAT))
342343
ereport(ERROR,
343344
(errcode(ERRCODE_DATA_CORRUPTED),
344345
errmsg("invalid page in block %u of relation %s",

src/backend/storage/buffer/bufmgr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ ReadBuffer(Relation reln, BlockNumber blockNum)
613613
*
614614
* In RBM_NORMAL mode, the page is read from disk, and the page header is
615615
* validated. An error is thrown if the page header is not valid. (But
616-
* note that an all-zero page is considered "valid"; see PageIsVerified().)
616+
* note that an all-zero page is considered "valid"; see
617+
* PageIsVerifiedExtended().)
617618
*
618619
* RBM_ZERO_ON_ERROR is like the normal mode, but if the page header is not
619620
* valid, the page is zeroed instead of throwing an error. This is intended
@@ -905,7 +906,8 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
905906
}
906907

907908
/* check for garbage data */
908-
if (!PageIsVerified((Page) bufBlock, blockNum))
909+
if (!PageIsVerifiedExtended((Page) bufBlock, blockNum,
910+
PIV_LOG_WARNING | PIV_REPORT_STAT))
909911
{
910912
if (mode == RBM_ZERO_ON_ERROR || zero_damaged_pages)
911913
{

src/backend/storage/page/bufpage.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ PageInit(Page page, Size pageSize, Size specialSize)
6262

6363
/*
6464
* PageIsVerified
65+
* Utility wrapper for PageIsVerifiedExtended().
66+
*/
67+
bool
68+
PageIsVerified(Page page, BlockNumber blkno)
69+
{
70+
return PageIsVerifiedExtended(page, blkno,
71+
PIV_LOG_WARNING | PIV_REPORT_STAT);
72+
}
73+
74+
75+
/*
76+
* PageIsVerifiedExtended
6577
* Check that the page header and checksum (if any) appear valid.
6678
*
6779
* This is called when a page has just been read in from disk. The idea is
@@ -77,9 +89,15 @@ PageInit(Page page, Size pageSize, Size specialSize)
7789
* allow zeroed pages here, and are careful that the page access macros
7890
* treat such a page as empty and without free space. Eventually, VACUUM
7991
* will clean up such a page and make it usable.
92+
*
93+
* If flag PIV_LOG_WARNING is set, a WARNING is logged in the event of
94+
* a checksum failure.
95+
*
96+
* If flag PIV_REPORT_STAT is set, a checksum failure is reported directly
97+
* to pgstat.
8098
*/
8199
bool
82-
PageIsVerified(Page page, BlockNumber blkno)
100+
PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
83101
{
84102
PageHeader p = (PageHeader) page;
85103
size_t *pagebytes;
@@ -147,12 +165,14 @@ PageIsVerified(Page page, BlockNumber blkno)
147165
*/
148166
if (checksum_failure)
149167
{
150-
ereport(WARNING,
151-
(errcode(ERRCODE_DATA_CORRUPTED),
152-
errmsg("page verification failed, calculated checksum %u but expected %u",
153-
checksum, p->pd_checksum)));
168+
if ((flags & PIV_LOG_WARNING) != 0)
169+
ereport(WARNING,
170+
(errcode(ERRCODE_DATA_CORRUPTED),
171+
errmsg("page verification failed, calculated checksum %u but expected %u",
172+
checksum, p->pd_checksum)));
154173

155-
pgstat_report_checksum_failure();
174+
if ((flags & PIV_REPORT_STAT) != 0)
175+
pgstat_report_checksum_failure();
156176

157177
if (header_sane && ignore_checksum_failure)
158178
return true;

src/include/storage/bufpage.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,23 @@ do { \
410410
* extern declarations
411411
* ----------------------------------------------------------------
412412
*/
413+
414+
/* flags for PageAddItemExtended() */
413415
#define PAI_OVERWRITE (1 << 0)
414416
#define PAI_IS_HEAP (1 << 1)
415417

418+
/* flags for PageIsVerifiedExtended() */
419+
#define PIV_LOG_WARNING (1 << 0)
420+
#define PIV_REPORT_STAT (1 << 1)
421+
416422
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap) \
417423
PageAddItemExtended(page, item, size, offsetNumber, \
418424
((overwrite) ? PAI_OVERWRITE : 0) | \
419425
((is_heap) ? PAI_IS_HEAP : 0))
420426

421427
extern void PageInit(Page page, Size pageSize, Size specialSize);
422428
extern bool PageIsVerified(Page page, BlockNumber blkno);
429+
extern bool PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags);
423430
extern OffsetNumber PageAddItemExtended(Page page, Item item, Size size,
424431
OffsetNumber offsetNumber, int flags);
425432
extern Page PageGetTempPage(Page page);

0 commit comments

Comments
 (0)