aboutsummaryrefslogtreecommitdiff
path: root/src/include/catalog/pg_subscription_rel.h
blob: d936973a9da091f768037fa1f4e543daf500356f (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* -------------------------------------------------------------------------
 *
 * pg_subscription_rel.h
 *		Local info about tables that come from the publisher of a
 *		subscription (pg_subscription_rel).
 *
 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * -------------------------------------------------------------------------
 */
#ifndef PG_SUBSCRIPTION_REL_H
#define PG_SUBSCRIPTION_REL_H

#include "access/xlogdefs.h"
#include "catalog/genbki.h"
#include "nodes/pg_list.h"

/* ----------------
 *		pg_subscription_rel definition. cpp turns this into
 *		typedef struct FormData_pg_subscription_rel
 * ----------------
 */
#define SubscriptionRelRelationId			6102

CATALOG(pg_subscription_rel,6102) BKI_WITHOUT_OIDS
{
	Oid			srsubid;		/* Oid of subscription */
	Oid			srrelid;		/* Oid of relation */
	char		srsubstate;		/* state of the relation in subscription */
	XLogRecPtr	srsublsn;		/* remote lsn of the state change used for
								 * synchronization coordination */
} FormData_pg_subscription_rel;

typedef FormData_pg_subscription_rel *Form_pg_subscription_rel;

/* ----------------
 *		compiler constants for pg_subscription_rel
 * ----------------
 */
#define Natts_pg_subscription_rel				4
#define Anum_pg_subscription_rel_srsubid		1
#define Anum_pg_subscription_rel_srrelid		2
#define Anum_pg_subscription_rel_srsubstate		3
#define Anum_pg_subscription_rel_srsublsn		4

/* ----------------
 *		substate constants
 * ----------------
 */
#define SUBREL_STATE_INIT		'i' /* initializing (sublsn NULL) */
#define SUBREL_STATE_DATASYNC	'd' /* data is being synchronized (sublsn
									 * NULL) */
#define SUBREL_STATE_SYNCDONE	's' /* synchronization finished in front of
									 * apply (sublsn set) */
#define SUBREL_STATE_READY		'r' /* ready (sublsn set) */

/* These are never stored in the catalog, we only use them for IPC. */
#define SUBREL_STATE_UNKNOWN	'\0'	/* unknown state */
#define SUBREL_STATE_SYNCWAIT	'w' /* waiting for sync */
#define SUBREL_STATE_CATCHUP	'c' /* catching up with apply */

typedef struct SubscriptionRelState
{
	Oid			relid;
	XLogRecPtr	lsn;
	char		state;
} SubscriptionRelState;

extern Oid SetSubscriptionRelState(Oid subid, Oid relid, char state,
						XLogRecPtr sublsn, bool update_only);
extern char GetSubscriptionRelState(Oid subid, Oid relid,
						XLogRecPtr *sublsn, bool missing_ok);
extern void RemoveSubscriptionRel(Oid subid, Oid relid);

extern List *GetSubscriptionRelations(Oid subid);
extern List *GetSubscriptionNotReadyRelations(Oid subid);

#endif							/* PG_SUBSCRIPTION_REL_H */