gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.6KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * syncrep.h
  4. * Exports from replication/syncrep.c.
  5. *
  6. * Portions Copyright (c) 2010-2019, 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 SyncRepConfigData *SyncRepConfig;
  67. /* communication variables for parsing synchronous_standby_names GUC */
  68. extern SyncRepConfigData *syncrep_parse_result;
  69. extern char *syncrep_parse_error_msg;
  70. /* user-settable parameters for synchronous replication */
  71. extern 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. /* obsolete, do not use in new code */
  82. extern List *SyncRepGetSyncStandbys(bool *am_sync);
  83. /* called by checkpointer */
  84. extern void SyncRepUpdateSyncStandbysDefined(void);
  85. /* GUC infrastructure */
  86. extern bool check_synchronous_standby_names(char **newval, void **extra, GucSource source);
  87. extern void assign_synchronous_standby_names(const char *newval, void *extra);
  88. extern void assign_synchronous_commit(int newval, void *extra);
  89. /*
  90. * Internal functions for parsing synchronous_standby_names grammar,
  91. * in syncrep_gram.y and syncrep_scanner.l
  92. */
  93. extern int syncrep_yyparse(void);
  94. extern int syncrep_yylex(void);
  95. extern void syncrep_yyerror(const char *str);
  96. extern void syncrep_scanner_init(const char *query_string);
  97. extern void syncrep_scanner_finish(void);
  98. #endif /* _SYNCREP_H */
上海开阖软件有限公司 沪ICP备12045867号-1