walsender_private.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*-------------------------------------------------------------------------
  2. *
  3. * walsender_private.h
  4. * Private definitions from replication/walsender.c.
  5. *
  6. * Portions Copyright (c) 2010-2016, PostgreSQL Global Development Group
  7. *
  8. * src/include/replication/walsender_private.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef _WALSENDER_PRIVATE_H
  13. #define _WALSENDER_PRIVATE_H
  14. #include "access/xlog.h"
  15. #include "nodes/nodes.h"
  16. #include "replication/syncrep.h"
  17. #include "storage/latch.h"
  18. #include "storage/shmem.h"
  19. #include "storage/spin.h"
  20. typedef enum WalSndState
  21. {
  22. WALSNDSTATE_STARTUP = 0,
  23. WALSNDSTATE_BACKUP,
  24. WALSNDSTATE_CATCHUP,
  25. WALSNDSTATE_STREAMING,
  26. WALSNDSTATE_STOPPING
  27. } WalSndState;
  28. /*
  29. * Each walsender has a WalSnd struct in shared memory.
  30. */
  31. typedef struct WalSnd
  32. {
  33. pid_t pid; /* this walsender's process id, or 0 */
  34. WalSndState state; /* this walsender's state */
  35. XLogRecPtr sentPtr; /* WAL has been sent up to this point */
  36. bool needreload; /* does currently-open file need to be
  37. * reloaded? */
  38. /*
  39. * The xlog locations that have been written, flushed, and applied by
  40. * standby-side. These may be invalid if the standby-side has not offered
  41. * values yet.
  42. */
  43. XLogRecPtr write;
  44. XLogRecPtr flush;
  45. XLogRecPtr apply;
  46. /* Protects shared variables shown above. */
  47. slock_t mutex;
  48. /*
  49. * Pointer to the walsender's latch. Used by backends to wake up this
  50. * walsender when it has work to do. NULL if the walsender isn't active.
  51. */
  52. Latch *latch;
  53. /*
  54. * The priority order of the standby managed by this WALSender, as listed
  55. * in synchronous_standby_names, or 0 if not-listed. Protected by
  56. * SyncRepLock.
  57. */
  58. int sync_standby_priority;
  59. } WalSnd;
  60. extern WalSnd *MyWalSnd;
  61. /* There is one WalSndCtl struct for the whole database cluster */
  62. typedef struct
  63. {
  64. /*
  65. * Synchronous replication queue with one queue per request type.
  66. * Protected by SyncRepLock.
  67. */
  68. SHM_QUEUE SyncRepQueue[NUM_SYNC_REP_WAIT_MODE];
  69. /*
  70. * Current location of the head of the queue. All waiters should have a
  71. * waitLSN that follows this value. Protected by SyncRepLock.
  72. */
  73. XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE];
  74. /*
  75. * Are any sync standbys defined? Waiting backends can't reload the
  76. * config file safely, so checkpointer updates this value as needed.
  77. * Protected by SyncRepLock.
  78. */
  79. bool sync_standbys_defined;
  80. WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER];
  81. } WalSndCtlData;
  82. extern WalSndCtlData *WalSndCtl;
  83. extern void WalSndSetState(WalSndState state);
  84. /*
  85. * Internal functions for parsing the replication grammar, in repl_gram.y and
  86. * repl_scanner.l
  87. */
  88. extern int replication_yyparse(void);
  89. extern int replication_yylex(void);
  90. extern void replication_yyerror(const char *str) pg_attribute_noreturn();
  91. extern void replication_scanner_init(const char *query_string);
  92. extern void replication_scanner_finish(void);
  93. extern Node *replication_parse_result;
  94. #endif /* _WALSENDER_PRIVATE_H */