aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/replication/slot.c45
-rw-r--r--src/backend/replication/slotfuncs.c24
2 files changed, 38 insertions, 31 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index a142855bd32..233652b4799 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -77,6 +77,22 @@ typedef struct ReplicationSlotOnDisk
ReplicationSlotPersistentData slotdata;
} ReplicationSlotOnDisk;
+/*
+ * Lookup table for slot invalidation causes.
+ */
+const char *const SlotInvalidationCauses[] = {
+ [RS_INVAL_NONE] = "none",
+ [RS_INVAL_WAL_REMOVED] = "wal_removed",
+ [RS_INVAL_HORIZON] = "rows_removed",
+ [RS_INVAL_WAL_LEVEL] = "wal_level_insufficient",
+};
+
+/* Maximum number of invalidation causes */
+#define RS_INVAL_MAX_CAUSES RS_INVAL_WAL_LEVEL
+
+StaticAssertDecl(lengthof(SlotInvalidationCauses) == (RS_INVAL_MAX_CAUSES + 1),
+ "array length mismatch");
+
/* size of version independent data */
#define ReplicationSlotOnDiskConstantSize \
offsetof(ReplicationSlotOnDisk, slotdata)
@@ -2290,23 +2306,26 @@ RestoreSlotFromDisk(const char *name)
}
/*
- * Maps the pg_replication_slots.conflict_reason text value to
- * ReplicationSlotInvalidationCause enum value
+ * Maps a conflict reason for a replication slot to
+ * ReplicationSlotInvalidationCause.
*/
ReplicationSlotInvalidationCause
-GetSlotInvalidationCause(char *conflict_reason)
+GetSlotInvalidationCause(const char *conflict_reason)
{
+ ReplicationSlotInvalidationCause cause;
+ bool found PG_USED_FOR_ASSERTS_ONLY = false;
+
Assert(conflict_reason);
- if (strcmp(conflict_reason, SLOT_INVAL_WAL_REMOVED_TEXT) == 0)
- return RS_INVAL_WAL_REMOVED;
- else if (strcmp(conflict_reason, SLOT_INVAL_HORIZON_TEXT) == 0)
- return RS_INVAL_HORIZON;
- else if (strcmp(conflict_reason, SLOT_INVAL_WAL_LEVEL_TEXT) == 0)
- return RS_INVAL_WAL_LEVEL;
- else
- Assert(0);
+ for (cause = RS_INVAL_NONE; cause <= RS_INVAL_MAX_CAUSES; cause++)
+ {
+ if (strcmp(SlotInvalidationCauses[cause], conflict_reason) == 0)
+ {
+ found = true;
+ break;
+ }
+ }
- /* Keep compiler quiet */
- return RS_INVAL_NONE;
+ Assert(found);
+ return cause;
}
diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c
index d2fa5e669a3..c108bf9608f 100644
--- a/src/backend/replication/slotfuncs.c
+++ b/src/backend/replication/slotfuncs.c
@@ -413,24 +413,12 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
nulls[i++] = true;
else
{
- switch (slot_contents.data.invalidated)
- {
- case RS_INVAL_NONE:
- nulls[i++] = true;
- break;
-
- case RS_INVAL_WAL_REMOVED:
- values[i++] = CStringGetTextDatum(SLOT_INVAL_WAL_REMOVED_TEXT);
- break;
-
- case RS_INVAL_HORIZON:
- values[i++] = CStringGetTextDatum(SLOT_INVAL_HORIZON_TEXT);
- break;
-
- case RS_INVAL_WAL_LEVEL:
- values[i++] = CStringGetTextDatum(SLOT_INVAL_WAL_LEVEL_TEXT);
- break;
- }
+ ReplicationSlotInvalidationCause cause = slot_contents.data.invalidated;
+
+ if (cause == RS_INVAL_NONE)
+ nulls[i++] = true;
+ else
+ values[i++] = CStringGetTextDatum(SlotInvalidationCauses[cause]);
}
values[i++] = BoolGetDatum(slot_contents.data.failover);