Skip to content

Commit d445990

Browse files
committed
Let caller of PageIsVerified() control ignore_checksum_failure
For AIO the completion of a read into shared buffers (i.e. verifying the page including the checksum, updating the BufferDesc to reflect the IO) can happen in a different backend than the backend that started the IO. As ignore_checksum_failure can differ between backends, we need to allow the caller of PageIsVerified() control whether to ignore checksum failures. The commit leaves a gap in the PIV_* values, as an upcoming commit, which depends on this commit, will add PIV_LOG_LOG, which better fits just after PIV_LOG_WARNING. Reviewed-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/20250329212929.a6.nmisch@google.com
1 parent b96d3c3 commit d445990

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/backend/catalog/storage.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
508508
for (blkno = 0; blkno < nblocks; blkno++)
509509
{
510510
BulkWriteBuffer buf;
511+
int piv_flags;
511512
bool checksum_failure;
512513
bool verified;
513514

@@ -517,9 +518,11 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
517518
buf = smgr_bulk_get_buf(bulkstate);
518519
smgrread(src, forkNum, blkno, (Page) buf);
519520

520-
verified = PageIsVerified((Page) buf, blkno, PIV_LOG_WARNING,
521+
piv_flags = PIV_LOG_WARNING;
522+
if (ignore_checksum_failure)
523+
piv_flags |= PIV_IGNORE_CHECKSUM_FAILURE;
524+
verified = PageIsVerified((Page) buf, blkno, piv_flags,
521525
&checksum_failure);
522-
523526
if (checksum_failure)
524527
{
525528
RelFileLocatorBackend rloc = src->smgr_rlocator;

src/backend/storage/buffer/bufmgr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ WaitReadBuffers(ReadBuffersOperation *operation)
15691569
{
15701570
BufferDesc *bufHdr;
15711571
Block bufBlock;
1572+
int piv_flags;
15721573
bool verified;
15731574
bool checksum_failure;
15741575

@@ -1584,8 +1585,11 @@ WaitReadBuffers(ReadBuffersOperation *operation)
15841585
}
15851586

15861587
/* check for garbage data */
1588+
piv_flags = PIV_LOG_WARNING;
1589+
if (ignore_checksum_failure)
1590+
piv_flags |= PIV_IGNORE_CHECKSUM_FAILURE;
15871591
verified = PageIsVerified((Page) bufBlock, io_first_block + j,
1588-
PIV_LOG_WARNING, &checksum_failure);
1592+
piv_flags, &checksum_failure);
15891593
if (checksum_failure)
15901594
{
15911595
RelFileLocatorBackend rloc = operation->smgr->smgr_rlocator;

src/backend/storage/page/bufpage.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,14 @@ PageInit(Page page, Size pageSize, Size specialSize)
8181
* If flag PIV_LOG_WARNING is set, a WARNING is logged in the event of
8282
* a checksum failure.
8383
*
84+
* If flag PIV_IGNORE_CHECKSUM_FAILURE is set, checksum failures will cause a
85+
* message about the failure to be emitted, but will not cause
86+
* PageIsVerified() to return false.
87+
*
8488
* To allow the caller to report statistics about checksum failures,
8589
* *checksum_failure_p can be passed in. Note that there may be checksum
8690
* failures even if this function returns true, due to
87-
* ignore_checksum_failure.
91+
* IGNORE_CHECKSUM_FAILURE.
8892
*/
8993
bool
9094
PageIsVerified(PageData *page, BlockNumber blkno, int flags, bool *checksum_failure_p)
@@ -150,7 +154,7 @@ PageIsVerified(PageData *page, BlockNumber blkno, int flags, bool *checksum_fail
150154
errmsg("page verification failed, calculated checksum %u but expected %u",
151155
checksum, p->pd_checksum)));
152156

153-
if (header_sane && ignore_checksum_failure)
157+
if (header_sane && (flags & PIV_IGNORE_CHECKSUM_FAILURE))
154158
return true;
155159
}
156160

src/include/storage/bufpage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ do { \
467467

468468
/* flags for PageIsVerified() */
469469
#define PIV_LOG_WARNING (1 << 0)
470+
#define PIV_IGNORE_CHECKSUM_FAILURE (1 << 2)
470471

471472
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap) \
472473
PageAddItemExtended(page, item, size, offsetNumber, \

0 commit comments

Comments
 (0)