PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgstat_subscription.c
Go to the documentation of this file.
1/* -------------------------------------------------------------------------
2 *
3 * pgstat_subscription.c
4 * Implementation of subscription statistics.
5 *
6 * This file contains the implementation of subscription statistics. It is kept
7 * separate from pgstat.c to enforce the line between the statistics access /
8 * storage implementation and the details about individual types of
9 * statistics.
10 *
11 * Copyright (c) 2001-2026, PostgreSQL Global Development Group
12 *
13 * IDENTIFICATION
14 * src/backend/utils/activity/pgstat_subscription.c
15 * -------------------------------------------------------------------------
16 */
17
18#include "postgres.h"
19
22
23
24/*
25 * Report a subscription error.
26 */
27void
29{
30 PgStat_EntryRef *entry_ref;
33
35 InvalidOid, subid, NULL);
36 pending = entry_ref->pending;
37
38 switch (wtype)
39 {
41 pending->apply_error_count++;
42 break;
43
45 pending->sync_seq_error_count++;
46 break;
47
49 pending->sync_table_error_count++;
50 break;
51
52 default:
53 /* Should never happen. */
54 Assert(0);
55 break;
56 }
57}
58
59/*
60 * Report a subscription conflict.
61 */
62void
64{
65 PgStat_EntryRef *entry_ref;
67
69 InvalidOid, subid, NULL);
70 pending = entry_ref->pending;
71 pending->conflict_count[type]++;
72}
73
74/*
75 * Report creating the subscription.
76 */
77void
79{
80 /* Ensures that stats are dropped if transaction rolls back */
82 InvalidOid, subid);
83
84 /* Create and initialize the subscription stats entry */
86 true, NULL);
88}
89
90/*
91 * Report dropping the subscription.
92 *
93 * Ensures that stats are dropped if transaction commits.
94 */
95void
101
102/*
103 * Support function for the SQL-callable pgstat* functions. Returns
104 * the collected statistics for one subscription or NULL.
105 */
112
113/*
114 * Flush out pending stats for the entry
115 *
116 * If nowait is true and the lock could not be immediately acquired, returns
117 * false without flushing the entry. Otherwise returns true.
118 */
119bool
121{
124
125 localent = (PgStat_BackendSubEntry *) entry_ref->pending;
127
128 /* localent always has non-zero content */
129
130 if (!pgstat_lock_entry(entry_ref, nowait))
131 return false;
132
133#define SUB_ACC(fld) shsubent->stats.fld += localent->fld
134 SUB_ACC(apply_error_count);
135 SUB_ACC(sync_seq_error_count);
136 SUB_ACC(sync_table_error_count);
137 for (int i = 0; i < CONFLICT_NUM_TYPES; i++)
138 SUB_ACC(conflict_count[i]);
139#undef SUB_ACC
140
141 pgstat_unlock_entry(entry_ref);
142 return true;
143}
144
145void
147{
148 ((PgStatShared_Subscription *) header)->stats.stat_reset_timestamp = ts;
149}
#define Assert(condition)
Definition c.h:885
ConflictType
Definition conflict.h:32
#define CONFLICT_NUM_TYPES
Definition conflict.h:64
int64 TimestampTz
Definition timestamp.h:39
int i
Definition isn.c:77
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
Definition pgstat.c:1275
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition pgstat.c:944
#define PGSTAT_KIND_SUBSCRIPTION
Definition pgstat_kind.h:31
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry)
void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, uint64 objid, TimestampTz ts)
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
void pgstat_drop_subscription(Oid subid)
void pgstat_create_subscription(Oid subid)
void pgstat_report_subscription_error(Oid subid)
void pgstat_report_subscription_conflict(Oid subid, ConflictType type)
#define SUB_ACC(fld)
bool pgstat_subscription_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
PgStat_StatSubEntry * pgstat_fetch_stat_subscription(Oid subid)
void pgstat_subscription_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)
void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)
#define InvalidOid
unsigned int Oid
static int fb(int x)
PgStat_Counter sync_table_error_count
Definition pgstat.h:117
PgStat_Counter apply_error_count
Definition pgstat.h:115
PgStat_Counter sync_seq_error_count
Definition pgstat.h:116
PgStat_Counter conflict_count[CONFLICT_NUM_TYPES]
Definition pgstat.h:118
PgStatShared_Common * shared_stats
const char * type
LogicalRepWorkerType
@ WORKERTYPE_TABLESYNC
@ WORKERTYPE_SEQUENCESYNC
@ WORKERTYPE_APPLY
static LogicalRepWorkerType get_logical_worker_type(void)