summaryrefslogtreecommitdiff
path: root/src/backend/utils/activity/pgstat_replslot.c
diff options
context:
space:
mode:
authorAndres Freund2022-04-07 00:56:19 +0000
committerAndres Freund2022-04-07 00:56:19 +0000
commit8fb580a35ce358063dfdd10991d017498283c767 (patch)
tree425767a0d794844d09fe549f89def74783ba6f05 /src/backend/utils/activity/pgstat_replslot.c
parent997afad89d12f314555600feee8189d753e105d1 (diff)
pgstat: prepare APIs used by pgstatfuncs for shared memory stats.
With the introduction of PgStat_Kind PgStat_Single_Reset_Type, PgStat_Shared_Reset_Target don't make sense anymore. Replace them with PgStat_Kind. Instead of having dedicated reset functions for different kinds of stats, use two generic helper routines (one to reset all stats of a kind, one to reset one stats entry). A number of reset functions were named pgstat_reset_*_counter(), despite affecting multiple counters. The generic helper routines get rid of pgstat_reset_single_counter(), pgstat_reset_subscription_counter(). Rename pgstat_reset_slru_counter(), pgstat_reset_replslot_counter() to pgstat_reset_slru(), pgstat_reset_replslot() respectively, and have them only deal with a single SLRU/slot. Resetting all SLRUs/slots goes through the generic pgstat_reset_of_kind(). Previously pg_stat_reset_replication_slot() used SearchNamedReplicationSlot() to check if a slot exists. API wise it seems better to move that to pgstat_replslot.c. This is done separately from the - quite large - shared memory statistics patch to make review easier. 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.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c
index 35078ad73c8..cfaf8d546c5 100644
--- a/src/backend/utils/activity/pgstat_replslot.c
+++ b/src/backend/utils/activity/pgstat_replslot.c
@@ -23,30 +23,45 @@
/*
- * Reset counters for a single replication slot, or all replication slots
- * (when name is null).
+ * Reset counters for a single replication slot.
*
* Permission checking for this function is managed through the normal
* GRANT system.
*/
void
-pgstat_reset_replslot_counter(const char *name)
+pgstat_reset_replslot(const char *name)
{
+ ReplicationSlot *slot;
PgStat_MsgResetreplslotcounter msg;
+ AssertArg(name != NULL);
+
if (pgStatSock == PGINVALID_SOCKET)
return;
- if (name)
- {
- namestrcpy(&msg.m_slotname, name);
- msg.clearall = false;
- }
- else
- msg.clearall = true;
+ /*
+ * Check if the slot exists with the given name. It is possible that by
+ * the time this message is executed the slot is dropped but at least this
+ * check will ensure that the given name is for a valid slot.
+ */
+ slot = SearchNamedReplicationSlot(name, true);
- pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETREPLSLOTCOUNTER);
+ if (!slot)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("replication slot \"%s\" does not exist",
+ name)));
+ /*
+ * Nothing to do for physical slots as we collect stats only for logical
+ * slots.
+ */
+ if (SlotIsPhysical(slot))
+ return;
+
+ pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETREPLSLOTCOUNTER);
+ namestrcpy(&msg.m_slotname, name);
+ msg.clearall = false;
pgstat_send(&msg, sizeof(msg));
}