PostgreSQL Source Code  git master
syncrep.c File Reference
#include "postgres.h"
#include <unistd.h>
#include "access/xact.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "replication/syncrep.h"
#include "replication/walsender.h"
#include "replication/walsender_private.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/ps_status.h"
Include dependency graph for syncrep.c:

Go to the source code of this file.

Macros

#define SyncStandbysDefined()   (SyncRepStandbyNames != NULL && SyncRepStandbyNames[0] != '\0')
 

Functions

static void SyncRepQueueInsert (int mode)
 
static void SyncRepCancelWait (void)
 
static int SyncRepWakeQueue (bool all, int mode)
 
static bool SyncRepGetSyncRecPtr (XLogRecPtr *writePtr, XLogRecPtr *flushPtr, XLogRecPtr *applyPtr, bool *am_sync)
 
static void SyncRepGetOldestSyncRecPtr (XLogRecPtr *writePtr, XLogRecPtr *flushPtr, XLogRecPtr *applyPtr, SyncRepStandbyData *sync_standbys, int num_standbys)
 
static void SyncRepGetNthLatestSyncRecPtr (XLogRecPtr *writePtr, XLogRecPtr *flushPtr, XLogRecPtr *applyPtr, SyncRepStandbyData *sync_standbys, int num_standbys, uint8 nth)
 
static int SyncRepGetStandbyPriority (void)
 
static int standby_priority_comparator (const void *a, const void *b)
 
static int cmp_lsn (const void *a, const void *b)
 
void SyncRepWaitForLSN (XLogRecPtr lsn, bool commit)
 
void SyncRepCleanupAtProcExit (void)
 
void SyncRepInitConfig (void)
 
void SyncRepReleaseWaiters (void)
 
int SyncRepGetCandidateStandbys (SyncRepStandbyData **standbys)
 
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)
 

Variables

char * SyncRepStandbyNames
 
static bool announce_next_takeover = true
 
SyncRepConfigDataSyncRepConfig = NULL
 
static int SyncRepWaitMode = SYNC_REP_NO_WAIT
 

Macro Definition Documentation

◆ SyncStandbysDefined

#define SyncStandbysDefined ( )    (SyncRepStandbyNames != NULL && SyncRepStandbyNames[0] != '\0')

Definition at line 92 of file syncrep.c.

Referenced by SyncRepGetStandbyPriority(), and SyncRepUpdateSyncStandbysDefined().

Function Documentation

◆ assign_synchronous_commit()

void assign_synchronous_commit ( int  newval,
void *  extra 
)

Definition at line 1086 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.

1087 {
1088  switch (newval)
1089  {
1092  break;
1095  break;
1098  break;
1099  default:
1101  break;
1102  }
1103 }
#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:98
#define SYNC_REP_WAIT_WRITE
Definition: syncrep.h:24

◆ assign_synchronous_standby_names()

void assign_synchronous_standby_names ( const char *  newval,
void *  extra 
)

Definition at line 1080 of file syncrep.c.

1081 {
1082  SyncRepConfig = (SyncRepConfigData *) extra;
1083 }
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:97

◆ check_synchronous_standby_names()

bool check_synchronous_standby_names ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1023 of file syncrep.c.

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

