#include #include #include #include "access/xlog_internal.h" #include "access/xlogrecovery.h" #include "pgstat.h" #include "replication/walreceiver.h" #include "storage/pmsignal.h" #include "storage/proc.h" #include "storage/shmem.h" #include "utils/timestamp.h"">

PostgreSQL Source Code: src/backend/replication/walreceiverfuncs.c File Reference (original) (raw)

#include "[postgres.h](postgres%5F8h%5Fsource.html)"
#include <sys/stat.h>
#include <[sys/time.h](time%5F8h%5Fsource.html)>
#include <[unistd.h](unistd%5F8h%5Fsource.html)>
#include <signal.h>
#include "[access/xlog_internal.h](xlog%5F%5Finternal%5F8h%5Fsource.html)"
#include "[access/xlogrecovery.h](xlogrecovery%5F8h%5Fsource.html)"
#include "[pgstat.h](pgstat%5F8h%5Fsource.html)"
#include "[replication/walreceiver.h](walreceiver%5F8h%5Fsource.html)"
#include "[storage/pmsignal.h](pmsignal%5F8h%5Fsource.html)"
#include "[storage/proc.h](proc%5F8h%5Fsource.html)"
#include "[storage/shmem.h](shmem%5F8h%5Fsource.html)"
#include "[utils/timestamp.h](utils%5F2timestamp%5F8h%5Fsource.html)"

Go to the source code of this file.

Functions
Size WalRcvShmemSize (void)
void WalRcvShmemInit (void)
bool WalRcvRunning (void)
bool WalRcvStreaming (void)
void ShutdownWalRcv (void)
void RequestXLogStreaming (TimeLineID tli, XLogRecPtr recptr, const char *conninfo, const char *slotname, bool create_temp_slot)
XLogRecPtr GetWalRcvFlushRecPtr (XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
XLogRecPtr GetWalRcvWriteRecPtr (void)
int GetReplicationApplyDelay (void)
int GetReplicationTransferLatency (void)

WALRCV_STARTUP_TIMEOUT

#define WALRCV_STARTUP_TIMEOUT 10

GetReplicationApplyDelay()

int GetReplicationApplyDelay ( void )

GetReplicationTransferLatency()

int GetReplicationTransferLatency ( void )

GetWalRcvFlushRecPtr()

Definition at line 332 of file walreceiverfuncs.c.

333{

336

339 if (latestChunkStart)

344

345 return recptr;

346}

XLogRecPtr latestChunkStart

static TimeLineID receiveTLI

References WalRcvData::flushedUpto, WalRcvData::latestChunkStart, WalRcvData::mutex, WalRcvData::receivedTLI, receiveTLI, SpinLockAcquire, SpinLockRelease, and WalRcv.

Referenced by CreateRestartPoint(), GetLatestLSN(), GetStandbyFlushRecPtr(), pg_last_wal_receive_lsn(), reserve_wal_for_local_slot(), and WaitForWALToBecomeAvailable().

GetWalRcvWriteRecPtr()

RequestXLogStreaming()

void RequestXLogStreaming ( TimeLineID tli,
XLogRecPtr recptr,
const char * conninfo,
const char * slotname,
bool create_temp_slot
)

Definition at line 246 of file walreceiverfuncs.c.

248{

250 bool launch = false;

253

254

255

256

257

258

259

262

264

265

268

269 if (conninfo != NULL)

271 else

273

274

275

276

277

278

279

280 if (slotname != NULL && slotname[0] != '\0')

281 {

284 }

285 else

286 {

289 }

290

292 {

293 launch = true;

295 }

296 else

299

300

301

302

303

305 {

309 }

312

313 walrcv_proc = walrcv->procno;

314

316

317 if (launch)

321}

Datum now(PG_FUNCTION_ARGS)

Assert(PointerIsAligned(start, uint64))

void SetLatch(Latch *latch)

void SendPostmasterSignal(PMSignalReason reason)

@ PMSIGNAL_START_WALRECEIVER

size_t strlcpy(char *dst, const char *src, size_t siz)

#define GetPGProcByNumber(n)

#define INVALID_PROC_NUMBER

TimeLineID receiveStartTLI

char slotname[NAMEDATALEN]

char conninfo[MAXCONNINFO]

#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)

References Assert(), WalRcvData::conninfo, WalRcvData::flushedUpto, GetPGProcByNumber, INVALID_PROC_NUMBER, WalRcvData::is_temp_slot, WalRcvData::latestChunkStart, MAXCONNINFO, WalRcvData::mutex, NAMEDATALEN, now(), PMSIGNAL_START_WALRECEIVER, WalRcvData::procno, WalRcvData::receivedTLI, WalRcvData::receiveStart, WalRcvData::receiveStartTLI, SendPostmasterSignal(), SetLatch(), WalRcvData::slotname, SpinLockAcquire, SpinLockRelease, WalRcvData::startTime, strlcpy(), wal_segment_size, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_WAITING, WalRcvData::walRcvState, and XLogSegmentOffset.

Referenced by WaitForWALToBecomeAvailable().

ShutdownWalRcv()

void ShutdownWalRcv ( void )

Definition at line 179 of file walreceiverfuncs.c.

180{

182 pid_t walrcvpid = 0;

183 bool stopped = false;

184

185

186

187

188

189

192 {

194 break;

197 stopped = true;

198 break;

199

204

206 walrcvpid = walrcv->pid;

207 break;

208 }

210

211

212 if (stopped)

214

215

216

217

218 if (walrcvpid != 0)

219 kill(walrcvpid, SIGTERM);

220

221

222

223

224

228 WAIT_EVENT_WAL_RECEIVER_EXIT);

230}

