PostgreSQL Source Code  git master
pgstat_replslot.c File Reference
#include "postgres.h"
#include "replication/slot.h"
#include "utils/builtins.h"
#include "utils/pgstat_internal.h"
Include dependency graph for pgstat_replslot.c:

Go to the source code of this file.

Macros

#define REPLSLOT_ACC(fld)   statent->fld += repSlotStat->fld
 

Functions

static int get_replslot_index (const char *name)
 
void pgstat_reset_replslot (const char *name)
 
void pgstat_report_replslot (ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
 
void pgstat_create_replslot (ReplicationSlot *slot)
 
void pgstat_acquire_replslot (ReplicationSlot *slot)
 
void pgstat_drop_replslot (ReplicationSlot *slot)
 
PgStat_StatReplSlotEntrypgstat_fetch_replslot (NameData slotname)
 
void pgstat_replslot_to_serialized_name_cb (const PgStat_HashKey *key, const PgStatShared_Common *header, NameData *name)
 
bool pgstat_replslot_from_serialized_name_cb (const NameData *name, PgStat_HashKey *key)
 
void pgstat_replslot_reset_timestamp_cb (PgStatShared_Common *header, TimestampTz ts)
 

Macro Definition Documentation

◆ REPLSLOT_ACC

#define REPLSLOT_ACC (   fld)    statent->fld += repSlotStat->fld

Function Documentation

◆ get_replslot_index()

static int get_replslot_index ( const char *  name)
static

Definition at line 212 of file pgstat_replslot.c.

213 {
214  ReplicationSlot *slot;
215 
216  Assert(name != NULL);
217 
218  slot = SearchNamedReplicationSlot(name, true);
219 
220  if (!slot)
221  return -1;
222 
223  return ReplicationSlotIndex(slot);
224 }
const char * name
Definition: encode.c:571
Assert(fmt[strlen(fmt) - 1] !='\n')
ReplicationSlot * SearchNamedReplicationSlot(const char *name, bool need_lock)
Definition: slot.c:375
int ReplicationSlotIndex(ReplicationSlot *slot)
Definition: slot.c:408

References Assert(), name, ReplicationSlotIndex(), and SearchNamedReplicationSlot().

Referenced by pgstat_fetch_replslot(), and pgstat_replslot_from_serialized_name_cb().

◆ pgstat_acquire_replslot()

void pgstat_acquire_replslot ( ReplicationSlot slot)

Definition at line 144 of file pgstat_replslot.c.

145 {
147  ReplicationSlotIndex(slot), true, NULL);
148 }
@ PGSTAT_KIND_REPLSLOT
Definition: pgstat.h:44
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create, bool *created_entry)
Definition: pgstat_shmem.c:397
#define InvalidOid
Definition: postgres_ext.h:36

References InvalidOid, pgstat_get_entry_ref(), PGSTAT_KIND_REPLSLOT, and ReplicationSlotIndex().

Referenced by ReplicationSlotAcquire().

◆ pgstat_create_replslot()

void pgstat_create_replslot ( ReplicationSlot slot)

Definition at line 111 of file pgstat_replslot.c.

112 {
113  PgStat_EntryRef *entry_ref;
114  PgStatShared_ReplSlot *shstatent;
115 
117  ReplicationSlotIndex(slot), false);
118  shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
119 
120  /*
121  * NB: need to accept that there might be stats from an older slot, e.g.
122  * if we previously crashed after dropping a slot.
123  */
124  memset(&shstatent->stats, 0, sizeof(shstatent->stats));
125 
126  pgstat_unlock_entry(entry_ref);
127 }
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:603
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait)
Definition: pgstat_shmem.c:612
PgStat_StatReplSlotEntry stats
PgStatShared_Common * shared_stats

References InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), PgStat_EntryRef::shared_stats, and PgStatShared_ReplSlot::stats.

Referenced by ReplicationSlotCreate().

◆ pgstat_drop_replslot()

void pgstat_drop_replslot ( ReplicationSlot slot)

Definition at line 154 of file pgstat_replslot.c.

155 {
157  ReplicationSlotIndex(slot));
158 }
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat_shmem.c:858

References InvalidOid, pgstat_drop_entry(), PGSTAT_KIND_REPLSLOT, and ReplicationSlotIndex().

Referenced by InvalidatePossiblyObsoleteSlot(), and ReplicationSlotDropPtr().

◆ pgstat_fetch_replslot()

PgStat_StatReplSlotEntry* pgstat_fetch_replslot ( NameData  slotname)

Definition at line 165 of file pgstat_replslot.c.