1024 {
1025  if (*newval != NULL && (*newval)[0] != '\0')
1026  {
1027  int parse_rc;
1028  SyncRepConfigData *pconf;
1029 
1030  /* Reset communication variables to ensure a fresh start */
1031  syncrep_parse_result = NULL;
1032  syncrep_parse_error_msg = NULL;
1033 
1034  /* Parse the synchronous_standby_names string */
1036  parse_rc = syncrep_yyparse();
1038 
1039  if (parse_rc != 0 || syncrep_parse_result == NULL)
1040  {
1041  GUC_check_errcode(ERRCODE_SYNTAX_ERROR);
1044  else
1045  GUC_check_errdetail("synchronous_standby_names parser failed");
1046  return false;
1047  }
1048 
1049  if (syncrep_parse_result->num_sync <= 0)
1050  {
1051  GUC_check_errmsg("number of synchronous standbys (%d) must be greater than zero",
1053  return false;
1054  }
1055 
1056  /* GUC extra value must be malloc'd, not palloc'd */
1057  pconf = (SyncRepConfigData *)
1059  if (pconf == NULL)
1060  return false;
1062 
1063  *extra = (void *) pconf;
1064 
1065  /*
1066  * We need not explicitly clean up syncrep_parse_result. It, and any
1067  * other cruft generated during parsing, will be freed when the
1068  * current memory context is deleted. (This code is generally run in
1069  * a short-lived context used for config file processing, so that will
1070  * not be very long.)
1071  */
1072  }
1073  else
1074  *extra = NULL;
1075 
1076  return true;
1077 }
void syncrep_scanner_finish(void)
void syncrep_scanner_init(const char *query_string)
#define GUC_check_errdetail
Definition: guc.h:422
char * syncrep_parse_error_msg
#define GUC_check_errmsg
Definition: guc.h:418
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:11403
#define malloc(a)
Definition: header.h:50
SyncRepConfigData * syncrep_parse_result
#define newval
int syncrep_yyparse(void)

◆ cmp_lsn()

static int cmp_lsn ( const void *  a,
const void *  b 
)
static

Definition at line 704 of file syncrep.c.

Referenced by SyncRepGetNthLatestSyncRecPtr().

705 {
706  XLogRecPtr lsn1 = *((const XLogRecPtr *) a);
707  XLogRecPtr lsn2 = *((const XLogRecPtr *) b);
708 
709  if (lsn1 > lsn2)
710  return -1;
711  else if (lsn1 == lsn2)
712  return 0;
713  else
714  return 1;
715 }
uint64 XLogRecPtr
Definition: xlogdefs.h:21

◆ standby_priority_comparator()

static int standby_priority_comparator ( const void *  a,
const void *  b 
)
static

Definition at line 804 of file syncrep.c.

References SyncRepStandbyData::sync_standby_priority, and SyncRepStandbyData::walsnd_index.

Referenced by SyncRepGetCandidateStandbys().

805 {
806  const SyncRepStandbyData *sa = (const SyncRepStandbyData *) a;
807  const SyncRepStandbyData *sb = (const SyncRepStandbyData *) b;
808 
809  /* First, sort by increasing priority value */
812 
813  /*
814  * We might have equal priority values; arbitrarily break ties by position
815  * in the WALSnd array. (This is utterly bogus, since that is arrival
816  * order dependent, but there are regression tests that rely on it.)
817  */
818  return sa->walsnd_index - sb->walsnd_index;
819 }
int sync_standby_priority
Definition: syncrep.h:50

◆ SyncRepCancelWait()

static void SyncRepCancelWait ( void  )
static

Definition at line 372 of file syncrep.c.

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

Referenced by SyncRepWaitForLSN().

373 {
374  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
378  LWLockRelease(SyncRepLock);
379 }
PGPROC * MyProc
Definition: proc.c:68
#define SYNC_REP_NOT_WAITING
Definition: syncrep.h:31
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
bool SHMQueueIsDetached(const SHM_QUEUE *queue)
Definition: shmqueue.c:47
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
SHM_QUEUE syncRepLinks
Definition: proc.h:201
void SHMQueueDelete(SHM_QUEUE *queue)
Definition: shmqueue.c:68
int syncRepState
Definition: proc.h:200

◆ SyncRepCleanupAtProcExit()

void SyncRepCleanupAtProcExit ( void  )

Definition at line 382 of file syncrep.c.

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

Referenced by ProcKill().

383 {
384  /*
385  * First check if we are removed from the queue without the lock to not
386  * slow down backend exit.
387  */
389  {
390  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
391 
392  /* maybe we have just been removed, so recheck */
395 
396  LWLockRelease(SyncRepLock);
397  }
398 }
PGPROC * MyProc
Definition: proc.c:68
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
bool SHMQueueIsDetached(const SHM_QUEUE *queue)
Definition: shmqueue.c:47
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
SHM_QUEUE syncRepLinks
Definition: proc.h:201
void SHMQueueDelete(SHM_QUEUE *queue)
Definition: shmqueue.c:68

◆ SyncRepGetCandidateStandbys()

int SyncRepGetCandidateStandbys ( SyncRepStandbyData **  standbys)

Definition at line 725 of file syncrep.c.

References SyncRepStandbyData::apply, WalSnd::apply, SyncRepStandbyData::flush, WalSnd::flush, i, SyncRepStandbyData::is_me, max_wal_senders, WalSnd::mutex, MyWalSnd, SyncRepConfigData::num_sync, palloc(), WalSnd::pid, SyncRepStandbyData::pid, qsort, SpinLockAcquire, SpinLockRelease, standby_priority_comparator(), WalSnd::state, SYNC_REP_PRIORITY, SyncRepStandbyData::sync_standby_priority, WalSnd::sync_standby_priority, SyncRepConfigData::syncrep_method, SyncRepStandbyData::walsnd_index, WalSndCtl, WalSndCtlData::walsnds, WALSNDSTATE_STOPPING, WALSNDSTATE_STREAMING, SyncRepStandbyData::write, WalSnd::write, and XLogRecPtrIsInvalid.

Referenced by pg_stat_get_wal_senders(), and SyncRepGetSyncRecPtr().

726 {
727  int i;
728  int n;
729 
730  /* Create result array */
731  *standbys = (SyncRepStandbyData *)
733 
734  /* Quick exit if sync replication is not requested */
735  if (SyncRepConfig == NULL)
736  return 0;
737 
738  /* Collect raw data from shared memory */
739  n = 0;
740  for (i = 0; i < max_wal_senders; i++)
741  {
742  volatile WalSnd *walsnd; /* Use volatile pointer to prevent code
743  * rearrangement */
744  SyncRepStandbyData *stby;
745  WalSndState state; /* not included in SyncRepStandbyData */
746 
747  walsnd = &WalSndCtl->walsnds[i];
748  stby = *standbys + n;
749 
750  SpinLockAcquire(&walsnd->mutex);
751  stby->pid = walsnd->pid;
752  state = walsnd->state;
753  stby->write = walsnd->write;
754  stby->flush = walsnd->flush;
755  stby->apply = walsnd->apply;
757  SpinLockRelease(&walsnd->mutex);
758 
759  /* Must be active */
760  if (stby->pid == 0)
761  continue;
762 
763  /* Must be streaming or stopping */
764  if (state != WALSNDSTATE_STREAMING &&
765  state != WALSNDSTATE_STOPPING)
766  continue;
767 
768  /* Must be synchronous */
769  if (stby->sync_standby_priority == 0)
770  continue;
771 
772  /* Must have a valid flush position */
773  if (XLogRecPtrIsInvalid(stby->flush))
774  continue;
775 
776  /* OK, it's a candidate */
777  stby->walsnd_index = i;
778  stby->is_me = (walsnd == MyWalSnd);
779  n++;
780  }
781 
782  /*
783  * In quorum mode, we return all the candidates. In priority mode, if we
784  * have too many candidates then return only the num_sync ones of highest
785  * priority.
786  */
788  n > SyncRepConfig->num_sync)
789  {
790  /* Sort by priority ... */
791  qsort(*standbys, n, sizeof(SyncRepStandbyData),
793  /* ... then report just the first num_sync ones */
794  n = SyncRepConfig->num_sync;
795  }
796 
797  return n;
798 }
XLogRecPtr write
#define SYNC_REP_PRIORITY
Definition: syncrep.h:36
uint8 syncrep_method
Definition: syncrep.h:69
WalSndCtlData * WalSndCtl
Definition: walsender.c:109
WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER]
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:97
int sync_standby_priority
Definition: syncrep.h:50
slock_t mutex
#define SpinLockAcquire(lock)
Definition: spin.h:62
XLogRecPtr flush
static int standby_priority_comparator(const void *a, const void *b)
Definition: syncrep.c:804
XLogRecPtr flush
Definition: syncrep.h:48
XLogRecPtr write
Definition: syncrep.h:47
WalSndState state
XLogRecPtr apply
Definition: syncrep.h:49
int max_wal_senders
Definition: walsender.c:121
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
#define SpinLockRelease(lock)
Definition: spin.h:64
WalSnd * MyWalSnd
Definition: walsender.c:112
int sync_standby_priority
Definition: regguts.h:317
WalSndState
void * palloc(Size size)
Definition: mcxt.c:1062
int i
#define qsort(a, b, c, d)
Definition: port.h:505
XLogRecPtr apply

