From 943f7ae1c8693cf3ea59d103aaf9590ea062fb9c Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Thu, 22 Feb 2024 08:40:40 +0900 Subject: Add lookup table for replication slot conflict reasons This commit switches the handling of the conflict cause strings for replication slots to use a table rather than being explicitly listed, using a C99-designated initializer syntax for the array elements. This makes the whole more readable while easing future maintenance with less areas to update when adding a new conflict reason. This is similar to 74a730631065, but the scale of the change is smaller as there are less conflict causes than LWLock builtin tranche names. Author: Bharath Rupireddy Reviewed-by: Jelte Fennema-Nio Discussion: https://postgr.es/m/CALj2ACUxSLA91QGFrJsWNKs58KXb1C03mbuwKmzqqmoAKLwJaw@mail.gmail.com --- src/include/replication/slot.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/include') diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h index e706ca834c0..acbf567150e 100644 --- a/src/include/replication/slot.h +++ b/src/include/replication/slot.h @@ -40,6 +40,9 @@ typedef enum ReplicationSlotPersistency /* * Slots can be invalidated, e.g. due to max_slot_wal_keep_size. If so, the * 'invalidated' field is set to a value other than _NONE. + * + * When adding a new invalidation cause here, remember to update + * SlotInvalidationCauses and RS_INVAL_MAX_CAUSES. */ typedef enum ReplicationSlotInvalidationCause { @@ -52,13 +55,7 @@ typedef enum ReplicationSlotInvalidationCause RS_INVAL_WAL_LEVEL, } ReplicationSlotInvalidationCause; -/* - * The possible values for 'conflict_reason' returned in - * pg_get_replication_slots. - */ -#define SLOT_INVAL_WAL_REMOVED_TEXT "wal_removed" -#define SLOT_INVAL_HORIZON_TEXT "rows_removed" -#define SLOT_INVAL_WAL_LEVEL_TEXT "wal_level_insufficient" +extern PGDLLIMPORT const char *const SlotInvalidationCauses[]; /* * On-Disk data of a replication slot, preserved across restarts. @@ -275,6 +272,6 @@ extern void CheckPointReplicationSlots(bool is_shutdown); extern void CheckSlotRequirements(void); extern void CheckSlotPermissions(void); extern ReplicationSlotInvalidationCause - GetSlotInvalidationCause(char *conflict_reason); + GetSlotInvalidationCause(const char *conflict_reason); #endif /* SLOT_H */ -- cgit v1.2.3