PostgreSQL Source Code git master
Loading...
Searching...
No Matches
checksum_impl.h File Reference
#include "storage/bufpage.h"
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:546
#define FNV_PRIME
static struct @172 value
static int fb(int x)

Definition at line 135 of file checksum_impl.h.

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

◆ FNV_PRIME

#define FNV_PRIME   16777619

Definition at line 108 of file checksum_impl.h.

◆ N_SUMS

#define N_SUMS   32

Definition at line 106 of file checksum_impl.h.

Function Documentation

◆ pg_checksum_block()

static uint32 pg_checksum_block ( const PGChecksummablePage page)
static

Definition at line 146 of file checksum_impl.h.

147{
149 uint32 result = 0;
150 uint32 i,
151 j;
152
153 /* ensure that the size is compatible with the algorithm */
155
156 /* initialize partial checksums to their corresponding offsets */
158
159 /* main checksum calculation */
160 for (i = 0; i < (uint32) (BLCKSZ / (sizeof(uint32) * N_SUMS)); i++)
161 for (j = 0; j < N_SUMS; j++)
162 CHECKSUM_COMP(sums[j], page->data[i][j]);
163
164 /* finally add in two rounds of zeroes for additional mixing */
165 for (i = 0; i < 2; i++)
166 for (j = 0; j < N_SUMS; j++)
167 CHECKSUM_COMP(sums[j], 0);
168
169 /* xor fold partial checksums together */
170 for (i = 0; i < N_SUMS; i++)
171 result ^= sums[i];
172
173 return result;
174}
#define Assert(condition)
Definition c.h:873
static const uint32 checksumBaseOffsets[N_SUMS]
#define CHECKSUM_COMP(checksum, value)
#define N_SUMS
int j
Definition isn.c:78
int i
Definition isn.c:77
uint32 data[BLCKSZ/(sizeof(uint32) *N_SUMS)][N_SUMS]

References Assert, CHECKSUM_COMP, checksumBaseOffsets, PGChecksummablePage::data, fb(), i, j, and N_SUMS.

Referenced by pg_checksum_page().

◆ pg_checksum_page()

uint16 pg_checksum_page ( char page,
BlockNumber  blkno 
)

Definition at line 187 of file checksum_impl.h.

188{
191 uint32 checksum;
192
193 /* We only calculate the checksum for properly-initialized pages */
194 Assert(!PageIsNew((Page) page));
195
196 /*
197 * Save pd_checksum and temporarily set it to zero, so that the checksum
198 * calculation isn't affected by the old checksum stored on the page.
199 * Restore it after, because actually updating the checksum is NOT part of
200 * the API of this function.
201 */
202 save_checksum = cpage->phdr.pd_checksum;
203 cpage->phdr.pd_checksum = 0;
204 checksum = pg_checksum_block(cpage);
205 cpage->phdr.pd_checksum = save_checksum;
206
207 /* Mix in the block number to detect transposed pages */
208 checksum ^= blkno;
209
210 /*
211 * Reduce to a uint16 (to fit in the pd_checksum field) with an offset of
212 * one. That avoids checksums of zero, which seems like a good idea.
213 */
214 return (uint16) ((checksum % 65535) + 1);
215}
static bool PageIsNew(const PageData *page)
Definition bufpage.h:233
PageData * Page
Definition bufpage.h:81
uint16_t uint16
Definition c.h:545
static uint32 pg_checksum_block(const PGChecksummablePage *page)

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

Referenced by modify_rel_block(), page_checksum_internal(), PageIsVerified(), PageSetChecksumCopy(), PageSetChecksumInplace(), 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 121 of file checksum_impl.h.

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

Referenced by pg_checksum_block().