◆ SyncRepGetNthLatestSyncRecPtr()

static void SyncRepGetNthLatestSyncRecPtr ( XLogRecPtr writePtr,
XLogRecPtr flushPtr,
XLogRecPtr applyPtr,
SyncRepStandbyData sync_standbys,
int  num_standbys,
uint8  nth 
)
static

Definition at line 659 of file syncrep.c.

References SyncRepStandbyData::apply, Assert, cmp_lsn(), SyncRepStandbyData::flush, i, palloc(), pfree(), qsort, and SyncRepStandbyData::write.

Referenced by SyncRepGetSyncRecPtr().

665 {
666  XLogRecPtr *write_array;
667  XLogRecPtr *flush_array;
668  XLogRecPtr *apply_array;
669  int i;
670 
671  /* Should have enough candidates, or somebody messed up */
672  Assert(nth > 0 && nth <= num_standbys);
673 
674  write_array = (XLogRecPtr *) palloc(sizeof(XLogRecPtr) * num_standbys);
675  flush_array = (XLogRecPtr *) palloc(sizeof(XLogRecPtr) * num_standbys);
676  apply_array = (XLogRecPtr *) palloc(sizeof(XLogRecPtr) * num_standbys);
677 
678  for (i = 0; i < num_standbys; i++)
679  {
680  write_array[i] = sync_standbys[i].write;
681  flush_array[i] = sync_standbys[i].flush;
682  apply_array[i] = sync_standbys[i].apply;
683  }
684 
685  /* Sort each array in descending order */
686  qsort(write_array, num_standbys, sizeof(XLogRecPtr), cmp_lsn);
687  qsort(flush_array, num_standbys, sizeof(XLogRecPtr), cmp_lsn);
688  qsort(apply_array, num_standbys, sizeof(XLogRecPtr), cmp_lsn);
689 
690  /* Get Nth latest Write, Flush, Apply positions */
691  *writePtr = write_array[nth - 1];
692  *flushPtr = flush_array[nth - 1];
693  *applyPtr = apply_array[nth - 1];
694 
695  pfree(write_array);
696  pfree(flush_array);
697  pfree(apply_array);
698 }
void pfree(void *pointer)
Definition: mcxt.c:1169
static int cmp_lsn(const void *a, const void *b)
Definition: syncrep.c:704
XLogRecPtr flush
Definition: syncrep.h:48
XLogRecPtr write
Definition: syncrep.h:47
XLogRecPtr apply
Definition: syncrep.h:49
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
void * palloc(Size size)
Definition: mcxt.c:1062
int i
#define qsort(a, b, c, d)
Definition: port.h:505

◆ SyncRepGetOldestSyncRecPtr()

static void SyncRepGetOldestSyncRecPtr ( XLogRecPtr writePtr,
XLogRecPtr flushPtr,
XLogRecPtr applyPtr,
SyncRepStandbyData sync_standbys,
int  num_standbys 
)
static

Definition at line 626 of file syncrep.c.

References SyncRepStandbyData::apply, SyncRepStandbyData::flush, i, write, SyncRepStandbyData::write, and XLogRecPtrIsInvalid.

Referenced by SyncRepGetSyncRecPtr().

631 {
632  int i;
633 
634  /*
635  * Scan through all sync standbys and calculate the oldest Write, Flush
636  * and Apply positions. We assume *writePtr et al were initialized to
637  * InvalidXLogRecPtr.
638  */
639  for (i = 0; i < num_standbys; i++)
640  {
641  XLogRecPtr write = sync_standbys[i].write;
642  XLogRecPtr flush = sync_standbys[i].flush;
643  XLogRecPtr apply = sync_standbys[i].apply;
644 
645  if (XLogRecPtrIsInvalid(*writePtr) || *writePtr > write)
646  *writePtr = write;
647  if (XLogRecPtrIsInvalid(*flushPtr) || *flushPtr > flush)
648  *flushPtr = flush;
649  if (XLogRecPtrIsInvalid(*applyPtr) || *applyPtr > apply)
650  *applyPtr = apply;
651  }
652 }
#define write(a, b, c)
Definition: win32.h:14
XLogRecPtr flush
Definition: syncrep.h:48
XLogRecPtr write
Definition: syncrep.h:47
XLogRecPtr apply
Definition: syncrep.h:49
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
uint64 XLogRecPtr
Definition: xlogdefs.h:21
int i

◆ SyncRepGetStandbyPriority()

static int SyncRepGetStandbyPriority ( void  )
static

