]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Extend PageIsVerified() to handle more custom options
authorMichael Paquier <michael@paquier.xyz>
Mon, 2 Nov 2020 01:41:34 +0000 (10:41 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 2 Nov 2020 01:41:34 +0000 (10:41 +0900)
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 d401c576, 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

src/backend/storage/buffer/bufmgr.c
src/backend/storage/page/bufpage.c
src/include/storage/bufpage.h

index 01eabe57063b485edb53a8aa6d3ada02f6a3dc62..8708ba35c33ab965afa5478649537c22b5911eb0 100644 (file)
@@ -612,7 +612,8 @@ ReadBuffer(Relation reln, BlockNumber blockNum)
  *
  * In RBM_NORMAL mode, the page is read from disk, and the page header is
  * validated.  An error is thrown if the page header is not valid.  (But
- * note that an all-zero page is considered "valid"; see PageIsVerified().)
+ * note that an all-zero page is considered "valid"; see
+ * PageIsVerifiedExtended().)
  *
  * RBM_ZERO_ON_ERROR is like the normal mode, but if the page header is not
  * 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,
                        }
 
                        /* check for garbage data */
-                       if (!PageIsVerified((Page) bufBlock, blockNum))
+                       if (!PageIsVerifiedExtended((Page) bufBlock, blockNum,
+                                                                               PIV_LOG_WARNING))
                        {
                                if (mode == RBM_ZERO_ON_ERROR || zero_damaged_pages)
                                {
index d2ea38bdabcbac4550464fc64b883159923d66fd..8d788b56ae48cc71d74da2c9d2d082bb5fdbc9f9 100644 (file)
@@ -61,6 +61,17 @@ PageInit(Page page, Size pageSize, Size specialSize)
 
 /*
  * PageIsVerified
+ *             Utility wrapper for PageIsVerifiedExtended().
+ */
+bool
+PageIsVerified(Page page, BlockNumber blkno)
+{
+       return PageIsVerifiedExtended(page, blkno, PIV_LOG_WARNING);
+}
+
+
+/*
+ * PageIsVerifiedExtended
  *             Check that the page header and checksum (if any) appear valid.
  *
  * 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)
  * allow zeroed pages here, and are careful that the page access macros
  * treat such a page as empty and without free space.  Eventually, VACUUM
  * will clean up such a page and make it usable.
+ *
+ * If flag PIV_LOG_WARNING is set, a WARNING is logged in the event of
+ * a checksum failure.
  */
 bool
-PageIsVerified(Page page, BlockNumber blkno)
+PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags)
 {
        PageHeader      p = (PageHeader) page;
        size_t     *pagebytes;
@@ -146,10 +160,11 @@ PageIsVerified(Page page, BlockNumber blkno)
         */
        if (checksum_failure)
        {
-               ereport(WARNING,
-                               (errcode(ERRCODE_DATA_CORRUPTED),
-                                errmsg("page verification failed, calculated checksum %u but expected %u",
-                                               checksum, p->pd_checksum)));
+               if ((flags & PIV_LOG_WARNING) != 0)
+                       ereport(WARNING,
+                                       (errcode(ERRCODE_DATA_CORRUPTED),
+                                        errmsg("page verification failed, calculated checksum %u but expected %u",
+                                                       checksum, p->pd_checksum)));
 
                if (header_sane && ignore_checksum_failure)
                        return true;
index 85dd10c45a3ebead868d77bb36da34037d9699b7..0d21c727ba5a5109456e05667f66e94c34483ea4 100644 (file)
@@ -406,9 +406,14 @@ do { \
  *             extern declarations
  * ----------------------------------------------------------------
  */
+
+/* flags for PageAddItemExtended() */
 #define PAI_OVERWRITE                  (1 << 0)
 #define PAI_IS_HEAP                            (1 << 1)
 
+/* flags for PageIsVerifiedExtended() */
+#define PIV_LOG_WARNING                        (1 << 0)
+
 #define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap) \
        PageAddItemExtended(page, item, size, offsetNumber, \
                                                ((overwrite) ? PAI_OVERWRITE : 0) | \
@@ -416,6 +421,7 @@ do { \
 
 extern void PageInit(Page page, Size pageSize, Size specialSize);
 extern bool PageIsVerified(Page page, BlockNumber blkno);
+extern bool PageIsVerifiedExtended(Page page, BlockNumber blkno, int flags);
 extern OffsetNumber PageAddItemExtended(Page page, Item item, Size size,
                                        OffsetNumber offsetNumber, int flags);
 extern Page PageGetTempPage(Page page);