2
0

syncrep.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*-------------------------------------------------------------------------
  2. *
  3. * syncrep.h
  4. * Exports from replication/syncrep.c.
  5. *
  6. * Portions Copyright (c) 2010-2022, 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. /* syncrep_method of SyncRepConfigData */
  30. #define SYNC_REP_PRIORITY 0
  31. #define SYNC_REP_QUORUM 1
  32. /*
  33. * SyncRepGetCandidateStandbys returns an array of these structs,
  34. * one per candidate synchronous walsender.
  35. */
  36. typedef struct SyncRepStandbyData
  37. {
  38. /* Copies of relevant fields from WalSnd shared-memory struct */
  39. pid_t pid;
  40. XLogRecPtr write;
  41. XLogRecPtr flush;
  42. XLogRecPtr apply;
  43. int sync_standby_priority;
  44. /* Index of this walsender in the WalSnd shared-memory array */
  45. int walsnd_index;
  46. /* This flag indicates whether this struct is about our own process */
  47. bool is_me;
  48. } SyncRepStandbyData;
  49. /*
  50. * Struct for the configuration of synchronous replication.
  51. *
  52. * Note: this must be a flat representation that can be held in a single
  53. * chunk of malloc'd memory, so that it can be stored as the "extra" data
  54. * for the synchronous_standby_names GUC.
  55. */
  56. typedef struct SyncRepConfigData
  57. {
  58. int config_size; /* total size of this struct, in bytes */
  59. int num_sync; /* number of sync standbys that we need to
  60. * wait for */
  61. uint8 syncrep_method; /* method to choose sync standbys */
  62. int nmembers; /* number of members in the following list */
  63. /* member_names contains nmembers consecutive nul-terminated C strings */
  64. char member_names[FLEXIBLE_ARRAY_MEMBER];
  65. } SyncRepConfigData;
  66. extern PGDLLIMPORT SyncRepConfigData *SyncRepConfig;
  67. /* communication variables for parsing synchronous_standby_names GUC */
  68. extern PGDLLIMPORT SyncRepConfigData *syncrep_parse_result;
  69. extern PGDLLIMPORT char *syncrep_parse_error_msg;
  70. /* user-settable parameters for synchronous replication */
  71. extern PGDLLIMPORT char *SyncRepStandbyNames;
  72. /* called by user backend */
  73. extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit);
  74. /* called at backend exit */
  75. extern void SyncRepCleanupAtProcExit(void);
  76. /* called by wal sender */
  77. extern void SyncRepInitConfig(void);
  78. extern void SyncRepReleaseWaiters(void);
  79. /* called by wal sender and user backend */
  80. extern int SyncRepGetCandidateStandbys(SyncRepStandbyData **standbys);
  81. /* called by checkpointer */
  82. extern void SyncRepUpdateSyncStandbysDefined(void);
  83. /* GUC infrastructure */
  84. extern bool check_synchronous_standby_names(char **newval, void **extra, GucSource source);
  85. extern void assign_synchronous_standby_names(const char *newval, void *extra);
  86. extern void assign_synchronous_commit(int newval, void *extra);
  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. #endif /* _SYNCREP_H */