Definition at line 831 of file syncrep.c.

References am_cascading_walsender, application_name, SyncRepConfigData::member_names, SyncRepConfigData::nmembers, pg_strcasecmp(), SYNC_REP_PRIORITY, SyncRepConfigData::syncrep_method, and SyncStandbysDefined.

Referenced by SyncRepInitConfig().

832 {
833  const char *standby_name;
834  int priority;
835  bool found = false;
836 
837  /*
838  * Since synchronous cascade replication is not allowed, we always set the
839  * priority of cascading walsender to zero.
840  */
842  return 0;
843 
844  if (!SyncStandbysDefined() || SyncRepConfig == NULL)
845  return 0;
846 
847  standby_name = SyncRepConfig->member_names;
848  for (priority = 1; priority <= SyncRepConfig->nmembers; priority++)
849  {
850  if (pg_strcasecmp(standby_name, application_name) == 0 ||
851  strcmp(standby_name, "*") == 0)
852  {
853  found = true;
854  break;
855  }
856  standby_name += strlen(standby_name) + 1;
857  }
858 
859  if (!found)
860  return 0;
861 
862  /*
863  * In quorum-based sync replication, all the standbys in the list have the
864  * same priority, one.
865  */
866  return (SyncRepConfig->syncrep_method == SYNC_REP_PRIORITY) ? priority : 1;
867 }
#define SYNC_REP_PRIORITY
Definition: syncrep.h:36
uint8 syncrep_method
Definition: syncrep.h:69
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:97
#define SyncStandbysDefined()
Definition: syncrep.c:92
char member_names[FLEXIBLE_ARRAY_MEMBER]
Definition: syncrep.h:72
char * application_name
Definition: guc.c:621
bool am_cascading_walsender
Definition: walsender.c:116

◆ SyncRepGetSyncRecPtr()

static bool SyncRepGetSyncRecPtr ( XLogRecPtr writePtr,
XLogRecPtr flushPtr,
XLogRecPtr applyPtr,
bool am_sync 
)
static

Definition at line 552 of file syncrep.c.

References i, InvalidXLogRecPtr, SyncRepConfigData::num_sync, pfree(), SYNC_REP_PRIORITY, SyncRepConfigData::syncrep_method, SyncRepGetCandidateStandbys(), SyncRepGetNthLatestSyncRecPtr(), and SyncRepGetOldestSyncRecPtr().

Referenced by SyncRepReleaseWaiters().

554 {
555  SyncRepStandbyData *sync_standbys;
556  int num_standbys;
557  int i;
558 
559  /* Initialize default results */
560  *writePtr = InvalidXLogRecPtr;
561  *flushPtr = InvalidXLogRecPtr;
562  *applyPtr = InvalidXLogRecPtr;
563  *am_sync = false;
564 
565  /* Quick out if not even configured to be synchronous */
566  if (SyncRepConfig == NULL)
567  return false;
568 
569  /* Get standbys that are considered as synchronous at this moment */
570  num_standbys = SyncRepGetCandidateStandbys(&sync_standbys);
571 
572  /* Am I among the candidate sync standbys? */
573  for (i = 0; i < num_standbys; i++)
574  {
575  if (sync_standbys[i].is_me)
576  {
577  *am_sync = true;
578  break;
579  }
580  }
581 
582  /*
583  * Nothing more to do if we are not managing a sync standby or there are
584  * not enough synchronous standbys.
585  */
586  if (!(*am_sync) ||
587  num_standbys < SyncRepConfig->num_sync)
588  {
589  pfree(sync_standbys);
590  return false;
591  }
592 
593  /*
594  * In a priority-based sync replication, the synced positions are the
595  * oldest ones among sync standbys. In a quorum-based, they are the Nth
596  * latest ones.
597  *
598  * SyncRepGetNthLatestSyncRecPtr() also can calculate the oldest
599  * positions. But we use SyncRepGetOldestSyncRecPtr() for that calculation
600  * because it's a bit more efficient.
601  *
602  * XXX If the numbers of current and requested sync standbys are the same,
603  * we can use SyncRepGetOldestSyncRecPtr() to calculate the synced
604  * positions even in a quorum-based sync replication.
605  */
607  {
608  SyncRepGetOldestSyncRecPtr(writePtr, flushPtr, applyPtr,
609  sync_standbys, num_standbys);
610  }
611  else
612  {
613  SyncRepGetNthLatestSyncRecPtr(writePtr, flushPtr, applyPtr,
614  sync_standbys, num_standbys,
616  }
617 
618  pfree(sync_standbys);
619  return true;
620 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define SYNC_REP_PRIORITY
Definition: syncrep.h:36
uint8 syncrep_method
Definition: syncrep.h:69
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:97
void pfree(void *pointer)
Definition: mcxt.c:1169
static void SyncRepGetNthLatestSyncRecPtr(XLogRecPtr *writePtr, XLogRecPtr *flushPtr, XLogRecPtr *applyPtr, SyncRepStandbyData *sync_standbys, int num_standbys, uint8 nth)
Definition: syncrep.c:659
static void SyncRepGetOldestSyncRecPtr(XLogRecPtr *writePtr, XLogRecPtr *flushPtr, XLogRecPtr *applyPtr, SyncRepStandbyData *sync_standbys, int num_standbys)
Definition: syncrep.c:626
int SyncRepGetCandidateStandbys(SyncRepStandbyData **standbys)
Definition: syncrep.c:725
int i

◆ SyncRepInitConfig()

void SyncRepInitConfig ( void  )

Definition at line 411 of file syncrep.c.

References application_name, DEBUG1, ereport, errmsg_internal(), WalSnd::mutex, MyWalSnd, SpinLockAcquire, SpinLockRelease, WalSnd::sync_standby_priority, and SyncRepGetStandbyPriority().

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

412 {
413  int priority;
414 
415  /*
416  * Determine if we are a potential sync standby and remember the result
417  * for handling replies from standby.
418  */
419  priority = SyncRepGetStandbyPriority();
420  if (MyWalSnd->sync_standby_priority != priority)
421  {
423  MyWalSnd->sync_standby_priority = priority;
425 
426  ereport(DEBUG1,
427  (errmsg_internal("standby \"%s\" now has synchronous standby priority %u",
428  application_name, priority)));
429  }
430 }
#define DEBUG1
Definition: elog.h:25
slock_t mutex
#define SpinLockAcquire(lock)
Definition: spin.h:62
#define SpinLockRelease(lock)
Definition: spin.h:64
WalSnd * MyWalSnd
Definition: walsender.c:112
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
int sync_standby_priority
char * application_name
Definition: guc.c:621
static int SyncRepGetStandbyPriority(void)
Definition: syncrep.c:831

◆ SyncRepQueueInsert()

static void SyncRepQueueInsert ( int  mode)
static

Definition at line 339 of file syncrep.c.

References Assert, mode, MyProc, NUM_SYNC_REP_WAIT_MODE, offsetof, SHMQueueInsertAfter(), SHMQueuePrev(), PGPROC::syncRepLinks, WalSndCtlData::SyncRepQueue, PGPROC::waitLSN, and WalSndCtl.

Referenced by SyncRepWaitForLSN().

340 {
341  PGPROC *proc;
342 
346  offsetof(PGPROC, syncRepLinks));
347 
348  while (proc)
349  {
350  /*
351  * Stop at the queue element that we should after to ensure the queue
352  * is ordered by LSN.
353  */
354  if (proc->waitLSN < MyProc->waitLSN)
355  break;
356 
358  &(proc->syncRepLinks),
359  offsetof(PGPROC, syncRepLinks));
360  }
361 
362  if (proc)
364  else
366 }
static PgChecksumMode mode
Definition: pg_checksums.c:65
Pointer SHMQueuePrev(const SHM_QUEUE *queue, const SHM_QUEUE *curElem, Size linkOffset)
Definition: shmqueue.c:164
PGPROC * MyProc
Definition: proc.c:68
WalSndCtlData * WalSndCtl
Definition: walsender.c:109
void SHMQueueInsertAfter(SHM_QUEUE *queue, SHM_QUEUE *elem)
Definition: shmqueue.c:108
SHM_QUEUE SyncRepQueue[NUM_SYNC_REP_WAIT_MODE]
#define Assert(condition)
Definition: c.h:804
SHM_QUEUE syncRepLinks
Definition: proc.h:201
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:28
Definition: proc.h:121
XLogRecPtr waitLSN
Definition: proc.h:199
#define offsetof(type, field)
Definition: c.h:727

