diff options
author | Andres Freund | 2022-04-07 01:26:17 +0000 |
---|---|---|
committer | Andres Freund | 2022-04-07 01:38:24 +0000 |
commit | e41aed674f35c63380175bb0e2dfa8dccfb2204d (patch) | |
tree | 2df5379b72989cd9c77a50fa9f4e995fed7e1e89 /src/backend/utils/activity/pgstat_replslot.c | |
parent | 8b1dccd37c71ed2ff016294d8f9053a32b02b19e (diff) |
pgstat: revise replication slot API in preparation for shared memory stats.
Previously the pgstat <-> replication slots API was done with on the basis of
names. However, the upcoming move to storing stats in shared memory makes it
more convenient to use a integer as key.
Change the replication slot functions to take the slot rather than the slot
name, and expose ReplicationSlotIndex() to compute the index of an replication
slot. Special handling will be required for restarts, as the index is not
stable across restarts. For now pgstat internally still uses names.
Rename pgstat_report_replslot_{create,drop}() to
pgstat_{create,drop}_replslot() to match the functions for other kinds of
stats.
Reviewed-By: Kyotaro Horiguchi <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/utils/activity/pgstat_replslot.c')
-rw-r--r-- | src/backend/utils/activity/pgstat_replslot.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index cfaf8d546c5..ceefc5d59b3 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -69,7 +69,7 @@ pgstat_reset_replslot(const char *name) * Report replication slot statistics. */ void -pgstat_report_replslot(const PgStat_StatReplSlotEntry *repSlotStat) +pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat) { PgStat_MsgReplSlot msg; @@ -93,14 +93,17 @@ pgstat_report_replslot(const PgStat_StatReplSlotEntry *repSlotStat) /* * Report replication slot creation. + * + * NB: This gets called with ReplicationSlotAllocationLock already held, be + * careful about calling back into slot.c. */ void -pgstat_report_replslot_create(const char *slotname) +pgstat_create_replslot(ReplicationSlot *slot) { PgStat_MsgReplSlot msg; pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT); - namestrcpy(&msg.m_slotname, slotname); + namestrcpy(&msg.m_slotname, NameStr(slot->data.name)); msg.m_create = true; msg.m_drop = false; pgstat_send(&msg, sizeof(PgStat_MsgReplSlot)); @@ -110,12 +113,12 @@ pgstat_report_replslot_create(const char *slotname) * Report replication slot drop. */ void -pgstat_report_replslot_drop(const char *slotname) +pgstat_drop_replslot(ReplicationSlot *slot) { PgStat_MsgReplSlot msg; pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT); - namestrcpy(&msg.m_slotname, slotname); + namestrcpy(&msg.m_slotname, NameStr(slot->data.name)); msg.m_create = false; msg.m_drop = true; pgstat_send(&msg, sizeof(PgStat_MsgReplSlot)); |