syncrep.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #include "access/xlogdefs.h"
  16. #include "utils/guc.h"
  17. #define SyncRepRequested() \
  18. (max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH)
  19. /* SyncRepWaitMode */
  20. #define SYNC_REP_NO_WAIT (-1)
  21. #define SYNC_REP_WAIT_WRITE 0
  22. #define SYNC_REP_WAIT_FLUSH 1
  23. #define SYNC_REP_WAIT_APPLY 2
  24. #define NUM_SYNC_REP_WAIT_MODE 3
  25. /* syncRepState */
  26. #define SYNC_REP_NOT_WAITING 0
  27. #define SYNC_REP_WAITING 1
  28. #define SYNC_REP_WAIT_COMPLETE 2
  29. /*
  30. * Struct for the configuration of synchronous replication.
  31. *
  32. * Note: this must be a flat representation that can be held in a single
  33. * chunk of malloc'd memory, so that it can be stored as the "extra" data
  34. * for the synchronous_standby_names GUC.
  35. */
  36. typedef struct SyncRepConfigData
  37. {
  38. int config_size; /* total size of this struct, in bytes */
  39. int num_sync; /* number of sync standbys that we need to
  40. * wait for */
  41. int nmembers; /* number of members in the following list */
  42. /* member_names contains nmembers consecutive nul-terminated C strings */
  43. char member_names[FLEXIBLE_ARRAY_MEMBER];
  44. } SyncRepConfigData;
  45. /* communication variables for parsing synchronous_standby_names GUC */
  46. extern SyncRepConfigData *syncrep_parse_result;
  47. extern char *syncrep_parse_error_msg;
  48. /* user-settable parameters for synchronous replication */
  49. extern char *SyncRepStandbyNames;
  50. /* called by user backend */
  51. extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit);
  52. /* called at backend exit */
  53. extern void SyncRepCleanupAtProcExit(void);
  54. /* called by wal sender */
  55. extern void SyncRepInitConfig(void);
  56. extern void SyncRepReleaseWaiters(void);
  57. /* called by wal sender and user backend */
  58. extern List *SyncRepGetSyncStandbys(bool *am_sync);
  59. /* called by checkpointer */
  60. extern void SyncRepUpdateSyncStandbysDefined(void);
  61. /* GUC infrastructure */
  62. extern bool check_synchronous_standby_names(char **newval, void **extra, GucSource source);
  63. extern void assign_synchronous_standby_names(const char *newval, void *extra);
  64. extern void assign_synchronous_commit(int newval, void *extra);
  65. /*
  66. * Internal functions for parsing synchronous_standby_names grammar,
  67. * in syncrep_gram.y and syncrep_scanner.l
  68. */
  69. extern int syncrep_yyparse(void);
  70. extern int syncrep_yylex(void);
  71. extern void syncrep_yyerror(const char *str);
  72. extern void syncrep_scanner_init(const char *query_string);
  73. extern void syncrep_scanner_finish(void);
  74. #endif /* _SYNCREP_H */