PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
syncrep.h File Reference
#include "access/xlogdefs.h"
#include "utils/guc.h"
Include dependency graph for syncrep.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SyncRepConfigData
 

Macros

#define SyncRepRequested()   (max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH)
 
#define SYNC_REP_NO_WAIT   (-1)
 
#define SYNC_REP_WAIT_WRITE   0
 
#define SYNC_REP_WAIT_FLUSH   1
 
#define SYNC_REP_WAIT_APPLY   2
 
#define NUM_SYNC_REP_WAIT_MODE   3
 
#define SYNC_REP_NOT_WAITING   0
 
#define SYNC_REP_WAITING   1
 
#define SYNC_REP_WAIT_COMPLETE   2
 
#define SYNC_REP_PRIORITY   0
 
#define SYNC_REP_QUORUM   1
 

Typedefs

typedef struct SyncRepConfigData SyncRepConfigData
 

Functions

void SyncRepWaitForLSN (XLogRecPtr lsn, bool commit)
 
void SyncRepCleanupAtProcExit (void)
 
void SyncRepInitConfig (void)
 
void SyncRepReleaseWaiters (void)
 
ListSyncRepGetSyncStandbys (bool *am_sync)
 
void SyncRepUpdateSyncStandbysDefined (void)
 
bool check_synchronous_standby_names (char **newval, void **extra, GucSource source)
 
void assign_synchronous_standby_names (const char *newval, void *extra)
 
void assign_synchronous_commit (int newval, void *extra)
 
int syncrep_yyparse (void)
 
int syncrep_yylex (void)
 
void syncrep_yyerror (const char *str)
 
void syncrep_scanner_init (const char *query_string)
 
void syncrep_scanner_finish (void)
 

Variables

SyncRepConfigDataSyncRepConfig
 
SyncRepConfigDatasyncrep_parse_result
 
char * syncrep_parse_error_msg
 
char * SyncRepStandbyNames
 

Macro Definition Documentation

#define NUM_SYNC_REP_WAIT_MODE   3
#define SYNC_REP_NO_WAIT   (-1)

Definition at line 23 of file syncrep.h.

Referenced by assign_synchronous_commit().

#define SYNC_REP_NOT_WAITING   0

Definition at line 31 of file syncrep.h.

Referenced by InitProcess(), SyncRepCancelWait(), and SyncRepWaitForLSN().

#define SYNC_REP_PRIORITY   0
#define SYNC_REP_QUORUM   1

Definition at line 37 of file syncrep.h.

Referenced by SyncRepGetSyncStandbysQuorum().

#define SYNC_REP_WAIT_APPLY   2

Definition at line 26 of file syncrep.h.

Referenced by assign_synchronous_commit(), and SyncRepReleaseWaiters().

#define SYNC_REP_WAIT_COMPLETE   2

Definition at line 33 of file syncrep.h.

Referenced by SyncRepWaitForLSN(), and SyncRepWakeQueue().

#define SYNC_REP_WAIT_FLUSH   1

Definition at line 25 of file syncrep.h.

Referenced by assign_synchronous_commit(), SyncRepReleaseWaiters(), and SyncRepWaitForLSN().

#define SYNC_REP_WAIT_WRITE   0

Definition at line 24 of file syncrep.h.

Referenced by assign_synchronous_commit(), and SyncRepReleaseWaiters().

#define SYNC_REP_WAITING   1

Definition at line 32 of file syncrep.h.

Referenced by SyncRepWaitForLSN().

#define SyncRepRequested ( )    (max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH)

Definition at line 19 of file syncrep.h.

Referenced by SyncRepWaitForLSN().

Typedef Documentation

Function Documentation

void assign_synchronous_commit ( int  newval,
void *  extra 
)

Definition at line 1161 of file syncrep.c.

References SYNC_REP_NO_WAIT, SYNC_REP_WAIT_APPLY, SYNC_REP_WAIT_FLUSH, SYNC_REP_WAIT_WRITE, SYNCHRONOUS_COMMIT_REMOTE_APPLY, SYNCHRONOUS_COMMIT_REMOTE_FLUSH, SYNCHRONOUS_COMMIT_REMOTE_WRITE, and SyncRepWaitMode.