◆ SyncRepReleaseWaiters()

void SyncRepReleaseWaiters ( void  )

Definition at line 440 of file syncrep.c.

References announce_next_takeover, application_name, DEBUG3, elog, ereport, errmsg(), WalSnd::flush, LOG, WalSndCtlData::lsn, LSN_FORMAT_ARGS, 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_STOPPING, WALSNDSTATE_STREAMING, and XLogRecPtrIsInvalid.

Referenced by ProcessStandbyReplyMessage().

441 {
442  volatile WalSndCtlData *walsndctl = WalSndCtl;
443  XLogRecPtr writePtr;
444  XLogRecPtr flushPtr;
445  XLogRecPtr applyPtr;
446  bool got_recptr;
447  bool am_sync;
448  int numwrite = 0;
449  int numflush = 0;
450  int numapply = 0;
451 
452  /*
453  * If this WALSender is serving a standby that is not on the list of
454  * potential sync standbys then we have nothing to do. If we are still
455  * starting up, still running base backup or the current flush position is
456  * still invalid, then leave quickly also. Streaming or stopping WAL
457  * senders are allowed to release waiters.
458  */
459  if (MyWalSnd->sync_standby_priority == 0 ||
463  {
464  announce_next_takeover = true;
465  return;
466  }
467 
468  /*
469  * We're a potential sync standby. Release waiters if there are enough
470  * sync standbys and we are considered as sync.
471  */
472  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
473 
474  /*
475  * Check whether we are a sync standby or not, and calculate the synced
476  * positions among all sync standbys. (Note: although this step does not
477  * of itself require holding SyncRepLock, it seems like a good idea to do
478  * it after acquiring the lock. This ensures that the WAL pointers we use
479  * to release waiters are newer than any previous execution of this
480  * routine used.)
481  */
482  got_recptr = SyncRepGetSyncRecPtr(&writePtr, &flushPtr, &applyPtr, &am_sync);
483 
484  /*
485  * If we are managing a sync standby, though we weren't prior to this,
486  * then announce we are now a sync standby.
487  */
488  if (announce_next_takeover && am_sync)
489  {
490  announce_next_takeover = false;
491 
493  ereport(LOG,
494  (errmsg("standby \"%s\" is now a synchronous standby with priority %u",
496  else
497  ereport(LOG,
498  (errmsg("standby \"%s\" is now a candidate for quorum synchronous standby",
499  application_name)));
500  }
501 
502  /*
503  * If the number of sync standbys is less than requested or we aren't
504  * managing a sync standby then just leave.
505  */
506  if (!got_recptr || !am_sync)
507  {
508  LWLockRelease(SyncRepLock);
509  announce_next_takeover = !am_sync;
510  return;
511  }
512 
513  /*
514  * Set the lsn first so that when we wake backends they will release up to
515  * this location.
516  */
517  if (walsndctl->lsn[SYNC_REP_WAIT_WRITE] < writePtr)
518  {
519  walsndctl->lsn[SYNC_REP_WAIT_WRITE] = writePtr;
520  numwrite = SyncRepWakeQueue(false, SYNC_REP_WAIT_WRITE);
521  }
522  if (walsndctl->lsn[SYNC_REP_WAIT_FLUSH] < flushPtr)
523  {
524  walsndctl->lsn[SYNC_REP_WAIT_FLUSH] = flushPtr;
525  numflush = SyncRepWakeQueue(false, SYNC_REP_WAIT_FLUSH);
526  }
527  if (walsndctl->lsn[SYNC_REP_WAIT_APPLY] < applyPtr)
528  {
529  walsndctl->lsn[SYNC_REP_WAIT_APPLY] = applyPtr;
530  numapply = SyncRepWakeQueue(false, SYNC_REP_WAIT_APPLY);
531  }
532 
533  LWLockRelease(SyncRepLock);
534 
535  elog(DEBUG3, "released %d procs up to write %X/%X, %d procs up to flush %X/%X, %d procs up to apply %X/%X",
536  numwrite, LSN_FORMAT_ARGS(writePtr),
537  numflush, LSN_FORMAT_ARGS(flushPtr),
538  numapply, LSN_FORMAT_ARGS(applyPtr));
539 }
static bool SyncRepGetSyncRecPtr(XLogRecPtr *writePtr, XLogRecPtr *flushPtr, XLogRecPtr *applyPtr, bool *am_sync)
Definition: syncrep.c:552
#define DEBUG3
Definition: elog.h:23
#define SYNC_REP_PRIORITY
Definition: syncrep.h:36
uint8 syncrep_method
Definition: syncrep.h:69
WalSndCtlData * WalSndCtl
Definition: walsender.c:109
#define LOG
Definition: elog.h:26
SyncRepConfigData * SyncRepConfig
Definition: syncrep.c:97
static int SyncRepWakeQueue(bool all, int mode)
Definition: syncrep.c:878
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
XLogRecPtr flush
#define SYNC_REP_WAIT_APPLY
Definition: syncrep.h:26
static bool announce_next_takeover
Definition: syncrep.c:95
WalSndState state
#define SYNC_REP_WAIT_FLUSH
Definition: syncrep.h:25
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
WalSnd * MyWalSnd
Definition: walsender.c:112
#define ereport(elevel,...)
Definition: elog.h:157
uint64 XLogRecPtr
Definition: xlogdefs.h:21
int sync_standby_priority
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE]
char * application_name
Definition: guc.c:621
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
#define SYNC_REP_WAIT_WRITE
Definition: syncrep.h:24

◆ SyncRepUpdateSyncStandbysDefined()

void SyncRepUpdateSyncStandbysDefined ( void  )

Definition at line 947 of file syncrep.c.

References Assert, i, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), mode, NUM_SYNC_REP_WAIT_MODE, offsetof, SHMQueueNext(), WalSndCtlData::sync_standbys_defined, PGPROC::syncRepLinks, WalSndCtlData::SyncRepQueue, SyncRepWakeQueue(), SyncStandbysDefined, PGPROC::waitLSN, and WalSndCtl.

Referenced by UpdateSharedMemoryConfig().

948 {
949  bool sync_standbys_defined = SyncStandbysDefined();
950 
951  if (sync_standbys_defined != WalSndCtl->sync_standbys_defined)
952  {
953  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
954 
955  /*
956  * If synchronous_standby_names has been reset to empty, it's futile
957  * for backends to continue waiting. Since the user no longer wants
958  * synchronous replication, we'd better wake them up.
959  */
960  if (!sync_standbys_defined)
961  {
962  int i;
963 
964  for (i = 0; i < NUM_SYNC_REP_WAIT_MODE; i++)
965  SyncRepWakeQueue(true, i);
966  }
967 
968  /*
969  * Only allow people to join the queue when there are synchronous
970  * standbys defined. Without this interlock, there's a race
971  * condition: we might wake up all the current waiters; then, some
972  * backend that hasn't yet reloaded its config might go to sleep on
973  * the queue (and never wake up). This prevents that.
974  */
975  WalSndCtl->sync_standbys_defined = sync_standbys_defined;
976 
977  LWLockRelease(SyncRepLock);
978  }
979 }
WalSndCtlData * WalSndCtl
Definition: walsender.c:109
static int SyncRepWakeQueue(bool all, int mode)
Definition: syncrep.c:878
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
#define SyncStandbysDefined()
Definition: syncrep.c:92
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
int i
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:28

◆ SyncRepWaitForLSN()

void SyncRepWaitForLSN ( XLogRecPtr  lsn,
bool  commit 
)

Definition at line 148 of file syncrep.c.

References Assert, DestNone, ereport, errcode(), errdetail(), errmsg(), get_ps_display(), InterruptHoldoffCount, LSN_FORMAT_ARGS, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), Min, mode, MyLatch, MyProc, palloc(), pfree(), pg_read_barrier, ProcDiePending, QueryCancelPending, ResetLatch(), set_ps_display(), SHMQueueIsDetached(), sprintf, 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, 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().

149 {
150  char *new_status = NULL;
151  const char *old_status;
152  int mode;
153 
154  /*
155  * This should be called while holding interrupts during a transaction
156  * commit to prevent the follow-up shared memory queue cleanups to be
157  * influenced by external interruptions.
158  */
160 
161  /*
162  * Fast exit if user has not requested sync replication, or there are no
163  * sync replication standby names defined.
164  *
165  * Since this routine gets called every commit time, it's important to
166  * exit quickly if sync replication is not requested. So we check
167  * WalSndCtl->sync_standbys_defined flag without the lock and exit
168  * immediately if it's false. If it's true, we need to check it again
169  * later while holding the lock, to check the flag and operate the sync
170  * rep queue atomically. This is necessary to avoid the race condition
171  * described in SyncRepUpdateSyncStandbysDefined(). On the other hand, if
172  * it's false, the lock is not necessary because we don't touch the queue.
173  */
174  if (!SyncRepRequested() ||
175  !((volatile WalSndCtlData *) WalSndCtl)->sync_standbys_defined)
176  return;
177 
178  /* Cap the level for anything other than commit to remote flush only. */
179  if (commit)
180  mode = SyncRepWaitMode;
181  else
183 
185  Assert(WalSndCtl != NULL);
186 
187  LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
189 
190  /*
191  * We don't wait for sync rep if WalSndCtl->sync_standbys_defined is not
192  * set. See SyncRepUpdateSyncStandbysDefined.
193  *
194  * Also check that the standby hasn't already replied. Unlikely race
195  * condition but we'll be fetching that cache line anyway so it's likely
196  * to be a low cost check.
197  */
198  if (!WalSndCtl->sync_standbys_defined ||
199  lsn <= WalSndCtl->lsn[mode])
200  {
201  LWLockRelease(SyncRepLock);
202  return;
203  }
204 
205  /*
206  * Set our waitLSN so WALSender will know when to wake us, and add
207  * ourselves to the queue.
208  */
209  MyProc->waitLSN = lsn;
211  SyncRepQueueInsert(mode);
212  Assert(SyncRepQueueIsOrderedByLSN(mode));
213  LWLockRelease(SyncRepLock);
214 
215  /* Alter ps display to show waiting for sync rep. */
217  {
218  int len;
219 
220  old_status = get_ps_display(&len);
221  new_status = (char *) palloc(len + 32 + 1);
222  memcpy(new_status, old_status, len);
223  sprintf(new_status + len, " waiting for %X/%X",
224  LSN_FORMAT_ARGS(lsn));
225  set_ps_display(new_status);
226  new_status[len] = '\0'; /* truncate off " waiting ..." */
227  }
228 
229  /*
230  * Wait for specified LSN to be confirmed.
231  *
232  * Each proc has its own wait latch, so we perform a normal latch
233  * check/wait loop here.
234  */
235  for (;;)
236  {
237  int rc;
238 
239  /* Must reset the latch before testing state. */
241 
242  /*
243  * Acquiring the lock is not needed, the latch ensures proper
244  * barriers. If it looks like we're done, we must really be done,
245  * because once walsender changes the state to SYNC_REP_WAIT_COMPLETE,
246  * it will never update it again, so we can't be seeing a stale value
247  * in that case.
248  */
250  break;
251 
252  /*
253  * If a wait for synchronous replication is pending, we can neither
254  * acknowledge the commit nor raise ERROR or FATAL. The latter would
255  * lead the client to believe that the transaction aborted, which is
256  * not true: it's already committed locally. The former is no good
257  * either: the client has requested synchronous replication, and is
258  * entitled to assume that an acknowledged commit is also replicated,
259  * which might not be true. So in this case we issue a WARNING (which
260  * some clients may be able to interpret) and shut off further output.
261  * We do NOT reset ProcDiePending, so that the process will die after
262  * the commit is cleaned up.
263  */
264  if (ProcDiePending)
265  {
267  (errcode(ERRCODE_ADMIN_SHUTDOWN),
268  errmsg("canceling the wait for synchronous replication and terminating connection due to administrator command"),
269  errdetail("The transaction has already committed locally, but might not have been replicated to the standby.")));
272  break;
273  }
274 
275  /*
276  * It's unclear what to do if a query cancel interrupt arrives. We
277  * can't actually abort at this point, but ignoring the interrupt
278  * altogether is not helpful, so we just terminate the wait with a
279  * suitable warning.
280  */
281  if (QueryCancelPending)
282  {
283  QueryCancelPending = false;
285  (errmsg("canceling wait for synchronous replication due to user request"),
286  errdetail("The transaction has already committed locally, but might not have been replicated to the standby.")));
288  break;
289  }
290 
291  /*
292  * Wait on latch. Any condition that should wake us up will set the
293  * latch, so no need for timeout.
294  */
297 
298  /*
299  * If the postmaster dies, we'll probably never get an acknowledgment,
300  * because all the wal sender processes will exit. So just bail out.
301  */
302  if (rc & WL_POSTMASTER_DEATH)
303  {
304  ProcDiePending = true;
307  break;
308  }
309  }
310 
311  /*
312  * WalSender has checked our LSN and has removed us from queue. Clean up
313  * state and leave. It's OK to reset these shared memory fields without
314  * holding SyncRepLock, because any walsenders will ignore us anyway when
315  * we're not on the queue. We need a read barrier to make sure we see the
316  * changes to the queue link (this might be unnecessary without
317  * assertions, but better safe than sorry).
318  */
319  pg_read_barrier();
322  MyProc->waitLSN = 0;
323 
324  if (new_status)
325  {
326  /* Reset ps display */
327  set_ps_display(new_status);
328  pfree(new_status);
329  }
330 }
static PgChecksumMode mode
Definition: pg_checksums.c:65
volatile uint32 InterruptHoldoffCount
Definition: globals.c:39
static void SyncRepCancelWait(void)
Definition: syncrep.c:372
volatile sig_atomic_t QueryCancelPending
Definition: globals.c:31
bool update_process_title
Definition: ps_status.c:36
static void SyncRepQueueInsert(int mode)
Definition: syncrep.c:339
PGPROC * MyProc
Definition: proc.c:68
#define SYNC_REP_WAITING
Definition: syncrep.h:32
#define Min(x, y)
Definition: c.h:986
#define SYNC_REP_NOT_WAITING
Definition: syncrep.h:31
WalSndCtlData * WalSndCtl
Definition: walsender.c:109
int errcode(int sqlerrcode)
Definition: elog.c:698
void ResetLatch(Latch *latch)
Definition: latch.c:660
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition: latch.c:452
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
void set_ps_display(const char *activity)
Definition: ps_status.c:349
#define sprintf
Definition: port.h:219
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
void pfree(void *pointer)
Definition: mcxt.c:1169
Definition: dest.h:89
const char * get_ps_display(int *displen)
Definition: ps_status.c:430
int errdetail(const char *fmt,...)
Definition: elog.c:1042
#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:129
#define ereport(elevel,...)
Definition: elog.h:157
#define SYNC_REP_WAIT_COMPLETE
Definition: syncrep.h:33
#define Assert(condition)
Definition: c.h:804
volatile sig_atomic_t ProcDiePending
Definition: globals.c:32
#define pg_read_barrier()
Definition: atomics.h:158
bool SHMQueueIsDetached(const SHM_QUEUE *queue)
Definition: shmqueue.c:47
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
SHM_QUEUE syncRepLinks
Definition: proc.h:201
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
struct Latch * MyLatch
Definition: globals.c:57
int syncRepState
Definition: proc.h:200
CommandDest whereToSendOutput
Definition: postgres.c:92
static int SyncRepWaitMode
Definition: syncrep.c:98
#define WL_LATCH_SET
Definition: latch.h:125
XLogRecPtr waitLSN
Definition: proc.h:199

