summaryrefslogtreecommitdiff
path: root/src/backend/utils/activity/pgstat_subscription.c
blob: 689029b30aff0a4e71d797fb1491eed3551b8396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* -------------------------------------------------------------------------
 *
 * pgstat_subscription.c
 *	  Implementation of subscription statistics.
 *
 * This file contains the implementation of subscription statistics. It is kept
 * separate from pgstat.c to enforce the line between the statistics access /
 * storage implementation and the details about individual types of
 * statistics.
 *
 * Copyright (c) 2001-2022, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
 *	  src/backend/utils/activity/pgstat_subscription.c
 * -------------------------------------------------------------------------
 */

#include "postgres.h"

#include "utils/pgstat_internal.h"


/*
 * Report a subscription error.
 */
void
pgstat_report_subscription_error(Oid subid, bool is_apply_error)
{
	PgStat_MsgSubscriptionError msg;

	pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_SUBSCRIPTIONERROR);
	msg.m_subid = subid;
	msg.m_is_apply_error = is_apply_error;
	pgstat_send(&msg, sizeof(PgStat_MsgSubscriptionError));
}

/*
 * Report creating the subscription.
 *
 * Ensures that stats are dropped if transaction rolls back.
 */
void
pgstat_create_subscription(Oid subid)
{
	pgstat_create_transactional(PGSTAT_KIND_SUBSCRIPTION,
								InvalidOid, subid);
}

/*
 * Report dropping the subscription.
 *
 * Ensures that stats are dropped if transaction commits.
 */
void
pgstat_drop_subscription(Oid subid)
{
	PgStat_MsgSubscriptionDrop msg;

	pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_SUBSCRIPTIONDROP);
	msg.m_subid = subid;
	pgstat_send(&msg, sizeof(PgStat_MsgSubscriptionDrop));

	pgstat_drop_transactional(PGSTAT_KIND_SUBSCRIPTION,
							  InvalidOid, subid);
}