walsender_private.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*-------------------------------------------------------------------------
  2. *
  3. * walsender_private.h
  4. * Private definitions from replication/walsender.c.
  5. *
  6. * Portions Copyright (c) 2010-2022, 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. * This struct is protected by its 'mutex' spinlock field, except that some
  32. * members are only written by the walsender process itself, and thus that
  33. * process is free to read those members without holding spinlock. pid and
  34. * needreload always require the spinlock to be held for all accesses.
  35. */
  36. typedef struct WalSnd
  37. {
  38. pid_t pid; /* this walsender's PID, or 0 if not active */
  39. WalSndState state; /* this walsender's state */
  40. XLogRecPtr sentPtr; /* WAL has been sent up to this point */
  41. bool needreload; /* does currently-open file need to be
  42. * reloaded? */
  43. /*
  44. * The xlog locations that have been written, flushed, and applied by
  45. * standby-side. These may be invalid if the standby-side has not offered
  46. * values yet.
  47. */
  48. XLogRecPtr write;
  49. XLogRecPtr flush;
  50. XLogRecPtr apply;
  51. /* Measured lag times, or -1 for unknown/none. */
  52. TimeOffset writeLag;
  53. TimeOffset flushLag;
  54. TimeOffset applyLag;
  55. /*
  56. * The priority order of the standby managed by this WALSender, as listed
  57. * in synchronous_standby_names, or 0 if not-listed.
  58. */
  59. int sync_standby_priority;
  60. /* Protects shared variables shown above. */
  61. slock_t mutex;
  62. /*
  63. * Pointer to the walsender's latch. Used by backends to wake up this
  64. * walsender when it has work to do. NULL if the walsender isn't active.
  65. */
  66. Latch *latch;
  67. /*
  68. * Timestamp of the last message received from standby.
  69. */
  70. TimestampTz replyTime;
  71. } WalSnd;
  72. extern PGDLLIMPORT WalSnd *MyWalSnd;
  73. /* There is one WalSndCtl struct for the whole database cluster */
  74. typedef struct
  75. {
  76. /*
  77. * Synchronous replication queue with one queue per request type.
  78. * Protected by SyncRepLock.
  79. */
  80. SHM_QUEUE SyncRepQueue[NUM_SYNC_REP_WAIT_MODE];
  81. /*
  82. * Current location of the head of the queue. All waiters should have a
  83. * waitLSN that follows this value. Protected by SyncRepLock.
  84. */
  85. XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE];
  86. /*
  87. * Are any sync standbys defined? Waiting backends can't reload the
  88. * config file safely, so checkpointer updates this value as needed.
  89. * Protected by SyncRepLock.
  90. */
  91. bool sync_standbys_defined;
  92. WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER];
  93. } WalSndCtlData;
  94. extern PGDLLIMPORT WalSndCtlData *WalSndCtl;
  95. extern void WalSndSetState(WalSndState state);
  96. /*
  97. * Internal functions for parsing the replication grammar, in repl_gram.y and
  98. * repl_scanner.l
  99. */
  100. extern int replication_yyparse(void);
  101. extern int replication_yylex(void);
  102. extern void replication_yyerror(const char *str) pg_attribute_noreturn();
  103. extern void replication_scanner_init(const char *query_string);
  104. extern void replication_scanner_finish(void);
  105. extern bool replication_scanner_is_replication_command(void);
  106. extern PGDLLIMPORT Node *replication_parse_result;
  107. #endif /* _WALSENDER_PRIVATE_H */