8000 Reorganize our CRC source files again. · postgrespro/postgres@4f700bc · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f700bc

Browse files
committed
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.
1 parent d577bb8 commit 4f700bc

File tree

25 files changed

+211
-181
lines changed
  • cache
  • hash
  • bin
  • common
  • include
  • port
  • tools/msvc
  • 25 files changed

    +211
    -181
    lines changed

    contrib/hstore/hstore_gist.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,7 @@
    66
    #include "access/gist.h"
    77
    #include "access/skey.h"
    88
    #include "catalog/pg_type.h"
    9-
    #include "common/pg_crc.h"
    9+
    #include "utils/pg_crc.h"
    1010

    1111
    #include "hstore.h"
    1212

    contrib/ltree/crc32.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -20,7 +20,7 @@
    2020
    #define TOLOWER(x) (x)
    2121
    #endif
    2222

    23-
    #include "common/pg_crc.h"
    23+
    #include "utils/pg_crc.h"
    2424
    #include "crc32.h"
    2525

    2626
    unsigned int

    contrib/pg_trgm/trgm_op.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,6 +10,7 @@
    1010
    #include "catalog/pg_type.h"
    1111
    #include "tsearch/ts_locale.h"
    1212
    #include "utils/memutils.h"
    13+
    #include "utils/pg_crc.h"
    1314

    1415
    PG_MODULE_MAGIC;
    1516

    src/backend/access/transam/twophase.c

    8000 Lines changed: 12 additions & 12 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1023,8 +1023,8 @@ EndPrepare(GlobalTransaction gxact)
    10231023
    TwoPhaseFileHeader *hdr;
    10241024
    char path[MAXPGPATH];
    10251025
    StateFileChunk *record;
    1026-
    pg_crc32 statefile_crc;
    1027-
    pg_crc32 bogus_crc;
    1026+
    pg_crc32c statefile_crc;
    1027+
    pg_crc32c bogus_crc;
    10281028
    int fd;
    10291029

    10301030
    /* Add the end sentinel to the list of 2PC records */
    @@ -1034,7 +1034,7 @@ EndPrepare(GlobalTransaction gxact)
    10341034
    /* Go back and fill in total_len in the file header record */
    10351035
    hdr = (TwoPhaseFileHeader *) records.head->data;
    10361036
    Assert(hdr->magic == TWOPHASE_MAGIC);
    1037-
    hdr->total_len = records.total_len + sizeof(pg_crc32);
    1037+
    hdr->total_len = records.total_len + sizeof(pg_crc32c);
    10381038

    10391039
    /*
    10401040
    * If the file size exceeds MaxAllocSize, we won't be able to read it in
    @@ -1082,7 +1082,7 @@ EndPrepare(GlobalTransaction gxact)
    10821082
    */
    10831083
    bogus_crc = ~statefile_crc;
    10841084

    1085-
    if ((write(fd, &bogus_crc, sizeof(pg_crc32))) != sizeof(pg_crc32))
    1085+
    if ((write(fd, &bogus_crc, sizeof(pg_crc32c))) != sizeof(pg_crc32c))
    10861086
    {
    10871087
    CloseTransientFile(fd);
    10881088
    ereport(ERROR,
    @@ -1091,7 +1091,7 @@ EndPrepare(GlobalTransaction gxact)
    10911091
    }
    10921092

    10931093
    /* Back up to prepare for rewriting the CRC */
    1094-
    if (lseek(fd, -((off_t) sizeof(pg_crc32)), SEEK_CUR) < 0)
    1094+
    if (lseek(fd, -((off_t) sizeof(pg_crc32c)), SEEK_CUR) < 0)
    10951095
    {
    10961096
    CloseTransientFile(fd);
    10971097
    ereport(ERROR,
    @@ -1135,7 +1135,7 @@ EndPrepare(GlobalTransaction gxact)
    11351135
    /* If we crash now, we have prepared: WAL replay will fix things */
    11361136

    11371137
    /* write correct CRC and close file */
    1138-
    if ((write(fd, &statefile_crc, sizeof(pg_crc32))) != sizeof(pg_crc32))
    1138+
    if ((write(fd, &statefile_crc, sizeof(pg_crc32c))) != sizeof(pg_crc32c))
    11391139
    {
    11401140
    CloseTransientFile(fd);
    11411141
    ereport(ERROR,
    @@ -1223,7 +1223,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
    12231223
    int fd;
    12241224
    struct stat stat;
    12251225
    uint32 crc_offset;
    1226-
    pg_crc32 calc_crc,
    1226+
    pg_crc32c calc_crc,
    12271227
    file_crc;
    12281228

    12291229
    TwoPhaseFilePath(path, xid);
    @@ -1258,14 +1258,14 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
    12581258

    12591259
    if (stat.st_size < (MAXALIGN(sizeof(TwoPhaseFileHeader)) +
    12601260
    MAXALIGN(sizeof(TwoPhaseRecordOnDisk)) +
    1261-
    sizeof(pg_crc32)) ||
    1261+
    sizeof(pg_crc32c)) ||
    12621262
    stat.st_size > MaxAllocSize)
    12631263
    {
    12641264
    CloseTransientFile(fd);
    12651265
    return NULL;
    12661266
    }
    12671267

    1268-
    crc_offset = stat.st_size - sizeof(pg_crc32);
    1268+
    crc_offset = stat.st_size - sizeof(pg_crc32c);
    12691269
    if (crc_offset != MAXALIGN(crc_offset))
    12701270
    {
    12711271
    CloseTransientFile(fd);
    @@ -1302,7 +1302,7 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
    13021302
    COMP_CRC32C(calc_crc, buf, crc_offset);
    13031303
    FIN_CRC32C(calc_crc);
    13041304

    1305-
    file_crc = *((pg_crc32 *) (buf + crc_offset));
    1305+
    file_crc = *((pg_crc32c *) (buf + crc_offset));
    13061306

    13071307
    if (!EQ_CRC32C(calc_crc, file_crc))
    13081308
    {
    @@ -1545,7 +1545,7 @@ void
    15451545
    RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
    15461546
    {
    15471547
    char path[MAXPGPATH];
    1548-
    pg_crc32 statefile_crc;
    1548+
    pg_crc32c statefile_crc;
    15491549
    int fd;
    15501550

    15511551
    /* Recompute CRC */
    @@ -1572,7 +1572,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
    15721572
    (errcode_for_file_access(),
    15731573
    errmsg("could not write two-phase state file: %m")));
    15741574
    }
    1575-
    if (write(fd, &statefile_crc, sizeof(pg_crc32)) != sizeof(pg_crc32))
    1575+
    if (write(fd, &statefile_crc, sizeof(pg_crc32c)) != sizeof(pg_crc32c))
    15761576
    {
    15771577
    CloseTransientFile(fd);
    15781578
    ereport(ERROR,

    src/backend/access/transam/xlog.c

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -862,7 +862,7 @@ XLogRecPtr
    862862
    XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn)
    863863
    {
    864864
    XLogCtlInsert *Insert = &XLogCtl->Insert;
    865-
    pg_crc32 rdata_crc;
    865+
    pg_crc32c rdata_crc;
    866866
    bool inserted;
    867867
    XLogRecord *rechdr = (XLogRecord *) rdata->data;
    868868
    bool isLogSwitch = (rechdr->xl_rmid == RM_XLOG_ID &&
    @@ -4179,7 +4179,7 @@ WriteControlFile(void)
    41794179
    static void
    41804180
    ReadControlFile(void)
    41814181
    {
    4182-
    pg_crc32 crc;
    4182+
    pg_crc32c crc;
    41834183
    int fd;
    41844184

    41854185
    /*
    @@ -4681,7 +4681,7 @@ BootStrapXLOG(void)
    46814681
    bool use_existent;
    46824682
    uint64 sysidentifier;
    46834683
    struct timeval tv;
    4684-
    pg_crc32 crc;
    4684+
    pg_crc32c crc;
    46854685

    46864686
    /*
    46874687
    * Select a hopefully-unique system identifier code for this installation.

    src/backend/access/transam/xloginsert.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -459,7 +459,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
    459459
    XLogRecData *rdt;
    460460
    uint32 total_len = 0;
    461461
    int block_id;
    462-
    pg_crc32 rdata_crc;
    462+
    pg_crc32c rdata_crc;
    463463
    registered_buffer *prev_regbuf = NULL;
    464464
    XLogRecData *rdt_datas_last;
    465465
    XLogRecord *rechdr;

    src/backend/access/transam/xlogreader.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -665,7 +665,7 @@ ValidXLogRecordHeader(XLogReaderState *state, XLogRecPtr RecPtr,
    665665
    static bool
    666666
    ValidXLogRecord(XLogReaderState *state, XLogRecord *record, XLogRecPtr recptr)
    667667
    {
    668-
    pg_crc32 crc;
    668+
    pg_crc32c crc;
    669669

    670670
    /* Calculate the CRC */
    671671
    INIT_CRC32C(crc);

    src/backend/replication/logical/snapbuild.c

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1391,7 +1391,7 @@ typedef struct SnapBuildOnDisk
    13911391

    13921392
    /* data not covered by checksum */
    13931393
    uint32 magic;
    1394-
    pg_crc32 checksum;
    1394+
    pg_crc32c checksum;
    13951395

    13961396
    /* data covered by checksum */
    13971397

    @@ -1634,7 +1634,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
    16341634
    char path[MAXPGPATH];
    16351635
    Size sz;
    16361636
    int readBytes;
    1637-
    pg_crc32 checksum;
    1637+
    pg_crc32c checksum;
    16381638

    16391639
    /* no point in loading a snapshot if we're already there */
    16401640
    if (builder->state == SNAPBUILD_CONSISTENT)

    src/backend/replication/slot.c

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -56,7 +56,7 @@ typedef struct ReplicationSlotOnDisk
    5656

    5757
    /* data not covered by checksum */
    5858
    uint32 magic;
    59-
    pg_crc32 checksum;
    59+
    pg_crc32c checksum;
    6060

    6161
    /* data covered by checksum */
    6262
    uint32 version;
    @@ -1075,7 +1075,7 @@ RestoreSlotFromDisk(const char *name)
    10751075
    int fd;
    10761076
    bool restored = false;
    10771077
    int readBytes;
    1078-
    pg_crc32 checksum;
    1078+
    pg_crc32c checksum;
    10791079

    10801080
    /* no need to lock here, no concurrent access allowed yet */
    10811081

    src/backend/utils/adt/tsgistidx.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -17,6 +17,7 @@
    1717
    #include "access/gist.h"
    1818
    #include "access/tuptoaster.h"
    1919
    #include "tsearch/ts_utils.h"
    20+
    #include "utils/pg_crc.h"
    2021

    2122

    2223
    #define SIGLENINT 31 /* >121 => key will toast, so it will not work

    0 commit comments

    Comments
     (0)
    0