1 /*------------------------------------------------------------------------- 2 * 3 * syncrep.h 4 * Exports from replication/syncrep.c. 5 * 6 * Portions Copyright (c) 2010-2016, 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 /* 36 * Struct for the configuration of synchronous replication. 37 * 38 * Note: this must be a flat representation that can be held in a single 39 * chunk of malloc'd memory, so that it can be stored as the "extra" data 40 * for the synchronous_standby_names GUC. 41 */ 42 typedef struct SyncRepConfigData 43 { 44 int config_size; /* total size of this struct, in bytes */ 45 int num_sync; /* number of sync standbys that we need to 46 * wait for */ 47 int nmembers; /* number of members in the following list */ 48 /* member_names contains nmembers consecutive nul-terminated C strings */ 49 char member_names[FLEXIBLE_ARRAY_MEMBER]; 50 } SyncRepConfigData; 51 52 /* communication variables for parsing synchronous_standby_names GUC */ 53 extern SyncRepConfigData *syncrep_parse_result; 54 extern char *syncrep_parse_error_msg; 55 56 /* user-settable parameters for synchronous replication */ 57 extern char *SyncRepStandbyNames; 58 59 /* called by user backend */ 60 extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit); 61 62 /* called at backend exit */ 63 extern void SyncRepCleanupAtProcExit(void); 64 65 /* called by wal sender */ 66 extern void SyncRepInitConfig(void); 67 extern void SyncRepReleaseWaiters(void); 68 69 /* called by wal sender and user backend */ 70 extern List *SyncRepGetSyncStandbys(bool *am_sync); 71 72 /* called by checkpointer */ 73 extern void SyncRepUpdateSyncStandbysDefined(void); 74 75 /* GUC infrastructure */ 76 extern bool check_synchronous_standby_names(char **newval, void **extra, GucSource source); 77 extern void assign_synchronous_standby_names(const char *newval, void *extra); 78 extern void assign_synchronous_commit(int newval, void *extra); 79 80 /* 81 * Internal functions for parsing synchronous_standby_names grammar, 82 * in syncrep_gram.y and syncrep_scanner.l 83 */ 84 extern int syncrep_yyparse(void); 85 extern int syncrep_yylex(void); 86 extern void syncrep_yyerror(const char *str); 87 extern void syncrep_scanner_init(const char *query_string); 88 extern void syncrep_scanner_finish(void); 89 90 #endif /* _SYNCREP_H */ 91