PostgreSQL Source Code git master
Loading...
Searching...
No Matches
checksum_impl.h File Reference
Include dependency graph for checksum_impl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  PGChecksummablePage
 

Macros

#define N_SUMS   32
 
#define FNV_PRIME   16777619
 
#define CHECKSUM_COMP(checksum, value)
 

Functions

static uint32 pg_checksum_block (const PGChecksummablePage *page)
 
uint16 pg_checksum_page (char *page, BlockNumber blkno)
 

Variables

static const uint32 checksumBaseOffsets [N_SUMS]
 

Macro Definition Documentation

◆ CHECKSUM_COMP

#define CHECKSUM_COMP (   checksum,
  value 
)
Value:
do { \
uint32 __tmp = (checksum) ^ (value); \
(checksum) = __tmp * FNV_PRIME ^ (__tmp >> 17); \
} while (0)
uint32_t uint32
Definition c.h:624
#define FNV_PRIME
static struct @177 value
static int fb(int x)

Definition at line 137 of file checksum_impl.h.

138 { \
139 uint32 __tmp = (checksum) ^ (value); \
140 (checksum) = __tmp * FNV_PRIME ^ (__tmp >> 17); \
141} while (0)

◆ FNV_PRIME

#define FNV_PRIME   16777619

Definition at line 110 of file checksum_impl.h.

◆ N_SUMS

#define N_SUMS   32

Definition at line 108 of file checksum_impl.h.

Function Documentation

◆ pg_checksum_block()

static uint32 pg_checksum_block ( const PGChecksummablePage page)
static

Definition at line 154 of file checksum_impl.h.

◆ pg_checksum_page()

uint16 pg_checksum_page ( char page,
BlockNumber  blkno 
)

Definition at line 172 of file checksum_impl.h.

173{
176 uint32 checksum;
177
178 /* We only calculate the checksum for properly-initialized pages */
179 Assert(!PageIsNew((Page) page));
180
181 /*
182 * Save pd_checksum and temporarily set it to zero, so that the checksum
183 * calculation isn't affected by the old checksum stored on the page.
184 * Restore it after, because actually updating the checksum is NOT part of
185 * the API of this function.
186 */
187 save_checksum = cpage->phdr.pd_checksum;
188 cpage->phdr.pd_checksum = 0;
189 checksum = pg_checksum_block(cpage);
190 cpage->phdr.pd_checksum = save_checksum;
191
192 /* Mix in the block number to detect transposed pages */
193 checksum ^= blkno;
194
195 /*
196 * Reduce to a uint16 (to fit in the pd_checksum field) with an offset of
197 * one. That avoids checksums of zero, which seems like a good idea.
198 */
199 return (uint16) ((checksum % 65535) + 1);
200}
static bool PageIsNew(const PageData *page)
Definition bufpage.h:258
PageData * Page
Definition bufpage.h:81
#define Assert(condition)
Definition c.h:943
uint16_t uint16
Definition c.h:623
static uint32(* pg_checksum_block)(const PGChecksummablePage *page)
Definition checksum.c:64

References Assert, fb(), PageIsNew(), and pg_checksum_block.

Referenced by modify_rel_block(), page_checksum_internal(), PageIsVerified(), PageSetChecksum(), rewriteVisibilityMap(), scan_file(), and verify_page_checksum().

Variable Documentation

◆ checksumBaseOffsets

const uint32 checksumBaseOffsets[N_SUMS]
static
Initial value:
= {
0x5B1F36E9, 0xB8525960, 0x02AB50AA, 0x1DE66D2A,
0x79FF467A, 0x9BB9F8A3, 0x217E7CD2, 0x83E13D2C,
0xF8D4474F, 0xE39EB970, 0x42C6AE16, 0x993216FA,
0x7B093B5D, 0x98DAFF3C, 0xF718902A, 0x0B1C9CDB,
0xE58F764B, 0x187636BC, 0x5D7B3BB1, 0xE73DE7DE,
0x92BEC979, 0xCCA6C0B2, 0x304A0979, 0x85AA43D4,
0x783125BB, 0x6CA8EAA2, 0xE407EAC6, 0x4B5CFC3E,
0x9FBF8C76, 0x15CA20BE, 0xF2CA9FD3, 0x959BD756
}

Definition at line 123 of file checksum_impl.h.

123 {
124 0x5B1F36E9, 0xB8525960, 0x02AB50AA, 0x1DE66D2A,
125 0x79FF467A, 0x9BB9F8A3, 0x217E7CD2, 0x83E13D2C,
126 0xF8D4474F, 0xE39EB970, 0x42C6AE16, 0x993216FA,
127 0x7B093B5D, 0x98DAFF3C, 0xF718902A, 0x0B1C9CDB,
128 0xE58F764B, 0x187636BC, 0x5D7B3BB1, 0xE73DE7DE,
129 0x92BEC979, 0xCCA6C0B2, 0x304A0979, 0x85AA43D4,
130 0x783125BB, 0x6CA8EAA2, 0xE407EAC6, 0x4B5CFC3E,
131 0x9FBF8C76, 0x15CA20BE, 0xF2CA9FD3, 0x959BD756
132};