PostgreSQL Source Code git master
syncrep.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * syncrep.h
4 * Exports from replication/syncrep.c.
5 *
6 * Portions Copyright (c) 2010-2025, PostgreSQL Global Development Group
7 *
8 * IDENTIFICATION
9 * src/include/replication/syncrep.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef _SYNCREP_H
14#define _SYNCREP_H
15
16#include "access/xlogdefs.h"
17
18#define SyncRepRequested() \
19 (max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH)
20
21/* SyncRepWaitMode */
22#define SYNC_REP_NO_WAIT (-1)
23#define SYNC_REP_WAIT_WRITE 0
24#define SYNC_REP_WAIT_FLUSH 1
25#define SYNC_REP_WAIT_APPLY 2
26
27#define NUM_SYNC_REP_WAIT_MODE 3
28
29/* syncRepState */
30#define SYNC_REP_NOT_WAITING 0
31#define SYNC_REP_WAITING 1
32#define SYNC_REP_WAIT_COMPLETE 2
33
34/* syncrep_method of SyncRepConfigData */
35#define SYNC_REP_PRIORITY 0
36#define SYNC_REP_QUORUM 1
37
38/*
39 * SyncRepGetCandidateStandbys returns an array of these structs,
40 * one per candidate synchronous walsender.
41 */
42typedef struct SyncRepStandbyData
43{
44 /* Copies of relevant fields from WalSnd shared-memory struct */
45 pid_t pid;
50 /* Index of this walsender in the WalSnd shared-memory array */
52 /* This flag indicates whether this struct is about our own process */
53 bool is_me;
55
56/*
57 * Struct for the configuration of synchronous replication.
58 *
59 * Note: this must be a flat representation that can be held in a single
60 * chunk of malloc'd memory, so that it can be stored as the "extra" data
61 * for the synchronous_standby_names GUC.
62 */
63typedef struct SyncRepConfigData
64{
65 int config_size; /* total size of this struct, in bytes */
66 int num_sync; /* number of sync standbys that we need to
67 * wait for */
68 uint8 syncrep_method; /* method to choose sync standbys */
69 int nmembers; /* number of members in the following list */
70 /* member_names contains nmembers consecutive nul-terminated C strings */
73
75
76/* user-settable parameters for synchronous replication */
78
79/* called by user backend */
80extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit);
81
82/* called at backend exit */
83extern void SyncRepCleanupAtProcExit(void);
84
85/* called by wal sender */
86extern void SyncRepInitConfig(void);
87extern void SyncRepReleaseWaiters(void);
88
89/* called by wal sender and user backend */
91
92/* called by checkpointer */
93extern void SyncRepUpdateSyncStandbysDefined(void);
94
95/*
96 * Internal functions for parsing synchronous_standby_names grammar,
97 * in syncrep_gram.y and syncrep_scanner.l
98 */
99union YYSTYPE;
100#ifndef YY_TYPEDEF_YY_SCANNER_T
101#define YY_TYPEDEF_YY_SCANNER_T
102typedef void *yyscan_t;
103#endif
104extern int syncrep_yyparse(SyncRepConfigData **syncrep_parse_result_p, char **syncrep_parse_error_msg_p, yyscan_t yyscanner);
105extern int syncrep_yylex(union YYSTYPE *yylval_param, char **syncrep_parse_error_msg_p, yyscan_t yyscanner);
106extern void syncrep_yyerror(SyncRepConfigData **syncrep_parse_result_p, char **syncrep_parse_error_msg_p, yyscan_t yyscanner, const char *str);
107extern void syncrep_scanner_init(const char *str, yyscan_t *yyscannerp);
108extern void syncrep_scanner_finish(yyscan_t yyscanner);
109
110#endif /* _SYNCREP_H */
#define PGDLLIMPORT
Definition: c.h:1291
uint8_t uint8
Definition: c.h:500
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:434
void * yyscan_t
Definition: cubedata.h:67
const char * str
int YYSTYPE
Definition: psqlscanslash.l:39
uint8 syncrep_method
Definition: syncrep.h:68
char member_names[FLEXIBLE_ARRAY_MEMBER]
Definition: syncrep.h:71
int sync_standby_priority
Definition: syncrep.h:49
XLogRecPtr apply
Definition: syncrep.h:48
XLogRecPtr write
Definition: syncrep.h:46
XLogRecPtr flush
Definition: syncrep.h:47
void SyncRepInitConfig(void)
Definition: syncrep.c:402
void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
Definition: syncrep.c:148
void * yyscan_t
Definition: syncrep.h:102
struct SyncRepConfigData SyncRepConfigData
void syncrep_scanner_finish(yyscan_t yyscanner)
struct SyncRepStandbyData SyncRepStandbyData
int SyncRepGetCandidateStandbys(SyncRepStandbyData **standbys)
Definition: syncrep.c:711
void syncrep_scanner_init(const char *str, yyscan_t *yyscannerp)
void SyncRepReleaseWaiters(void)
Definition: syncrep.c:431
PGDLLIMPORT SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:97
PGDLLIMPORT char * SyncRepStandbyNames
Definition: syncrep.c:90
void SyncRepUpdateSyncStandbysDefined(void)
Definition: syncrep.c:921
int syncrep_yylex(union YYSTYPE *yylval_param, char **syncrep_parse_error_msg_p, yyscan_t yyscanner)
int syncrep_yyparse(SyncRepConfigData **syncrep_parse_result_p, char **syncrep_parse_error_msg_p, yyscan_t yyscanner)
void SyncRepCleanupAtProcExit(void)
Definition: syncrep.c:373
void syncrep_yyerror(SyncRepConfigData **syncrep_parse_result_p, char **syncrep_parse_error_msg_p, yyscan_t yyscanner, const char *str)
uint64 XLogRecPtr
Definition: xlogdefs.h:21