Skip to content

Commit 0a593bc

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 d1ac060 commit 0a593bc

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/backend/storage/buffer/bufmgr.c

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

900901
/* check for garbage data */
901-
if (!PageIsVerified((Page) bufBlock, blockNum))
902+
if (!PageIsVerifiedExtended((Page) bufBlock, blockNum,
903+
PIV_LOG_WARNING))
902904
{
903905
if (mode == RBM_ZERO_ON_ERROR || zero_damaged_pages)
904906
{

src/backend/storage/page/bufpage.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ PageInit(Page page, Size pageSize, Size specialSize)
6161

6262
/*
6363
* PageIsVerified
64+
* Utility wrapper for PageIsVerifiedExtended().
65+
*/
66+
bool
67+
PageIsVerified(Page page, BlockNumber blkno)
68+
{
69+
return PageIsVerifiedExtended(page, blkno, PIV_LOG_WARNING);
70+
}
71+
72+
73+
/*
74+
* PageIsVerifiedExtended
6475
* Check that the page header and checksum (if any) appear valid.
6576
*
6677
* This is called when a page has just been read in from disk. The idea is
@@ -76,9 +87,12 @@ PageInit(Page page, Size pageSize, Size specialSize)
7687
* allow zeroed pages here, and are careful that the page access macros
7788
* treat such a page as empty and without free space. Eventually, VACUUM
7889
* will clean up such a page and make it usable.
90+
*
91+
* If flag PIV_LOG_WARNING is set, a WARNING is logged in the event of
92+
* a checksum failure.
7993
*/
8094
bool
81-
PageIsVerified(Page page, BlockNumber blkno)
95+
PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
8296
{
8397
PageHeader p = (PageHeader) page;
8498
size_t *pagebytes;
@@ -146,10 +160,11 @@ PageIsVerified(Page page, BlockNumber blkno)
146160
*/
147161
if (checksum_failure)
148162
{
149-
ereport(WARNING,
150-
(errcode(ERRCODE_DATA_CORRUPTED),
151-
errmsg("page verification failed, calculated checksum %u but expected %u",
152-
checksum, p->pd_checksum)));
163+
if ((flags & PIV_LOG_WARNING) != 0)
164+
ereport(WARNING,
165+
(errcode(ERRCODE_DATA_CORRUPTED),
166+
errmsg("page verification failed, calculated checksum %u but expected %u",
167+
checksum, p->pd_checksum)));
153168

154169
if (header_sane && ignore_checksum_failure)
155170
return true;

src/include/storage/bufpage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,22 @@ do { \
406406
* extern declarations
407407
* ----------------------------------------------------------------
408408
*/
409+
410+
/* flags for PageAddItemExtended() */
409411
#define PAI_OVERWRITE (1 << 0)
410412
#define PAI_IS_HEAP (1 << 1)
411413

414+
/* flags for PageIsVerifiedExtended() */
415+
#define PIV_LOG_WARNING (1 << 0)
416+
412417
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap) \
413418
PageAddItemExtended(page, item, size, offsetNumber, \
414419
((overwrite) ? PAI_OVERWRITE : 0) | \
415420
((is_heap) ? PAI_IS_HEAP : 0))
416421

417422
extern void PageInit(Page page, Size pageSize, Size specialSize);
418423
extern bool PageIsVerified(Page page, BlockNumber blkno);
424+
extern bool PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags);
419425
extern OffsetNumber PageAddItemExtended(Page page, Item item, Size size,
420426
OffsetNumber offsetNumber, int flags);
421427
extern Page PageGetTempPage(Page page);

0 commit comments

Comments
 (0)