mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-01-09 14:45:47 +02:00
Update CRC32 algorithm to CRC32C
This is to be compatible with Postgres >= 9.5 that switched to a more performant algorithm. Per reminder from Zhuravlev Uriy.
This commit is contained in:
parent
55db450c6f
commit
25ebddb02b
32
data.c
32
data.c
@ -68,7 +68,7 @@ doDeflate(z_stream *zp, size_t in_size, size_t out_size, void *inbuf,
|
||||
}
|
||||
|
||||
/* update CRC */
|
||||
COMP_CRC32(*crc, outbuf, out_size - zp->avail_out);
|
||||
COMP_CRC32C(*crc, outbuf, out_size - zp->avail_out);
|
||||
|
||||
*write_size += out_size - zp->avail_out;
|
||||
|
||||
@ -146,7 +146,7 @@ doInflate(z_stream *zp, size_t in_size, size_t out_size,void *inbuf,
|
||||
}
|
||||
|
||||
/* update CRC */
|
||||
COMP_CRC32(*crc, outbuf, out_size - zp->avail_out);
|
||||
COMP_CRC32C(*crc, outbuf, out_size - zp->avail_out);
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -216,7 +216,7 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
z_stream z;
|
||||
char outbuf[zlibOutSize];
|
||||
#endif
|
||||
INIT_CRC32(crc);
|
||||
INIT_CRC32C(crc);
|
||||
|
||||
/* reset size summary */
|
||||
file->read_size = 0;
|
||||
@ -226,7 +226,7 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
in = fopen(file->path, "r");
|
||||
if (in == NULL)
|
||||
{
|
||||
FIN_CRC32(crc);
|
||||
FIN_CRC32C(crc);
|
||||
file->crc = crc;
|
||||
|
||||
/* maybe vanished, it's not error */
|
||||
@ -338,9 +338,9 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
}
|
||||
|
||||
/* update CRC */
|
||||
COMP_CRC32(crc, &header, sizeof(header));
|
||||
COMP_CRC32(crc, page.data, header.hole_offset);
|
||||
COMP_CRC32(crc, page.data + upper_offset, upper_length);
|
||||
COMP_CRC32C(crc, &header, sizeof(header));
|
||||
COMP_CRC32C(crc, page.data, header.hole_offset);
|
||||
COMP_CRC32C(crc, page.data + upper_offset, upper_length);
|
||||
|
||||
file->write_size += sizeof(header) + read_len - header.hole_length;
|
||||
}
|
||||
@ -393,7 +393,7 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
_("can't write at block %u of \"%s\": %s"),
|
||||
blknum, to_path, strerror(errno_tmp));
|
||||
}
|
||||
COMP_CRC32(crc, &header, sizeof(header));
|
||||
COMP_CRC32C(crc, &header, sizeof(header));
|
||||
file->write_size += sizeof(header);
|
||||
}
|
||||
}
|
||||
@ -418,7 +418,7 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
blknum, to_path, strerror(errno_tmp));
|
||||
}
|
||||
|
||||
COMP_CRC32(crc, page.data, read_len);
|
||||
COMP_CRC32C(crc, page.data, read_len);
|
||||
file->write_size += read_len;
|
||||
}
|
||||
|
||||
@ -462,7 +462,7 @@ backup_data_file(const char *from_root, const char *to_root,
|
||||
fclose(out);
|
||||
|
||||
/* finish CRC calculation and store into pgFile */
|
||||
FIN_CRC32(crc);
|
||||
FIN_CRC32C(crc);
|
||||
file->crc = crc;
|
||||
|
||||
/* Treat empty file as not-datafile */
|
||||
@ -553,7 +553,7 @@ restore_data_file(const char *from_root,
|
||||
if (inflateInit(&z) != Z_OK)
|
||||
elog(ERROR_SYSTEM, _("can't initialize compression library: %s"),
|
||||
z.msg);
|
||||
INIT_CRC32(crc);
|
||||
INIT_CRC32C(crc);
|
||||
read_size = 0;
|
||||
}
|
||||
#endif
|
||||
@ -700,7 +700,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
char outbuf[zlibOutSize];
|
||||
char inbuf[zlibInSize];
|
||||
#endif
|
||||
INIT_CRC32(crc);
|
||||
INIT_CRC32C(crc);
|
||||
|
||||
/* reset size summary */
|
||||
file->read_size = 0;
|
||||
@ -710,7 +710,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
in = fopen(file->path, "r");
|
||||
if (in == NULL)
|
||||
{
|
||||
FIN_CRC32(crc);
|
||||
FIN_CRC32C(crc);
|
||||
file->crc = crc;
|
||||
|
||||
/* maybe deleted, it's not error */
|
||||
@ -825,7 +825,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
strerror(errno_tmp));
|
||||
}
|
||||
/* update CRC */
|
||||
COMP_CRC32(crc, buf, read_len);
|
||||
COMP_CRC32C(crc, buf, read_len);
|
||||
|
||||
file->write_size += sizeof(buf);
|
||||
file->read_size += sizeof(buf);
|
||||
@ -862,7 +862,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
strerror(errno_tmp));
|
||||
}
|
||||
/* update CRC */
|
||||
COMP_CRC32(crc, buf, read_len);
|
||||
COMP_CRC32C(crc, buf, read_len);
|
||||
|
||||
file->write_size += read_len;
|
||||
}
|
||||
@ -900,7 +900,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
|
||||
|
||||
#endif
|
||||
/* finish CRC calculation and store into pgFile */
|
||||
FIN_CRC32(crc);
|
||||
FIN_CRC32C(crc);
|
||||
file->crc = crc;
|
||||
|
||||
/* update file permission */
|
||||
|
8
dir.c
8
dir.c
@ -141,20 +141,20 @@ pgFileGetCRC(pgFile *file)
|
||||
file->path, strerror(errno));
|
||||
|
||||
/* calc CRC of backup file */
|
||||
INIT_CRC32(crc);
|
||||
INIT_CRC32C(crc);
|
||||
while ((len = fread(buf, 1, sizeof(buf), fp)) == sizeof(buf))
|
||||
{
|
||||
if (interrupted)
|
||||
elog(ERROR_INTERRUPTED, _("interrupted during CRC calculation"));
|
||||
COMP_CRC32(crc, buf, len);
|
||||
COMP_CRC32C(crc, buf, len);
|
||||
}
|
||||
errno_tmp = errno;
|
||||
if (!feof(fp))
|
||||
elog(WARNING, _("can't read \"%s\": %s"), file->path,
|
||||
strerror(errno_tmp));
|
||||
if (len > 0)
|
||||
COMP_CRC32(crc, buf, len);
|
||||
FIN_CRC32(crc);
|
||||
COMP_CRC32C(crc, buf, len);
|
||||
FIN_CRC32C(crc);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
|
@ -679,13 +679,13 @@ get_current_timeline(void)
|
||||
close(fd);
|
||||
|
||||
/* Check the CRC. */
|
||||
INIT_CRC32(crc);
|
||||
COMP_CRC32(crc,
|
||||
INIT_CRC32C(crc);
|
||||
COMP_CRC32C(crc,
|
||||
(char *) &ControlFile,
|
||||
offsetof(ControlFileData, crc));
|
||||
FIN_CRC32(crc);
|
||||
FIN_CRC32C(crc);
|
||||
|
||||
if (!EQ_CRC32(crc, ControlFile.crc))
|
||||
if (!EQ_CRC32C(crc, ControlFile.crc))
|
||||
{
|
||||
elog(WARNING, _("Calculated CRC checksum does not match value stored in file.\n"
|
||||
"Either the file is corrupt, or it has a different layout than this program\n"
|
||||
|
Loading…
Reference in New Issue
Block a user