codekingpro/portable-devtools
114k
1/*-------------------------------------------------------------------------2 *3 * walsender_private.h4 * Private definitions from replication/walsender.c.5 *6 * Portions Copyright (c) 2010-2023, PostgreSQL Global Development Group7 *8 * src/include/replication/walsender_private.h9 *10 *-------------------------------------------------------------------------11 */12#ifndef _WALSENDER_PRIVATE_H13#define _WALSENDER_PRIVATE_H14 15#include "access/xlog.h"16#include "lib/ilist.h"17#include "nodes/nodes.h"18#include "nodes/replnodes.h"19#include "replication/syncrep.h"20#include "storage/condition_variable.h"21#include "storage/latch.h"22#include "storage/shmem.h"23#include "storage/spin.h"24 25typedef enum WalSndState26{27 WALSNDSTATE_STARTUP = 0,28 WALSNDSTATE_BACKUP,29 WALSNDSTATE_CATCHUP,30 WALSNDSTATE_STREAMING,31 WALSNDSTATE_STOPPING32} WalSndState;33 34/*35 * Each walsender has a WalSnd struct in shared memory.36 *37 * This struct is protected by its 'mutex' spinlock field, except that some38 * members are only written by the walsender process itself, and thus that39 * process is free to read those members without holding spinlock. pid and40 * needreload always require the spinlock to be held for all accesses.41 */42typedef struct WalSnd43{44 pid_t pid; /* this walsender's PID, or 0 if not active */45 46 WalSndState state; /* this walsender's state */47 XLogRecPtr sentPtr; /* WAL has been sent up to this point */48 bool needreload; /* does currently-open file need to be49 * reloaded? */50 51 /*52 * The xlog locations that have been written, flushed, and applied by53 * standby-side. These may be invalid if the standby-side has not offered54 * values yet.55 */56 XLogRecPtr write;57 XLogRecPtr flush;58 XLogRecPtr apply;59 60 /* Measured lag times, or -1 for unknown/none. */61 TimeOffset writeLag;62 TimeOffset flushLag;63 TimeOffset applyLag;64 65 /*66 * The priority order of the standby managed by this WALSender, as listed67 * in synchronous_standby_names, or 0 if not-listed.68 */69 int sync_standby_priority;70 71 /* Protects shared variables in this structure. */72 slock_t mutex;73 74 /*75 * Pointer to the walsender's latch. Used by backends to wake up this76 * walsender when it has work to do. NULL if the walsender isn't active.77 */78 Latch *latch;79 80 /*81 * Timestamp of the last message received from standby.82 */83 TimestampTz replyTime;84 85 ReplicationKind kind;86} WalSnd;87 88extern PGDLLIMPORT WalSnd *MyWalSnd;89 90/* There is one WalSndCtl struct for the whole database cluster */91typedef struct92{93 /*94 * Synchronous replication queue with one queue per request type.95 * Protected by SyncRepLock.96 */97 dlist_head SyncRepQueue[NUM_SYNC_REP_WAIT_MODE];98 99 /*100 * Current location of the head of the queue. All waiters should have a101 * waitLSN that follows this value. Protected by SyncRepLock.102 */103 XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE];104 105 /*106 * Are any sync standbys defined? Waiting backends can't reload the107 * config file safely, so checkpointer updates this value as needed.108 * Protected by SyncRepLock.109 */110 bool sync_standbys_defined;111 112 /* used as a registry of physical / logical walsenders to wake */113 ConditionVariable wal_flush_cv;114 ConditionVariable wal_replay_cv;115 116 WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER];117} WalSndCtlData;118 119extern PGDLLIMPORT WalSndCtlData *WalSndCtl;120 121 122extern void WalSndSetState(WalSndState state);123 124/*125 * Internal functions for parsing the replication grammar, in repl_gram.y and126 * repl_scanner.l127 */128extern int replication_yyparse(void);129extern int replication_yylex(void);130extern void replication_yyerror(const char *message) pg_attribute_noreturn();131extern void replication_scanner_init(const char *str);132extern void replication_scanner_finish(void);133extern bool replication_scanner_is_replication_command(void);134 135extern PGDLLIMPORT Node *replication_parse_result;136 137#endif /* _WALSENDER_PRIVATE_H */138 