166 {
167  int idx = get_replslot_index(NameStr(slotname));
168 
169  if (idx == -1)
170  return NULL;
171 
172  return (PgStat_StatReplSlotEntry *)
174 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
#define NameStr(name)
Definition: c.h:730
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:804
static int get_replslot_index(const char *name)

References get_replslot_index(), idx(), InvalidOid, NameStr, pgstat_fetch_entry(), and PGSTAT_KIND_REPLSLOT.

Referenced by pg_stat_get_replication_slot().

◆ pgstat_replslot_from_serialized_name_cb()

bool pgstat_replslot_from_serialized_name_cb ( const NameData name,
PgStat_HashKey key 
)

Definition at line 190 of file pgstat_replslot.c.

191 {
193 
194  /* slot might have been deleted */
195  if (idx == -1)
196  return false;
197 
198  key->kind = PGSTAT_KIND_REPLSLOT;
199  key->dboid = InvalidOid;
200  key->objoid = idx;
201 
202  return true;
203 }

References get_replslot_index(), idx(), InvalidOid, sort-test::key, name, NameStr, and PGSTAT_KIND_REPLSLOT.

◆ pgstat_replslot_reset_timestamp_cb()

void pgstat_replslot_reset_timestamp_cb ( PgStatShared_Common header,
TimestampTz  ts 
)

Definition at line 206 of file pgstat_replslot.c.

207 {
208  ((PgStatShared_ReplSlot *) header)->stats.stat_reset_timestamp = ts;
209 }

◆ pgstat_replslot_to_serialized_name_cb()

void pgstat_replslot_to_serialized_name_cb ( const PgStat_HashKey key,
const PgStatShared_Common header,
NameData name 
)

Definition at line 177 of file pgstat_replslot.c.

178 {
179  /*
180  * This is only called late during shutdown. The set of existing slots
181  * isn't allowed to change at this point, we can assume that a slot exists
182  * at the offset.
183  */
184  if (!ReplicationSlotName(key->objoid, name))
185  elog(ERROR, "could not find name for replication slot index %u",
186  key->objoid);
187 }
#define ERROR
Definition: elog.h:39
bool ReplicationSlotName(int index, Name name)
Definition: slot.c:424

References elog(), ERROR, sort-test::key, name, and ReplicationSlotName().

◆ pgstat_report_replslot()

void pgstat_report_replslot ( ReplicationSlot slot,
const PgStat_StatReplSlotEntry repSlotStat 
)

Definition at line 78 of file pgstat_replslot.c.

79 {
80  PgStat_EntryRef *entry_ref;
81  PgStatShared_ReplSlot *shstatent;
82  PgStat_StatReplSlotEntry *statent;
83 
85  ReplicationSlotIndex(slot), false);
86  shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats;
87  statent = &shstatent->stats;
88 
89  /* Update the replication slot statistics */
90 #define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
91  REPLSLOT_ACC(spill_txns);
92  REPLSLOT_ACC(spill_count);
93  REPLSLOT_ACC(spill_bytes);
94  REPLSLOT_ACC(stream_txns);
95  REPLSLOT_ACC(stream_count);
96  REPLSLOT_ACC(stream_bytes);
97  REPLSLOT_ACC(total_txns);
98  REPLSLOT_ACC(total_bytes);
99 #undef REPLSLOT_ACC
100 
101  pgstat_unlock_entry(entry_ref);
102 }
#define REPLSLOT_ACC(fld)

References InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), REPLSLOT_ACC, PgStat_EntryRef::shared_stats, and PgStatShared_ReplSlot::stats.

Referenced by UpdateDecodingStats().

◆ pgstat_reset_replslot()

void pgstat_reset_replslot ( const char *  name)

Definition at line 43 of file pgstat_replslot.c.

44 {
45  ReplicationSlot *slot;
46 
47  Assert(name != NULL);
48 
49  /* Check if the slot exits with the given name. */
50  slot = SearchNamedReplicationSlot(name, true);
51 
52  if (!slot)
53  ereport(ERROR,
54  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
55  errmsg("replication slot \"%s\" does not exist",
56  name)));
57 
58  /*
59  * Nothing to do for physical slots as we collect stats only for logical
60  * slots.
61  */
62  if (SlotIsPhysical(slot))
63  return;
64 
65  /* reset this one entry */
67  ReplicationSlotIndex(slot));
68 }
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ereport(elevel,...)
Definition: elog.h:149
void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid)
Definition: pgstat.c:726
#define SlotIsPhysical(slot)
Definition: slot.h:183

References Assert(), ereport, errcode(), errmsg(), ERROR, InvalidOid, name, PGSTAT_KIND_REPLSLOT, pgstat_reset(), ReplicationSlotIndex(), SearchNamedReplicationSlot(), and SlotIsPhysical.

Referenced by pg_stat_reset_replication_slot().