aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/slot.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/replication/slot.c')
-rw-r--r--src/backend/replication/slot.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 7817ad8659e..937b669e8cd 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -61,18 +61,29 @@ typedef struct ReplicationSlotOnDisk
uint32 version;
uint32 length;
+ /*
+ * The actual data in the slot that follows can differ based on the above
+ * 'version'.
+ */
+
ReplicationSlotPersistentData slotdata;
} ReplicationSlotOnDisk;
-/* size of the part of the slot that is version independent */
+/* size of version independent data */
#define ReplicationSlotOnDiskConstantSize \
offsetof(ReplicationSlotOnDisk, slotdata)
-/* size of the slots that is not version indepenent */
-#define ReplicationSlotOnDiskDynamicSize \
+/* size of the part of the slot not covered by the checksum */
+#define SnapBuildOnDiskNotChecksummedSize \
+ offsetof(ReplicationSlotOnDisk, version)
+/* size of the part covered by the checksum */
+#define SnapBuildOnDiskChecksummedSize \
+ sizeof(ReplicationSlotOnDisk) - SnapBuildOnDiskNotChecksummedSize
+/* size of the slot data that is version dependant */
+#define ReplicationSlotOnDiskV2Size \
sizeof(ReplicationSlotOnDisk) - ReplicationSlotOnDiskConstantSize
#define SLOT_MAGIC 0x1051CA1 /* format identifier */
-#define SLOT_VERSION 1 /* version for new files */
+#define SLOT_VERSION 2 /* version for new files */
/* Control array for replication slot management */
ReplicationSlotCtlData *ReplicationSlotCtl = NULL;
@@ -992,8 +1003,8 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
cp.magic = SLOT_MAGIC;
INIT_CRC32C(cp.checksum);
- cp.version = 1;
- cp.length = ReplicationSlotOnDiskDynamicSize;
+ cp.version = SLOT_VERSION;
+ cp.length = ReplicationSlotOnDiskV2Size;
SpinLockAcquire(&slot->mutex);
@@ -1002,8 +1013,9 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
SpinLockRelease(&slot->mutex);
COMP_CRC32C(cp.checksum,
- (char *) (&cp) + ReplicationSlotOnDiskConstantSize,
- ReplicationSlotOnDiskDynamicSize);
+ (char *) (&cp) + SnapBuildOnDiskNotChecksummedSize,
+ SnapBuildOnDiskChecksummedSize);
+ FIN_CRC32C(cp.checksum);
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
{
@@ -1155,7 +1167,7 @@ RestoreSlotFromDisk(const char *name)
path, cp.version)));
/* boundary check on length */
- if (cp.length != ReplicationSlotOnDiskDynamicSize)
+ if (cp.length != ReplicationSlotOnDiskV2Size)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("replication slot file \"%s\" has corrupted length %u",
@@ -1182,8 +1194,9 @@ RestoreSlotFromDisk(const char *name)
/* now verify the CRC */
INIT_CRC32C(checksum);
COMP_CRC32C(checksum,
- (char *) &cp + ReplicationSlotOnDiskConstantSize,
- ReplicationSlotOnDiskDynamicSize);
+ (char *) &cp + SnapBuildOnDiskNotChecksummedSize,
+ SnapBuildOnDiskChecksummedSize);
+ FIN_CRC32C(checksum);
if (!EQ_CRC32C(checksum, cp.checksum))
ereport(PANIC,