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-2024, 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  */
42 typedef 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  */
63 typedef 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 /* communication variables for parsing synchronous_standby_names GUC */
79 
80 /* user-settable parameters for synchronous replication */
81 extern PGDLLIMPORT char *SyncRepStandbyNames;
82 
83 /* called by user backend */
84 extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit);
85 
86 /* called at backend exit */
87 extern void SyncRepCleanupAtProcExit(void);
88 
89 /* called by wal sender */
90 extern void SyncRepInitConfig(void);
91 extern void SyncRepReleaseWaiters(void);
92 
93 /* called by wal sender and user backend */
94 extern int SyncRepGetCandidateStandbys(SyncRepStandbyData **standbys);
95 
96 /* called by checkpointer */
97 extern void SyncRepUpdateSyncStandbysDefined(void);
98 
99 /*
100  * Internal functions for parsing synchronous_standby_names grammar,
101  * in syncrep_gram.y and syncrep_scanner.l
102  */
103 extern int syncrep_yyparse(void);
104 extern int syncrep_yylex(void);
105 extern void syncrep_yyerror(const char *str);
106 extern void syncrep_scanner_init(const char *str);
107 extern void syncrep_scanner_finish(void);
108 
109 #endif /* _SYNCREP_H */
#define PGDLLIMPORT
Definition: c.h:1295
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:413
unsigned char uint8
Definition: c.h:490
const char * str
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
struct SyncRepConfigData SyncRepConfigData
void syncrep_scanner_init(const char *str)
void syncrep_scanner_finish(void)
struct SyncRepStandbyData SyncRepStandbyData
int SyncRepGetCandidateStandbys(SyncRepStandbyData **standbys)
Definition: syncrep.c:711
void syncrep_yyerror(const char *str)
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_yyparse(void)
PGDLLIMPORT SyncRepConfigData * syncrep_parse_result
PGDLLIMPORT char * syncrep_parse_error_msg
void SyncRepCleanupAtProcExit(void)
Definition: syncrep.c:373
int syncrep_yylex(void)
uint64 XLogRecPtr
Definition: xlogdefs.h:21