bool ConditionVariableCancelSleep(void)

void ConditionVariableBroadcast(ConditionVariable *cv)

void ConditionVariablePrepareToSleep(ConditionVariable *cv)

void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)

ConditionVariable walRcvStoppedCV

References ConditionVariableBroadcast(), ConditionVariableCancelSleep(), ConditionVariablePrepareToSleep(), ConditionVariableSleep(), kill, WalRcvData::mutex, WalRcvData::pid, SpinLockAcquire, SpinLockRelease, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, WalRcvRunning(), WalRcvData::walRcvState, and WalRcvData::walRcvStoppedCV.

Referenced by XLogShutdownWalRcv().

WalRcvRunning()

bool WalRcvRunning ( void )

Definition at line 76 of file walreceiverfuncs.c.

77{

81

83

86

88

89

90

91

92

93

94

96 {

98

100 {

101 bool stopped = false;

102

105 {

107 stopped = true;

108 }

110

111 if (stopped)

113 }

114 }

115

117 return true;

118 else

119 return false;

120}

#define WALRCV_STARTUP_TIMEOUT

References ConditionVariableBroadcast(), WalRcvData::mutex, now(), SpinLockAcquire, SpinLockRelease, WalRcvData::startTime, WalRcv, WALRCV_STARTING, WALRCV_STARTUP_TIMEOUT, WALRCV_STOPPED, WalRcvData::walRcvState, and WalRcvData::walRcvStoppedCV.

Referenced by ShutdownWalRcv(), and StartupRequestWalReceiverRestart().

WalRcvShmemInit()

void WalRcvShmemInit ( void )

Definition at line 55 of file walreceiverfuncs.c.

56{

57 bool found;

58

61

62 if (!found)

63 {

64

71 }

72}

static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)

#define MemSet(start, val, len)

void ConditionVariableInit(ConditionVariable *cv)

void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)

#define SpinLockInit(lock)

Size WalRcvShmemSize(void)

References ConditionVariableInit(), INVALID_PROC_NUMBER, MemSet, WalRcvData::mutex, pg_atomic_init_u64(), WalRcvData::procno, ShmemInitStruct(), SpinLockInit, WalRcv, WALRCV_STOPPED, WalRcvShmemSize(), WalRcvData::walRcvState, WalRcvData::walRcvStoppedCV, and WalRcvData::writtenUpto.

Referenced by CreateOrAttachShmemStructs().

WalRcvShmemSize()

Size WalRcvShmemSize ( void )

WalRcvStreaming()

bool WalRcvStreaming ( void )

Definition at line 127 of file walreceiverfuncs.c.

128{

132

134

137

139

140

141

142

143

144

145

147 {

149

151 {

152 bool stopped = false;

153

156 {

158 stopped = true;

159 }

161

162 if (stopped)

164 }

165 }

166

169 return true;

170 else

171 return false;

172}

References ConditionVariableBroadcast(), WalRcvData::mutex, now(), SpinLockAcquire, SpinLockRelease, WalRcvData::startTime, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STARTUP_TIMEOUT, WALRCV_STOPPED, WALRCV_STREAMING, WalRcvData::walRcvState, and WalRcvData::walRcvStoppedCV.

Referenced by FinishWalRecovery(), and WaitForWALToBecomeAvailable().

WalRcv

Definition at line 34 of file walreceiverfuncs.c.

Referenced by GetReplicationApplyDelay(), GetReplicationTransferLatency(), GetWalRcvFlushRecPtr(), GetWalRcvWriteRecPtr(), pg_stat_get_wal_receiver(), ProcessWalSndrMessage(), RequestXLogStreaming(), ShutdownWalRcv(), WalRcvDie(), WalRcvForceReply(), WalRcvRunning(), WalRcvShmemInit(), WalRcvStreaming(), WalRcvWaitForStartPosition(), WalReceiverMain(), XLogWalRcvFlush(), and XLogWalRcvWrite().