Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita879544

Browse files
committed
Extend PageIsVerified() to handle more custom options
This is useful for checks of relation pages without having to load thepages into the shared buffers, and two cases can make use of that: pageverification in base backups and the online, lock-safe, flavor.Compatibility is kept with past versions using a routine that calls thenew extended routine with the set of options compatible with theoriginal version. Contrary tod401c57, a macro cannot be used as theremay 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-upcommit addressing a set of issues with page verification in basebackups.Extracted from a larger patch by the same author.Author: Anastasia LubennikovaReviewed-by: Michael Paquier, Julien RouhaudDiscussion:https://postgr.es/m/608f3476-0598-2514-2c03-e05c7d2b0cbd@postgrespro.ruBackpatch-through: 11
1 parent7d72fd9 commita879544

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(Pagepage,BlockNumberblkno)
69+
{
70+
returnPageIsVerifiedExtended(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(Pagepage,BlockNumberblkno)
100+
PageIsVerifiedExtended(Pagepage,BlockNumberblkno,intflags)
83101
{
84102
PageHeaderp= (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
#definePAI_OVERWRITE(1 << 0)
414416
#definePAI_IS_HEAP(1 << 1)
415417

418+
/* flags for PageIsVerifiedExtended() */
419+
#definePIV_LOG_WARNING(1 << 0)
420+
#definePIV_REPORT_STAT(1 << 1)
421+
416422
#definePageAddItem(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
externvoidPageInit(Pagepage,SizepageSize,SizespecialSize);
422428
externboolPageIsVerified(Pagepage,BlockNumberblkno);
429+
externboolPageIsVerifiedExtended(Pagepage,BlockNumberblkno,intflags);
423430
externOffsetNumberPageAddItemExtended(Pagepage,Itemitem,Sizesize,
424431
OffsetNumberoffsetNumber,intflags);
425432
externPagePageGetTempPage(Pagepage);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp