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

Commitd401c57

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 macro that calls thenew extended routine with the set of options compatible with theoriginal version.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.ru
1 parentba9f18a commitd401c57

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

‎src/backend/catalog/storage.c

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 15 additions & 7 deletions
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(Pagepage,BlockNumberblkno)
88+
PageIsVerifiedExtended(Pagepage,BlockNumberblkno,intflags)
8389
{
8490
PageHeaderp= (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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,26 +404,36 @@ do { \
404404
*extern declarations
405405
* ----------------------------------------------------------------
406406
*/
407+
408+
/* flags for PageAddItemExtended() */
407409
#definePAI_OVERWRITE(1 << 0)
408410
#definePAI_IS_HEAP(1 << 1)
409411

412+
/* flags for PageIsVerifiedExtended() */
413+
#definePIV_LOG_WARNING(1 << 0)
414+
#definePIV_REPORT_STAT(1 << 1)
415+
410416
#definePageAddItem(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+
#definePageIsVerified(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 nativeword size. Note that this assertion
429+
*is kept within a header to makesure that StaticAssertDecl() works
430+
*across various combinations ofplatforms 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
externvoidPageInit(Pagepage,SizepageSize,SizespecialSize);
426-
externboolPageIsVerified(Pagepage,BlockNumberblkno);
436+
externboolPageIsVerifiedExtended(Pagepage,BlockNumberblkno,intflags);
427437
externOffsetNumberPageAddItemExtended(Pagepage,Itemitem,Sizesize,
428438
OffsetNumberoffsetNumber,intflags);
429439
externPagePageGetTempPage(Pagepage);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp