PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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 #include "utils/guc.h"
18 
19 #define SyncRepRequested() \
20  (max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH)
21 
22 /* SyncRepWaitMode */
23 #define SYNC_REP_NO_WAIT (-1)
24 #define SYNC_REP_WAIT_WRITE 0
25 #define SYNC_REP_WAIT_FLUSH 1
26 #define SYNC_REP_WAIT_APPLY 2
27 
28 #define NUM_SYNC_REP_WAIT_MODE 3
29 
30 /* syncRepState */
31 #define SYNC_REP_NOT_WAITING 0
32 #define SYNC_REP_WAITING 1
33 #define SYNC_REP_WAIT_COMPLETE 2
34 
35 /* syncrep_method of SyncRepConfigData */
36 #define SYNC_REP_PRIORITY 0
37 #define SYNC_REP_QUORUM 1
38 
39 /*
40  * Struct for the configuration of synchronous replication.
41  *
42  * Note: this must be a flat representation that can be held in a single
43  * chunk of malloc'd memory, so that it can be stored as the "extra" data
44  * for the synchronous_standby_names GUC.
45  */
46 typedef struct SyncRepConfigData
47 {
48  int config_size; /* total size of this struct, in bytes */
49  int num_sync; /* number of sync standbys that we need to
50  * wait for */
51  uint8 syncrep_method; /* method to choose sync standbys */
52  int nmembers; /* number of members in the following list */
53  /* member_names contains nmembers consecutive nul-terminated C strings */
54  char member_names[FLEXIBLE_ARRAY_MEMBER];
56 
58 
59 /* communication variables for parsing synchronous_standby_names GUC */
61 extern char *syncrep_parse_error_msg;
62 
63 /* user-settable parameters for synchronous replication */
64 extern char *SyncRepStandbyNames;
65 
66 /* called by user backend */
67 extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit);
68 
69 /* called at backend exit */
70 extern void SyncRepCleanupAtProcExit(void);
71 
72 /* called by wal sender */
73 extern void SyncRepInitConfig(void);
74 extern void SyncRepReleaseWaiters(void);
75 
76 /* called by wal sender and user backend */
77 extern List *SyncRepGetSyncStandbys(bool *am_sync);
78 
79 /* called by checkpointer */
80 extern void SyncRepUpdateSyncStandbysDefined(void);
81 
82 /* GUC infrastructure */
83 extern bool check_synchronous_standby_names(char **newval, void **extra, GucSource source);
84 extern void assign_synchronous_standby_names(const char *newval, void *extra);
85 extern void assign_synchronous_commit(int newval, void *extra);
86 
87 /*
88  * Internal functions for parsing synchronous_standby_names grammar,
89  * in syncrep_gram.y and syncrep_scanner.l
90  */
91 extern int syncrep_yyparse(void);
92 extern int syncrep_yylex(void);
93 extern void syncrep_yyerror(const char *str);
94 extern void syncrep_scanner_init(const char *query_string);
95 extern void syncrep_scanner_finish(void);
96 
97 #endif /* _SYNCREP_H */
void syncrep_scanner_finish(void)
void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
Definition: syncrep.c:146
void syncrep_scanner_init(const char *query_string)
int syncrep_yylex(void)
char * syncrep_parse_error_msg
void assign_synchronous_standby_names(const char *newval, void *extra)
Definition: syncrep.c:1160
uint8 syncrep_method
Definition: syncrep.h:51
unsigned char uint8
Definition: c.h:266
void SyncRepReleaseWaiters(void)
Definition: syncrep.c:409
char * SyncRepStandbyNames
Definition: syncrep.c:90
GucSource
Definition: guc.h:105
List * SyncRepGetSyncStandbys(bool *am_sync)
Definition: syncrep.c:677
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:97
void syncrep_yyerror(const char *str)
void SyncRepInitConfig(void)
Definition: syncrep.c:381
struct SyncRepConfigData SyncRepConfigData
uint64 XLogRecPtr
Definition: xlogdefs.h:21
char member_names[FLEXIBLE_ARRAY_MEMBER]
Definition: syncrep.h:54
void SyncRepCleanupAtProcExit(void)
Definition: syncrep.c:360
SyncRepConfigData * syncrep_parse_result
#define newval
void assign_synchronous_commit(int newval, void *extra)
Definition: syncrep.c:1166
bool check_synchronous_standby_names(char **newval, void **extra, GucSource source)
Definition: syncrep.c:1103
void SyncRepUpdateSyncStandbysDefined(void)
Definition: syncrep.c:1027
int syncrep_yyparse(void)
Definition: pg_list.h:45