mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
Reorganize our CRC source files again.
Now that we use CRC-32C in WAL and the control file, the "traditional" and "legacy" CRC-32 variants are not used in any frontend programs anymore. Move the code for those back from src/common to src/backend/utils/hash. Also move the slicing-by-8 implementation (back) to src/port. This is in preparation for next patch that will add another implementation that uses Intel SSE 4.2 instructions to calculate CRC-32C, where available.
This commit is contained in:
@@ -1023,8 +1023,8 @@ EndPrepare(GlobalTransaction gxact)
|
||||
TwoPhaseFileHeader *hdr;
|
||||
char path[MAXPGPATH];
|
||||
StateFileChunk *record;
|
||||
pg_crc32 statefile_crc;
|
||||
pg_crc32 bogus_crc;
|
||||
pg_crc32c statefile_crc;
|
||||
pg_crc32c bogus_crc;
|
||||
int fd;
|
||||
|
||||
/* Add the end sentinel to the list of 2PC records */
|
||||
@@ -1034,7 +1034,7 @@ EndPrepare(GlobalTransaction gxact)
|
||||
/* Go back and fill in total_len in the file header record */
|
||||
hdr = (TwoPhaseFileHeader *) records.head->data;
|
||||
Assert(hdr->magic == TWOPHASE_MAGIC);
|
||||
hdr->total_len = records.total_len + sizeof(pg_crc32);
|
||||
hdr->total_len = records.total_len + sizeof(pg_crc32c);
|
||||
|
||||
/*
|
||||
* If the file size exceeds MaxAllocSize, we won't be able to read it in
|
||||
@@ -1082,7 +1082,7 @@ EndPrepare(GlobalTransaction gxact)
|
||||
*/
|
||||
bogus_crc = ~statefile_crc;
|
||||
|
||||
if ((write(fd, &bogus_crc, sizeof(pg_crc32))) != sizeof(pg_crc32))
|
||||
if ((write(fd, &bogus_crc, sizeof(pg_crc32c))) != sizeof(pg_crc32c))
|
||||
{
|
||||
CloseTransientFile(fd);
|
||||
ereport(ERROR,
|
||||
@@ -1091,7 +1091,7 @@ EndPrepare(GlobalTransaction gxact)
|
||||
}
|
||||
|
||||
/* Back up to prepare for rewriting the CRC */
|
||||
if (lseek(fd, -((off_t) sizeof(pg_crc32)), SEEK_CUR) < 0)
|
||||
if (lseek(fd, -((off_t) sizeof(pg_crc32c)), SEEK_CUR) < 0)
|
||||
{
|
||||
CloseTransientFile(fd);
|
||||
ereport(ERROR,
|
||||
@@ -1135,7 +1135,7 @@ EndPrepare(GlobalTransaction gxact)
|
||||
/* If we crash now, we have prepared: WAL replay will fix things */
|
||||
|
||||
/* write correct CRC and close file */
|
||||
if ((write(fd, &statefile_crc, sizeof(pg_crc32))) != sizeof(pg_crc32))
|
||||
if ((write(fd, &statefile_crc, sizeof(pg_crc32c))) != sizeof(pg_crc32c))
|
||||
{
|
||||
CloseTransientFile(fd);
|
||||
ereport(ERROR,
|
||||
@@ -1223,7 +1223,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
|
||||
int fd;
|
||||
struct stat stat;
|
||||
uint32 crc_offset;
|
||||
pg_crc32 calc_crc,
|
||||
pg_crc32c calc_crc,
|
||||
file_crc;
|
||||
|
||||
TwoPhaseFilePath(path, xid);
|
||||
@@ -1258,14 +1258,14 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
|
||||
|
||||
if (stat.st_size < (MAXALIGN(sizeof(TwoPhaseFileHeader)) +
|
||||
MAXALIGN(sizeof(TwoPhaseRecordOnDisk)) +
|
||||
sizeof(pg_crc32)) ||
|
||||
sizeof(pg_crc32c)) ||
|
||||
stat.st_size > MaxAllocSize)
|
||||
{
|
||||
CloseTransientFile(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
crc_offset = stat.st_size - sizeof(pg_crc32);
|
||||
crc_offset = stat.st_size - sizeof(pg_crc32c);
|
||||
if (crc_offset != MAXALIGN(crc_offset))
|
||||
{
|
||||
CloseTransientFile(fd);
|
||||
@@ -1302,7 +1302,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
|
||||
COMP_CRC32C(calc_crc, buf, crc_offset);
|
||||
FIN_CRC32C(calc_crc);
|
||||
|
||||
file_crc = *((pg_crc32 *) (buf + crc_offset));
|
||||
file_crc = *((pg_crc32c *) (buf + crc_offset));
|
||||
|
||||
if (!EQ_CRC32C(calc_crc, file_crc))
|
||||
{
|
||||
@@ -1545,7 +1545,7 @@ void
|
||||
RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
|
||||
{
|
||||
char path[MAXPGPATH];
|
||||
pg_crc32 statefile_crc;
|
||||
pg_crc32c statefile_crc;
|
||||
int fd;
|
||||
|
||||
/* Recompute CRC */
|
||||
@@ -1572,7 +1572,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write two-phase state file: %m")));
|
||||
}
|
||||
if (write(fd, &statefile_crc, sizeof(pg_crc32)) != sizeof(pg_crc32))
|
||||
if (write(fd, &statefile_crc, sizeof(pg_crc32c)) != sizeof(pg_crc32c))
|
||||
{
|
||||
CloseTransientFile(fd);
|
||||
ereport(ERROR,
|
||||
|
||||
@@ -862,7 +862,7 @@ XLogRecPtr
|
||||
XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn)
|
||||
{
|
||||
XLogCtlInsert *Insert = &XLogCtl->Insert;
|
||||
pg_crc32 rdata_crc;
|
||||
pg_crc32c rdata_crc;
|
||||
bool inserted;
|
||||
XLogRecord *rechdr = (XLogRecord *) rdata->data;
|
||||
bool isLogSwitch = (rechdr->xl_rmid == RM_XLOG_ID &&
|
||||
@@ -4179,7 +4179,7 @@ WriteControlFile(void)
|
||||
static void
|
||||
ReadControlFile(void)
|
||||
{
|
||||
pg_crc32 crc;
|
||||
pg_crc32c crc;
|
||||
int fd;
|
||||
|
||||
/*
|
||||
@@ -4681,7 +4681,7 @@ BootStrapXLOG(void)
|
||||
bool use_existent;
|
||||
uint64 sysidentifier;
|
||||
struct timeval tv;
|
||||
pg_crc32 crc;
|
||||
pg_crc32c crc;
|
||||
|
||||
/*
|
||||
* Select a hopefully-unique system identifier code for this installation.
|
||||
|
||||
@@ -459,7 +459,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
|
||||
XLogRecData *rdt;
|
||||
uint32 total_len = 0;
|
||||
int block_id;
|
||||
pg_crc32 rdata_crc;
|
||||
pg_crc32c rdata_crc;
|
||||
registered_buffer *prev_regbuf = NULL;
|
||||
XLogRecData *rdt_datas_last;
|
||||
XLogRecord *rechdr;
|
||||
|
||||
@@ -665,7 +665,7 @@ ValidXLogRecordHeader(XLogReaderState *state, XLogRecPtr RecPtr,
|
||||
static bool
|
||||
ValidXLogRecord(XLogReaderState *state, XLogRecord *record, XLogRecPtr recptr)
|
||||
{
|
||||
pg_crc32 crc;
|
||||
pg_crc32c crc;
|
||||
|
||||
/* Calculate the CRC */
|
||||
INIT_CRC32C(crc);
|
||||
|
||||
Reference in New Issue
Block a user