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

Commit d401c57

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 macro that calls the new extended routine with the set of options compatible with the original version. 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
1 parent ba9f18a commit d401c57

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

src/backend/catalog/storage.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
443443

444444
smgrread(src, forkNum, blkno, buf.data);
445445

446-
if (!PageIsVerified(page, blkno))
446+
if (!PageIsVerifiedExtended(page, blkno,
447+
PIV_LOG_WARNING | PIV_REPORT_STAT))
447448
ereport(ERROR,
448449
(errcode(ERRCODE_DATA_CORRUPTED),
449450
errmsg("invalid page in block %u of relation %s",

src/backend/storage/buffer/bufmgr.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ ReadBuffer(Relation reln, BlockNumber blockNum)
625625
*
626626
* In RBM_NORMAL mode, the page is read from disk, and the page header is
627627
* validated. An error is thrown if the page header is not valid. (But
628-
* note that an all-zero page is considered "valid"; see PageIsVerified().)
628+
* note that an all-zero page is considered "valid"; see
629+
* PageIsVerifiedExtended().)
629630
*
630631
* RBM_ZERO_ON_ERROR is like the normal mode, but if the page header is not
631632
* valid, the page is zeroed instead of throwing an error. This is intended
@@ -917,7 +918,8 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
917918
}
918919

919920
/* check for garbage data */
920-
if (!PageIsVerified((Page) bufBlock, blockNum))
921+
if (!PageIsVerifiedExtended((Page) bufBlock, blockNum,
922+
PIV_LOG_WARNING | PIV_REPORT_STAT))
921923
{
922924
if (mode == RBM_ZERO_ON_ERROR || zero_damaged_pages)
923925
{

src/backend/storage/page/bufpage.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PageInit(Page page, Size pageSize, Size specialSize)
6161

6262

6363
/*
64-
* PageIsVerified
64+
* PageIsVerifiedExtended
6565
* Check that the page header and checksum (if any) appear valid.
6666
*
6767
* This is called when a page has just been read in from disk. The idea is
@@ -77,9 +77,15 @@ PageInit(Page page, Size pageSize, Size specialSize)
7777
* allow zeroed pages here, and are careful that the page access macros
7878
* treat such a page as empty and without free space. Eventually, VACUUM
7979
* will clean up such a page and make it usable.
80+
*
81+
* If flag PIV_LOG_WARNING is set, a WARNING is logged in the event of
82+
* a checksum failure.
83+
*
84+
* If flag PIV_REPORT_STAT is set, a checksum failure is reported directly
85+
* to pgstat.
8086
*/
8187
bool
82-
PageIsVerified(Page page, BlockNumber blkno)
88+
PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
8389
{
8490
PageHeader p = (PageHeader) page;
8591
size_t *pagebytes;
@@ -140,12 +146,14 @@ PageIsVerified(Page page, BlockNumber blkno)
140146
*/
141147
if (checksum_failure)
142148
{
143-
ereport(WARNING,
144-
(errcode(ERRCODE_DATA_CORRUPTED),
145-
errmsg("page verification failed, calculated checksum %u but expected %u",
146-
checksum, p->pd_checksum)));
149+
if ((flags & PIV_LOG_WARNING) != 0)
150+
ereport(WARNING,
151+
(errcode(ERRCODE_DATA_CORRUPTED),
152+
errmsg("page verification failed, calculated checksum %u but expected %u",
153+
checksum, p->pd_checksum)));
147154

148-
pgstat_report_checksum_failure();
155+
if ((flags & PIV_REPORT_STAT) != 0)
156+
pgstat_report_checksum_failure();
149157

150158
if (header_sane && ignore_checksum_failure)
151159
return true;

src/include/storage/bufpage.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -404,26 +404,36 @@ do { \
404404
* extern declarations
405405
* ----------------------------------------------------------------
406406
*/
407+
408+
/* flags for PageAddItemExtended() */
407409
#define PAI_OVERWRITE (1 << 0)
408410
#define PAI_IS_HEAP (1 << 1)
409411

412+
/* flags for PageIsVerifiedExtended() */
413+
#define PIV_LOG_WARNING (1 << 0)
414+
#define PIV_REPORT_STAT (1 << 1)
415+
410416
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap) \
411417
PageAddItemExtended(page, item, size, offsetNumber, \
412418
((overwrite) ? PAI_OVERWRITE : 0) | \
413419
((is_heap) ? PAI_IS_HEAP : 0))
414420

421+
#define PageIsVerified(page, blkno) \
422+
PageIsVerifiedExtended(page, blkno, \
423+
PIV_LOG_WARNING | PIV_REPORT_STAT)
424+
415425
/*
416-
* Check that BLCKSZ is a multiple of sizeof(size_t). In PageIsVerified(),
417-
* it is much faster to check if a page is full of zeroes using the native
418-
* word size. Note that this assertion is kept within a header to make
419-
* sure that StaticAssertDecl() works across various combinations of
420-
* platforms and compilers.
426+
* Check that BLCKSZ is a multiple of sizeof(size_t). In
427+
* PageIsVerifiedExtended(), it is much faster to check if a page is
428+
* full of zeroes using the native word size. Note that this assertion
429+
* is kept within a header to make sure that StaticAssertDecl() works
430+
* across various combinations of platforms and compilers.
421431
*/
422432
StaticAssertDecl(BLCKSZ == ((BLCKSZ / sizeof(size_t)) * sizeof(size_t)),
423433
"BLCKSZ has to be a multiple of sizeof(size_t)");
424434

425435
extern void PageInit(Page page, Size pageSize, Size specialSize);
426-
extern bool PageIsVerified(Page page, BlockNumber blkno);
436+
extern bool PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags);
427437
extern OffsetNumber PageAddItemExtended(Page page, Item item, Size size,
428438
OffsetNumber offsetNumber, int flags);
429439
extern Page PageGetTempPage(Page page);

0 commit comments

Comments
 (0)