PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgstat_replslot.c File Reference
#include "postgres.h"
#include "replication/slot.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, bool need_lock)
 
void pgstat_reset_replslot (const char *name)
 
void pgstat_report_replslot (ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
 
void pgstat_report_replslotsync (ReplicationSlot *slot)
 
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,
bool  need_lock 
)
static

Definition at line 254 of file pgstat_replslot.c.

255{
256 ReplicationSlot *slot;
257
258 Assert(name != NULL);
259
261
262 if (!slot)
263 return -1;
264
265 return ReplicationSlotIndex(slot);
266}
#define Assert(condition)
Definition c.h:873
static int fb(int x)
int ReplicationSlotIndex(ReplicationSlot *slot)
Definition slot.c:573
ReplicationSlot * SearchNamedReplicationSlot(const char *name, bool need_lock)
Definition slot.c:540
const char * name

References Assert, fb(), 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 176 of file pgstat_replslot.c.

177{
179 ReplicationSlotIndex(slot), true, NULL);
180}
#define PGSTAT_KIND_REPLSLOT
Definition pgstat_kind.h:30
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry)
#define InvalidOid

References fb(), 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 141 of file pgstat_replslot.c.

142{
143 PgStat_EntryRef *entry_ref;
145
147
149 ReplicationSlotIndex(slot), false);
151
152 /*
153 * NB: need to accept that there might be stats from an older slot, e.g.
154 * if we previously crashed after dropping a slot.
155 */
156 memset(&shstatent->stats, 0, sizeof(shstatent->stats));
157
158 pgstat_unlock_entry(entry_ref);
159}
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1955
@ LW_EXCLUSIVE
Definition lwlock.h:112
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
PgStatShared_Common * shared_stats

References Assert, fb(), InvalidOid, LW_EXCLUSIVE, LWLockHeldByMeInMode(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), and PgStat_EntryRef::shared_stats.

Referenced by ReplicationSlotCreate().

◆ pgstat_drop_replslot()

void pgstat_drop_replslot ( ReplicationSlot slot)

◆ pgstat_fetch_replslot()

PgStat_StatReplSlotEntry * pgstat_fetch_replslot ( NameData  slotname)

Definition at line 200 of file pgstat_replslot.c.

201{
202 int idx;
204
206
207 idx = get_replslot_index(NameStr(slotname), false);
208
209 if (idx != -1)
211 InvalidOid, idx);
212
214
215 return slotentry;
216}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262
#define NameStr(name)
Definition c.h:765
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1176
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1793
@ LW_SHARED
Definition lwlock.h:113
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:944
static int get_replslot_index(const char *name, bool need_lock)

References fb(), get_replslot_index(), idx(), InvalidOid, LW_SHARED, LWLockAcquire(), LWLockRelease(), 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 232 of file pgstat_replslot.c.

233{
234 int idx = get_replslot_index(NameStr(*name), true);
235
236 /* slot might have been deleted */
237 if (idx == -1)
238 return false;
239
241 key->dboid = InvalidOid;
242 key->objid = idx;
243
244 return true;
245}

References get_replslot_index(), idx(), InvalidOid, 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 248 of file pgstat_replslot.c.

249{
250 ((PgStatShared_ReplSlot *) header)->stats.stat_reset_timestamp = ts;
251}

◆ 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 219 of file pgstat_replslot.c.

220{
221 /*
222 * This is only called late during shutdown. The set of existing slots
223 * isn't allowed to change at this point, we can assume that a slot exists
224 * at the offset.
225 */
226 if (!ReplicationSlotName(key->objid, name))
227 elog(ERROR, "could not find name for replication slot index %" PRIu64,
228 key->objid);
229}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
bool ReplicationSlotName(int index, Name name)
Definition slot.c:589

References elog, ERROR, fb(), name, and ReplicationSlotName().

◆ pgstat_report_replslot()

void pgstat_report_replslot ( ReplicationSlot slot,
const PgStat_StatReplSlotEntry repSlotStat 
)

Definition at line 77 of file pgstat_replslot.c.

78{
79 PgStat_EntryRef *entry_ref;
82
84 ReplicationSlotIndex(slot), false);
86 statent = &shstatent->stats;
87
88 /* Update the replication slot statistics */
89#define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld
90 REPLSLOT_ACC(spill_txns);
91 REPLSLOT_ACC(spill_count);
92 REPLSLOT_ACC(spill_bytes);
93 REPLSLOT_ACC(stream_txns);
94 REPLSLOT_ACC(stream_count);
95 REPLSLOT_ACC(stream_bytes);
96 REPLSLOT_ACC(mem_exceeded_count);
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 fb(), InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), ReplicationSlotIndex(), REPLSLOT_ACC, and PgStat_EntryRef::shared_stats.

Referenced by UpdateDecodingStats().

◆ pgstat_report_replslotsync()

void pgstat_report_replslotsync ( ReplicationSlot slot)

Definition at line 111 of file pgstat_replslot.c.

112{
113 PgStat_EntryRef *entry_ref;
116
117 /* Slot sync stats are valid only for synced logical slots on standby. */
118 Assert(slot->data.synced);
120
122 ReplicationSlotIndex(slot), false);
123 Assert(entry_ref != NULL);
124
126 statent = &shstatent->stats;
127
128 statent->slotsync_skip_count += 1;
129 statent->slotsync_last_skip = GetCurrentTimestamp();
130
131 pgstat_unlock_entry(entry_ref);
132}
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1645
ReplicationSlotPersistentData data
Definition slot.h:210
bool RecoveryInProgress(void)
Definition xlog.c:6460

References Assert, ReplicationSlot::data, fb(), GetCurrentTimestamp(), InvalidOid, pgstat_get_entry_ref_locked(), PGSTAT_KIND_REPLSLOT, pgstat_unlock_entry(), RecoveryInProgress(), ReplicationSlotIndex(), PgStat_EntryRef::shared_stats, and ReplicationSlotPersistentData::synced.

Referenced by update_slotsync_skip_stats().

◆ pgstat_reset_replslot()

void pgstat_reset_replslot ( const char name)

Definition at line 42 of file pgstat_replslot.c.

43{
44 ReplicationSlot *slot;
45
46 Assert(name != NULL);
47
49
50 /* Check if the slot exists with the given name. */
51 slot = SearchNamedReplicationSlot(name, false);
52 if (!slot)
55 errmsg("replication slot \"%s\" does not exist",
56 name)));
57
58 /*
59 * Reset stats if it is a logical slot. Nothing to do for physical slots
60 * as we collect stats only for logical slots.
61 */
62 if (SlotIsLogical(slot))
65
67}
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150
void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:864
#define SlotIsLogical(slot)
Definition slot.h:285

References Assert, ereport, errcode(), errmsg(), ERROR, fb(), InvalidOid, LW_SHARED, LWLockAcquire(), LWLockRelease(), name, PGSTAT_KIND_REPLSLOT, pgstat_reset(), ReplicationSlotIndex(), SearchNamedReplicationSlot(), and SlotIsLogical.

Referenced by pg_stat_reset_replication_slot().