1162 {
1163  switch (newval)
1164  {
1167  break;
1170  break;
1173  break;
1174  default:
1176  break;
1177  }
1178 }
#define SYNC_REP_NO_WAIT
Definition: syncrep.h:23
#define SYNC_REP_WAIT_APPLY
Definition: syncrep.h:26
#define SYNC_REP_WAIT_FLUSH
Definition: syncrep.h:25
#define newval
static int SyncRepWaitMode
Definition: syncrep.c:94
#define SYNC_REP_WAIT_WRITE
Definition: syncrep.h:24
void assign_synchronous_standby_names ( const char *  newval,
void *  extra 
)

Definition at line 1155 of file syncrep.c.

1156 {
1157  SyncRepConfig = (SyncRepConfigData *) extra;
1158 }
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:93
bool check_synchronous_standby_names ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1098 of file syncrep.c.

References SyncRepConfigData::config_size, GUC_check_errcode(), GUC_check_errdetail, GUC_check_errmsg, malloc, NULL, SyncRepConfigData::num_sync, syncrep_parse_error_msg, syncrep_parse_result, syncrep_scanner_finish(), syncrep_scanner_init(), and syncrep_yyparse().

1099 {
1100  if (*newval != NULL && (*newval)[0] != '\0')
1101  {
1102  int parse_rc;
1103  SyncRepConfigData *pconf;
1104 
1105  /* Reset communication variables to ensure a fresh start */
1108 
1109  /* Parse the synchronous_standby_names string */
1111  parse_rc = syncrep_yyparse();
1113 
1114  if (parse_rc != 0 || syncrep_parse_result == NULL)
1115  {
1116  GUC_check_errcode(ERRCODE_SYNTAX_ERROR);
1119  else
1120  GUC_check_errdetail("synchronous_standby_names parser failed");
1121  return false;
1122  }
1123 
1124  if (syncrep_parse_result->num_sync <= 0)
1125  {
1126  GUC_check_errmsg("number of synchronous standbys (%d) must be greater than zero",
1128  return false;
1129  }
1130 
1131  /* GUC extra value must be malloc'd, not palloc'd */
1132  pconf = (SyncRepConfigData *)
1134  if (pconf == NULL)
1135  return false;
1137 
1138  *extra = (void *) pconf;
1139 
1140  /*
1141  * We need not explicitly clean up syncrep_parse_result. It, and any
1142  * other cruft generated during parsing, will be freed when the
1143  * current memory context is deleted. (This code is generally run in
1144  * a short-lived context used for config file processing, so that will
1145  * not be very long.)
1146  */
1147  }
1148  else
1149  *extra = NULL;
1150 
1151  return true;
1152 }
void syncrep_scanner_finish(void)
void syncrep_scanner_init(const char *query_string)
#define GUC_check_errdetail
Definition: guc.h:407
char * syncrep_parse_error_msg
#define GUC_check_errmsg
Definition: guc.h:403
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:9730
#define malloc(a)
Definition: header.h:45
#define NULL
Definition: c.h:226
SyncRepConfigData * syncrep_parse_result
#define newval
int syncrep_yyparse(void)
void syncrep_scanner_finish ( void  )
void syncrep_scanner_init ( const char *  query_string)
void syncrep_yyerror ( const char *  str)
int syncrep_yylex ( void  )
int syncrep_yyparse ( void  )
void SyncRepCleanupAtProcExit ( void  )

Definition at line 356 of file syncrep.c.

References LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProc, SHMQueueDelete(), SHMQueueIsDetached(), and PGPROC::syncRepLinks.

Referenced by ProcKill().

357 {
359  {
360  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
362  LWLockRelease(SyncRepLock);
363  }
364 }
PGPROC * MyProc
Definition: proc.c:67
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1714
bool SHMQueueIsDetached(const SHM_QUEUE *queue)
Definition: shmqueue.c:47
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1110
SHM_QUEUE syncRepLinks
Definition: proc.h:139
void SHMQueueDelete(SHM_QUEUE *queue)
Definition: shmqueue.c:68
List* SyncRepGetSyncStandbys ( bool am_sync)

Definition at line 672 of file syncrep.c.

References NIL, NULL, SYNC_REP_PRIORITY, SyncRepConfigData::syncrep_method, SyncRepGetSyncStandbysPriority(), and SyncRepGetSyncStandbysQuorum().

Referenced by pg_stat_get_wal_senders(), and SyncRepGetSyncRecPtr().

673 {
674  /* Set default result */
675  if (am_sync != NULL)
676  *am_sync = false;
677 
678  /* Quick exit if sync replication is not requested */
679  if (SyncRepConfig == NULL)
680  return NIL;
681 
685 }
#define NIL
Definition: pg_list.h:69
static List * SyncRepGetSyncStandbysPriority(bool *am_sync)
Definition: syncrep.c:753
#define SYNC_REP_PRIORITY
Definition: syncrep.h:36
uint8 syncrep_method
Definition: syncrep.h:51
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:93
static List * SyncRepGetSyncStandbysQuorum(bool *am_sync)
Definition: syncrep.c:698
#define NULL
Definition: c.h:226
void SyncRepInitConfig ( void  )

Definition at line 377 of file syncrep.c.

References application_name, DEBUG1, ereport, errmsg(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyWalSnd, WalSnd::sync_standby_priority, and SyncRepGetStandbyPriority().

Referenced by StartLogicalReplication(), StartReplication(), WalSndLoop(), WalSndWaitForWal(), and WalSndWriteData().

378 {
379  int priority;
380 
381  /*
382  * Determine if we are a potential sync standby and remember the result
383  * for handling replies from standby.
384  */
385  priority = SyncRepGetStandbyPriority();
386  if (MyWalSnd->sync_standby_priority != priority)
387  {
388  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
389  MyWalSnd->sync_standby_priority = priority;
390  LWLockRelease(SyncRepLock);
391  ereport(DEBUG1,
392  (errmsg("standby \"%s\" now has synchronous standby priority %u",
393  application_name, priority)));
394  }
395 }
#define DEBUG1
Definition: elog.h:25
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1714
#define ereport(elevel, rest)
Definition: elog.h:122
WalSnd * MyWalSnd
Definition: walsender.c:103
int sync_standby_priority
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1110
char * application_name
Definition: guc.c:471
int errmsg(const char *fmt,...)
Definition: elog.c:797
static int SyncRepGetStandbyPriority(void)
Definition: syncrep.c:921
void SyncRepReleaseWaiters ( void  )

Definition at line 405 of file syncrep.c.

References announce_next_takeover, application_name, DEBUG3, elog, ereport, errmsg(), WalSnd::flush, LOG, WalSndCtlData::lsn, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyWalSnd, WalSnd::state, SYNC_REP_PRIORITY, SYNC_REP_WAIT_APPLY, SYNC_REP_WAIT_FLUSH, SYNC_REP_WAIT_WRITE, WalSnd::sync_standby_priority, SyncRepConfigData::syncrep_method, SyncRepGetSyncRecPtr(), SyncRepWakeQueue(), WalSndCtl, WALSNDSTATE_STREAMING, and XLogRecPtrIsInvalid.

Referenced by ProcessStandbyReplyMessage().

406 {
407  volatile WalSndCtlData *walsndctl = WalSndCtl;
408  XLogRecPtr writePtr;
409  XLogRecPtr flushPtr;
410  XLogRecPtr applyPtr;
411  bool got_recptr;
412  bool am_sync;
413  int numwrite = 0;
414  int numflush = 0;
415  int numapply = 0;
416 
417  /*
418  * If this WALSender is serving a standby that is not on the list of
419  * potential sync standbys then we have nothing to do. If we are still
420  * starting up, still running base backup or the current flush position is
421  * still invalid, then leave quickly also.
422  */
423  if (MyWalSnd->sync_standby_priority == 0 ||
426  {
427  announce_next_takeover = true;
428  return;
429  }
430 
431  /*
432  * We're a potential sync standby. Release waiters if there are enough
433  * sync standbys and we are considered as sync.
434  */
435  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
436 
437  /*
438  * Check whether we are a sync standby or not, and calculate the synced
439  * positions among all sync standbys.
440  */
441  got_recptr = SyncRepGetSyncRecPtr(&writePtr, &flushPtr, &applyPtr, &am_sync);
442 
443  /*
444  * If we are managing a sync standby, though we weren't prior to this,
445  * then announce we are now a sync standby.
446  */
447  if (announce_next_takeover && am_sync)
448  {
449  announce_next_takeover = false;
450 
452  ereport(LOG,
453  (errmsg("standby \"%s\" is now a synchronous standby with priority %u",
455  else
456  ereport(LOG,
457  (errmsg("standby \"%s\" is now a candidate for quorum synchronous standby",
458  application_name)));
459  }
460 
461  /*
462  * If the number of sync standbys is less than requested or we aren't
463  * managing a sync standby then just leave.
464  */
465  if (!got_recptr || !am_sync)
466  {
467  LWLockRelease(SyncRepLock);
468  announce_next_takeover = !am_sync;
469  return;
470  }
471 
472  /*
473  * Set the lsn first so that when we wake backends they will release up to
474  * this location.
475  */
476  if (walsndctl->lsn[SYNC_REP_WAIT_WRITE] < writePtr)
477  {
478  walsndctl->lsn[SYNC_REP_WAIT_WRITE] = writePtr;
479  numwrite = SyncRepWakeQueue(false, SYNC_REP_WAIT_WRITE);
480  }
481  if (walsndctl->lsn[SYNC_REP_WAIT_FLUSH] < flushPtr)
482  {
483  walsndctl->lsn[SYNC_REP_WAIT_FLUSH] = flushPtr;
484  numflush = SyncRepWakeQueue(false, SYNC_REP_WAIT_FLUSH);
485  }
486  if (walsndctl->lsn[SYNC_REP_WAIT_APPLY] < applyPtr)
487  {
488  walsndctl->lsn[SYNC_REP_WAIT_APPLY] = applyPtr;
489  numapply = SyncRepWakeQueue(false, SYNC_REP_WAIT_APPLY);
490  }
491 
492  LWLockRelease(SyncRepLock);
493 
494  elog(DEBUG3, "released %d procs up to write %X/%X, %d procs up to flush %X/%X, %d procs up to apply %X/%X",
495  numwrite, (uint32) (writePtr >> 32), (uint32) writePtr,
496  numflush, (uint32) (flushPtr >> 32), (uint32) flushPtr,
497  numapply, (uint32) (applyPtr >> 32), (uint32) applyPtr);
498 }
static bool SyncRepGetSyncRecPtr(XLogRecPtr *writePtr, XLogRecPtr *flushPtr, XLogRecPtr *applyPtr, bool *am_sync)
Definition: syncrep.c:511
#define DEBUG3
Definition: elog.h:23
#define SYNC_REP_PRIORITY
Definition: syncrep.h:36
uint8 syncrep_method
Definition: syncrep.h:51
WalSndCtlData * WalSndCtl
Definition: walsender.c:100
#define LOG
Definition: elog.h:26
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:93
static int SyncRepWakeQueue(bool all, int mode)
Definition: syncrep.c:961
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1714
XLogRecPtr flush
#define SYNC_REP_WAIT_APPLY
Definition: syncrep.h:26
static bool announce_next_takeover
Definition: syncrep.c:91
WalSndState state
unsigned int uint32
Definition: c.h:265
#define ereport(elevel, rest)
Definition: elog.h:122
#define SYNC_REP_WAIT_FLUSH
Definition: syncrep.h:25
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
WalSnd * MyWalSnd
Definition: walsender.c:103
uint64 XLogRecPtr
Definition: xlogdefs.h:21
int sync_standby_priority
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1110
XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE]
char * application_name
Definition: guc.c:471
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
#define SYNC_REP_WAIT_WRITE
Definition: syncrep.h:24
void SyncRepUpdateSyncStandbysDefined ( void  )

Definition at line 1022 of file syncrep.c.

References i, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), NUM_SYNC_REP_WAIT_MODE, WalSndCtlData::sync_standbys_defined, SyncRepWakeQueue(), SyncStandbysDefined, and WalSndCtl.

Referenced by UpdateSharedMemoryConfig().

1023 {
1024  bool sync_standbys_defined = SyncStandbysDefined();
1025 
1026  if (sync_standbys_defined != WalSndCtl->sync_standbys_defined)
1027  {
1028  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
1029 
1030  /*
1031  * If synchronous_standby_names has been reset to empty, it's futile
1032  * for backends to continue to waiting. Since the user no longer
1033  * wants synchronous replication, we'd better wake them up.
1034  */
1035  if (!sync_standbys_defined)
1036  {
1037  int i;
1038 
1039  for (i = 0; i < NUM_SYNC_REP_WAIT_MODE; i++)
1040  SyncRepWakeQueue(true, i);
1041  }
1042 
1043  /*
1044  * Only allow people to join the queue when there are synchronous
1045  * standbys defined. Without this interlock, there's a race
1046  * condition: we might wake up all the current waiters; then, some
1047  * backend that hasn't yet reloaded its config might go to sleep on
1048  * the queue (and never wake up). This prevents that.
1049  */
1050  WalSndCtl->sync_standbys_defined = sync_standbys_defined;
1051 
1052  LWLockRelease(SyncRepLock);
1053  }
1054 }
WalSndCtlData * WalSndCtl
Definition: walsender.c:100
static int SyncRepWakeQueue(bool all, int mode)
Definition: syncrep.c:961
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1714
#define SyncStandbysDefined()
Definition: syncrep.c:88
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1110
int i
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:28
void SyncRepWaitForLSN ( XLogRecPtr  lsn,
bool  commit 
)

Definition at line 142 of file syncrep.c.

References Assert, DestNone, ereport, errcode(), errdetail(), errmsg(), get_ps_display(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), Min, MyLatch, MyProc, NULL, palloc(), pfree(), PostmasterIsAlive(), ProcDiePending, QueryCancelPending, ResetLatch(), set_ps_display(), SHMQueueIsDetached(), SYNC_REP_NOT_WAITING, SYNC_REP_WAIT_COMPLETE, SYNC_REP_WAIT_FLUSH, SYNC_REP_WAITING, WalSndCtlData::sync_standbys_defined, SyncRepCancelWait(), PGPROC::syncRepLinks, SyncRepQueueInsert(), SyncRepRequested, PGPROC::syncRepState, SyncRepWaitMode, SyncStandbysDefined, update_process_title, WAIT_EVENT_SYNC_REP, WaitLatch(), PGPROC::waitLSN, WalSndCtl, WARNING, whereToSendOutput, WL_LATCH_SET, and WL_POSTMASTER_DEATH.

Referenced by EndPrepare(), RecordTransactionAbortPrepared(), RecordTransactionCommit(), and RecordTransactionCommitPrepared().

143 {
144  char *new_status = NULL;
145  const char *old_status;
146  int mode;
147 
148  /* Cap the level for anything other than commit to remote flush only. */
149  if (commit)
150  mode = SyncRepWaitMode;
151  else
153 
154  /*
155  * Fast exit if user has not requested sync replication, or there are no
156  * sync replication standby names defined. Note that those standbys don't
157  * need to be connected.
158  */
160  return;
161 
163  Assert(WalSndCtl != NULL);
164 
165  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
167 
168  /*
169  * We don't wait for sync rep if WalSndCtl->sync_standbys_defined is not
170  * set. See SyncRepUpdateSyncStandbysDefined.
171  *
172  * Also check that the standby hasn't already replied. Unlikely race
173  * condition but we'll be fetching that cache line anyway so it's likely
174  * to be a low cost check.
175  */
177  lsn <= WalSndCtl->lsn[mode])
178  {
179  LWLockRelease(SyncRepLock);
180  return;
181  }
182 
183  /*
184  * Set our waitLSN so WALSender will know when to wake us, and add
185  * ourselves to the queue.
186  */
187  MyProc->waitLSN = lsn;
189  SyncRepQueueInsert(mode);
190  Assert(SyncRepQueueIsOrderedByLSN(mode));
191  LWLockRelease(SyncRepLock);
192 
193  /* Alter ps display to show waiting for sync rep. */
195  {
196  int len;
197 
198  old_status = get_ps_display(&len);
199  new_status = (char *) palloc(len + 32 + 1);
200  memcpy(new_status, old_status, len);
201  sprintf(new_status + len, " waiting for %X/%X",
202  (uint32) (lsn >> 32), (uint32) lsn);
203  set_ps_display(new_status, false);
204  new_status[len] = '\0'; /* truncate off " waiting ..." */
205  }
206 
207  /*
208  * Wait for specified LSN to be confirmed.
209  *
210  * Each proc has its own wait latch, so we perform a normal latch
211  * check/wait loop here.
212  */
213  for (;;)
214  {
215  /* Must reset the latch before testing state. */
217 
218  /*
219  * Acquiring the lock is not needed, the latch ensures proper
220  * barriers. If it looks like we're done, we must really be done,
221  * because once walsender changes the state to SYNC_REP_WAIT_COMPLETE,
222  * it will never update it again, so we can't be seeing a stale value
223  * in that case.
224  */
226  break;
227 
228  /*
229  * If a wait for synchronous replication is pending, we can neither
230  * acknowledge the commit nor raise ERROR or FATAL. The latter would
231  * lead the client to believe that the transaction aborted, which is
232  * not true: it's already committed locally. The former is no good
233  * either: the client has requested synchronous replication, and is
234  * entitled to assume that an acknowledged commit is also replicated,
235  * which might not be true. So in this case we issue a WARNING (which
236  * some clients may be able to interpret) and shut off further output.
237  * We do NOT reset ProcDiePending, so that the process will die after
238  * the commit is cleaned up.
239  */
240  if (ProcDiePending)
241  {
243  (errcode(ERRCODE_ADMIN_SHUTDOWN),
244  errmsg("canceling the wait for synchronous replication and terminating connection due to administrator command"),
245  errdetail("The transaction has already committed locally, but might not have been replicated to the standby.")));
248  break;
249  }
250 
251  /*
252  * It's unclear what to do if a query cancel interrupt arrives. We
253  * can't actually abort at this point, but ignoring the interrupt
254  * altogether is not helpful, so we just terminate the wait with a
255  * suitable warning.
256  */
257  if (QueryCancelPending)
258  {
259  QueryCancelPending = false;
261  (errmsg("canceling wait for synchronous replication due to user request"),
262  errdetail("The transaction has already committed locally, but might not have been replicated to the standby.")));
264  break;
265  }
266 
267  /*
268  * If the postmaster dies, we'll probably never get an
269  * acknowledgement, because all the wal sender processes will exit. So
270  * just bail out.
271  */
272  if (!PostmasterIsAlive())
273  {
274  ProcDiePending = true;
277  break;
278  }
279 
280  /*
281  * Wait on latch. Any condition that should wake us up will set the
282  * latch, so no need for timeout.
283  */
286  }
287 
288  /*
289  * WalSender has checked our LSN and has removed us from queue. Clean up
290  * state and leave. It's OK to reset these shared memory fields without
291  * holding SyncRepLock, because any walsenders will ignore us anyway when
292  * we're not on the queue.
293  */
296  MyProc->waitLSN = 0;
297 
298  if (new_status)
299  {
300  /* Reset ps display */
301  set_ps_display(new_status, false);
302  pfree(new_status);
303  }
304 }
static void SyncRepCancelWait(void)
Definition: syncrep.c:346
bool update_process_title
Definition: ps_status.c:35
static void SyncRepQueueInsert(int mode)
Definition: syncrep.c:313
PGPROC * MyProc
Definition: proc.c:67
#define SYNC_REP_WAITING
Definition: syncrep.h:32
#define Min(x, y)
Definition: c.h:801
void set_ps_display(const char *activity, bool force)
Definition: ps_status.c:326
#define SYNC_REP_NOT_WAITING
Definition: syncrep.h:31
WalSndCtlData * WalSndCtl
Definition: walsender.c:100
int errcode(int sqlerrcode)
Definition: elog.c:575
void ResetLatch(volatile Latch *latch)
Definition: latch.c:462
volatile bool QueryCancelPending
Definition: globals.c:30
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1714
int WaitLatch(volatile Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:301
void pfree(void *pointer)
Definition: mcxt.c:992
Definition: dest.h:88
const char * get_ps_display(int *displen)
Definition: ps_status.c:405
#define SyncStandbysDefined()
Definition: syncrep.c:88
bool PostmasterIsAlive(void)
Definition: pmsignal.c:272
int errdetail(const char *fmt,...)
Definition: elog.c:873
unsigned int uint32
Definition: c.h:265
#define ereport(elevel, rest)
Definition: elog.h:122
#define SYNC_REP_WAIT_FLUSH
Definition: syncrep.h:25
#define SyncRepRequested()
Definition: syncrep.h:19
#define WARNING
Definition: elog.h:40
#define WL_POSTMASTER_DEATH
Definition: latch.h:128
#define SYNC_REP_WAIT_COMPLETE
Definition: syncrep.h:33
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
bool SHMQueueIsDetached(const SHM_QUEUE *queue)
Definition: shmqueue.c:47
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1110
SHM_QUEUE syncRepLinks
Definition: proc.h:139
volatile bool ProcDiePending
Definition: globals.c:31
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
struct Latch * MyLatch
Definition: globals.c:51
int syncRepState
Definition: proc.h:138
CommandDest whereToSendOutput
Definition: postgres.c:86
static int SyncRepWaitMode
Definition: syncrep.c:94
#define WL_LATCH_SET
Definition: latch.h:124
XLogRecPtr waitLSN
Definition: proc.h:137

Variable Documentation

char* syncrep_parse_error_msg
SyncRepConfigData* syncrep_parse_result
SyncRepConfigData* SyncRepConfig

Definition at line 93 of file syncrep.c.

Referenced by pg_stat_get_wal_senders().

char* SyncRepStandbyNames

Definition at line 86 of file syncrep.c.