◆ SyncRepWakeQueue()

static int SyncRepWakeQueue ( bool  all,
int  mode 
)
static

Definition at line 878 of file syncrep.c.

References Assert, WalSndCtlData::lsn, LW_EXCLUSIVE, LWLockHeldByMeInMode(), mode, NUM_SYNC_REP_WAIT_MODE, offsetof, pg_write_barrier, PGPROC::procLatch, SetLatch(), SHMQueueDelete(), SHMQueueNext(), SYNC_REP_WAIT_COMPLETE, PGPROC::syncRepLinks, WalSndCtlData::SyncRepQueue, PGPROC::syncRepState, PGPROC::waitLSN, and WalSndCtl.

Referenced by SyncRepReleaseWaiters(), and SyncRepUpdateSyncStandbysDefined().

879 {
880  volatile WalSndCtlData *walsndctl = WalSndCtl;
881  PGPROC *proc = NULL;
882  PGPROC *thisproc = NULL;
883  int numprocs = 0;
884 
887  Assert(SyncRepQueueIsOrderedByLSN(mode));
888 
891  offsetof(PGPROC, syncRepLinks));
892 
893  while (proc)
894  {
895  /*
896  * Assume the queue is ordered by LSN
897  */
898  if (!all && walsndctl->lsn[mode] < proc->waitLSN)
899  return numprocs;
900 
901  /*
902  * Move to next proc, so we can delete thisproc from the queue.
903  * thisproc is valid, proc may be NULL after this.
904  */
905  thisproc = proc;
907  &(proc->syncRepLinks),
908  offsetof(PGPROC, syncRepLinks));
909 
910  /*
911  * Remove thisproc from queue.
912  */
913  SHMQueueDelete(&(thisproc->syncRepLinks));
914 
915  /*
916  * SyncRepWaitForLSN() reads syncRepState without holding the lock, so
917  * make sure that it sees the queue link being removed before the
918  * syncRepState change.
919  */
921 
922  /*
923  * Set state to complete; see SyncRepWaitForLSN() for discussion of
924  * the various states.
925  */
927 
928  /*
929  * Wake only when we have set state and removed from queue.
930  */
931  SetLatch(&(thisproc->procLatch));
932 
933  numprocs++;
934  }
935 
936  return numprocs;
937 }
static PgChecksumMode mode
Definition: pg_checksums.c:65
bool LWLockHeldByMeInMode(LWLock *l, LWLockMode mode)
Definition: lwlock.c:1937
WalSndCtlData * WalSndCtl
Definition: walsender.c:109
void SetLatch(Latch *latch)
Definition: latch.c:567
Latch procLatch
Definition: proc.h:130
SHM_QUEUE SyncRepQueue[NUM_SYNC_REP_WAIT_MODE]
Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem, Size linkOffset)
Definition: shmqueue.c:145
#define SYNC_REP_WAIT_COMPLETE
Definition: syncrep.h:33
#define Assert(condition)
Definition: c.h:804
SHM_QUEUE syncRepLinks
Definition: proc.h:201
XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE]
#define pg_write_barrier()
Definition: atomics.h:159
void SHMQueueDelete(SHM_QUEUE *queue)
Definition: shmqueue.c:68
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:28
int syncRepState
Definition: proc.h:200
Definition: proc.h:121
XLogRecPtr waitLSN
Definition: proc.h:199
#define offsetof(type, field)
Definition: c.h:727

Variable Documentation

◆ announce_next_takeover

bool announce_next_takeover = true
static

Definition at line 95 of file syncrep.c.

Referenced by SyncRepReleaseWaiters().

◆ SyncRepConfig

SyncRepConfigData* SyncRepConfig = NULL

Definition at line 97 of file syncrep.c.

Referenced by pg_stat_get_wal_senders().

◆ SyncRepStandbyNames

char* SyncRepStandbyNames

Definition at line 90 of file syncrep.c.

◆ SyncRepWaitMode

int SyncRepWaitMode = SYNC_REP_NO_WAIT
static

Definition at line 98 of file syncrep.c.

Referenced by assign_synchronous_commit(), and SyncRepWaitForLSN().