LCOV - differential code coverage report
Current view: top level - src/backend/access/common - bufmask.c (source / functions) Coverage Total Hit UBC CBC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 97.1 % 35 34 1 34
Current Date: 2025-09-06 07:49:51 +0900 Functions: 100.0 % 5 5 5
Baseline: lcov-20250906-005545-baseline Branches: 57.1 % 14 8 6 8
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 97.1 % 35 34 1 34
Function coverage date bins:
(360..) days: 100.0 % 5 5 5
Branch coverage date bins:
(360..) days: 57.1 % 14 8 6 8

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * bufmask.c
                                  4                 :                :  *    Routines for buffer masking. Used to mask certain bits
                                  5                 :                :  *    in a page which can be different when the WAL is generated
                                  6                 :                :  *    and when the WAL is applied.
                                  7                 :                :  *
                                  8                 :                :  * Portions Copyright (c) 2016-2025, PostgreSQL Global Development Group
                                  9                 :                :  *
                                 10                 :                :  * Contains common routines required for masking a page.
                                 11                 :                :  *
                                 12                 :                :  * IDENTIFICATION
                                 13                 :                :  *    src/backend/access/common/bufmask.c
                                 14                 :                :  *
                                 15                 :                :  *-------------------------------------------------------------------------
                                 16                 :                :  */
                                 17                 :                : 
                                 18                 :                : #include "postgres.h"
                                 19                 :                : 
                                 20                 :                : #include "access/bufmask.h"
                                 21                 :                : 
                                 22                 :                : /*
                                 23                 :                :  * mask_page_lsn_and_checksum
                                 24                 :                :  *
                                 25                 :                :  * In consistency checks, the LSN of the two pages compared will likely be
                                 26                 :                :  * different because of concurrent operations when the WAL is generated and
                                 27                 :                :  * the state of the page when WAL is applied. Also, mask out checksum as
                                 28                 :                :  * masking anything else on page means checksum is not going to match as well.
                                 29                 :                :  */
                                 30                 :                : void
 2906 rhaas@postgresql.org       31                 :CBC     4606810 : mask_page_lsn_and_checksum(Page page)
                                 32                 :                : {
 3132                            33                 :        4606810 :     PageHeader  phdr = (PageHeader) page;
                                 34                 :                : 
                                 35                 :        4606810 :     PageXLogRecPtrSet(phdr->pd_lsn, (uint64) MASK_MARKER);
 2906                            36                 :        4606810 :     phdr->pd_checksum = MASK_MARKER;
 3132                            37                 :        4606810 : }
                                 38                 :                : 
                                 39                 :                : /*
                                 40                 :                :  * mask_page_hint_bits
                                 41                 :                :  *
                                 42                 :                :  * Mask hint bits in PageHeader. We want to ignore differences in hint bits,
                                 43                 :                :  * since they can be set without emitting any WAL.
                                 44                 :                :  */
                                 45                 :                : void
                                 46                 :        4605618 : mask_page_hint_bits(Page page)
                                 47                 :                : {
                                 48                 :        4605618 :     PageHeader  phdr = (PageHeader) page;
                                 49                 :                : 
                                 50                 :                :     /* Ignore prune_xid (it's like a hint-bit) */
                                 51                 :        4605618 :     phdr->pd_prune_xid = MASK_MARKER;
                                 52                 :                : 
                                 53                 :                :     /* Ignore PD_PAGE_FULL and PD_HAS_FREE_LINES flags, they are just hints. */
                                 54                 :        4605618 :     PageClearFull(page);
                                 55                 :        4605618 :     PageClearHasFreeLinePointers(page);
                                 56                 :                : 
                                 57                 :                :     /*
                                 58                 :                :      * During replay, if the page LSN has advanced past our XLOG record's LSN,
                                 59                 :                :      * we don't mark the page all-visible. See heap_xlog_visible() for
                                 60                 :                :      * details.
                                 61                 :                :      */
                                 62                 :        4605618 :     PageClearAllVisible(page);
                                 63                 :        4605618 : }
                                 64                 :                : 
                                 65                 :                : /*
                                 66                 :                :  * mask_unused_space
                                 67                 :                :  *
                                 68                 :                :  * Mask the unused space of a page between pd_lower and pd_upper.
                                 69                 :                :  */
                                 70                 :                : void
                                 71                 :        4605510 : mask_unused_space(Page page)
                                 72                 :                : {
                                 73                 :        4605510 :     int         pd_lower = ((PageHeader) page)->pd_lower;
                                 74                 :        4605510 :     int         pd_upper = ((PageHeader) page)->pd_upper;
                                 75                 :        4605510 :     int         pd_special = ((PageHeader) page)->pd_special;
                                 76                 :                : 
                                 77                 :                :     /* Sanity check */
                                 78   [ +  -  +  - ]:        4605510 :     if (pd_lower > pd_upper || pd_special < pd_upper ||
                                 79   [ +  -  -  + ]:        4605510 :         pd_lower < SizeOfPageHeaderData || pd_special > BLCKSZ)
                                 80                 :                :     {
  977 michael@paquier.xyz        81         [ #  # ]:UBC           0 :         elog(ERROR, "invalid page pd_lower %u pd_upper %u pd_special %u",
                                 82                 :                :              pd_lower, pd_upper, pd_special);
                                 83                 :                :     }
                                 84                 :                : 
 3132 rhaas@postgresql.org       85                 :CBC     4605510 :     memset(page + pd_lower, MASK_MARKER, pd_upper - pd_lower);
                                 86                 :        4605510 : }
                                 87                 :                : 
                                 88                 :                : /*
                                 89                 :                :  * mask_lp_flags
                                 90                 :                :  *
                                 91                 :                :  * In some index AMs, line pointer flags can be modified on the primary
                                 92                 :                :  * without emitting any WAL record.
                                 93                 :                :  */
                                 94                 :                : void
                                 95                 :        1170188 : mask_lp_flags(Page page)
                                 96                 :                : {
                                 97                 :                :     OffsetNumber offnum,
                                 98                 :                :                 maxoff;
                                 99                 :                : 
                                100                 :        1170188 :     maxoff = PageGetMaxOffsetNumber(page);
                                101                 :        1170188 :     for (offnum = FirstOffsetNumber;
                                102         [ +  + ]:      206503082 :          offnum <= maxoff;
                                103                 :      205332894 :          offnum = OffsetNumberNext(offnum))
                                104                 :                :     {
                                105                 :      205332894 :         ItemId      itemId = PageGetItemId(page, offnum);
                                106                 :                : 
                                107         [ +  + ]:      205332894 :         if (ItemIdIsUsed(itemId))
                                108                 :      205329930 :             itemId->lp_flags = LP_UNUSED;
                                109                 :                :     }
                                110                 :        1170188 : }
                                111                 :                : 
                                112                 :                : /*
                                113                 :                :  * mask_page_content
                                114                 :                :  *
                                115                 :                :  * In some index AMs, the contents of deleted pages need to be almost
                                116                 :                :  * completely ignored.
                                117                 :                :  */
                                118                 :                : void
                                119                 :            360 : mask_page_content(Page page)
                                120                 :                : {
                                121                 :                :     /* Mask Page Content */
                                122                 :            360 :     memset(page + SizeOfPageHeaderData, MASK_MARKER,
                                123                 :                :            BLCKSZ - SizeOfPageHeaderData);
                                124                 :                : 
                                125                 :                :     /* Mask pd_lower and pd_upper */
                                126                 :            360 :     memset(&((PageHeader) page)->pd_lower, MASK_MARKER,
                                127                 :                :            sizeof(uint16));
                                128                 :            360 :     memset(&((PageHeader) page)->pd_upper, MASK_MARKER,
                                129                 :                :            sizeof(uint16));
                                130                 :            360 : }
        

Generated by: LCOV version 2.4-beta