#include "utils/pgstat_internal.h"
-static int get_replslot_index(const char *name);
+static int get_replslot_index(const char *name, bool need_lock);
/*
Assert(name != NULL);
+ LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
+
/* Check if the slot exits with the given name. */
- slot = SearchNamedReplicationSlot(name, true);
+ slot = SearchNamedReplicationSlot(name, false);
if (!slot)
ereport(ERROR,
name)));
/*
- * Nothing to do for physical slots as we collect stats only for logical
- * slots.
+ * Reset stats if it is a logical slot. Nothing to do for physical slots
+ * as we collect stats only for logical slots.
*/
- if (SlotIsPhysical(slot))
- return;
+ if (SlotIsLogical(slot))
+ pgstat_reset(PGSTAT_KIND_REPLSLOT, InvalidOid,
+ ReplicationSlotIndex(slot));
- /* reset this one entry */
- pgstat_reset(PGSTAT_KIND_REPLSLOT, InvalidOid,
- ReplicationSlotIndex(slot));
+ LWLockRelease(ReplicationSlotControlLock);
}
/*
PgStat_StatReplSlotEntry *
pgstat_fetch_replslot(NameData slotname)
{
- int idx = get_replslot_index(NameStr(slotname));
+ int idx;
+ PgStat_StatReplSlotEntry *slotentry = NULL;
- if (idx == -1)
- return NULL;
+ LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
+
+ idx = get_replslot_index(NameStr(slotname), false);
+
+ if (idx != -1)
+ slotentry = (PgStat_StatReplSlotEntry *) pgstat_fetch_entry(PGSTAT_KIND_REPLSLOT,
+ InvalidOid, idx);
+
+ LWLockRelease(ReplicationSlotControlLock);
- return (PgStat_StatReplSlotEntry *)
- pgstat_fetch_entry(PGSTAT_KIND_REPLSLOT, InvalidOid, idx);
+ return slotentry;
}
void
bool
pgstat_replslot_from_serialized_name_cb(const NameData *name, PgStat_HashKey *key)
{
- int idx = get_replslot_index(NameStr(*name));
+ int idx = get_replslot_index(NameStr(*name), true);
/* slot might have been deleted */
if (idx == -1)
}
static int
-get_replslot_index(const char *name)
+get_replslot_index(const char *name, bool need_lock)
{
ReplicationSlot *slot;
Assert(name != NULL);
- slot = SearchNamedReplicationSlot(name, true);
+ slot = SearchNamedReplicationSlot(name, need_lock);
if (!slot)
return -1;