aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/replication')
-rw-r--r--src/backend/replication/syncrep.c20
-rw-r--r--src/backend/replication/walreceiver.c4
-rw-r--r--src/backend/replication/walsender.c16
3 files changed, 26 insertions, 14 deletions
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 7d7f340274b..56deeeb7a19 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -111,9 +111,6 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
Assert(SHMQueueIsDetached(&(MyProc->syncRepLinks)));
Assert(WalSndCtl != NULL);
- /* Reset the latch before adding ourselves to the queue. */
- ResetLatch(&MyProc->waitLatch);
-
LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
Assert(MyProc->syncRepState == SYNC_REP_NOT_WAITING);
@@ -167,7 +164,7 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
int syncRepState;
/* Must reset the latch before testing state. */
- ResetLatch(&MyProc->waitLatch);
+ ResetLatch(&MyProc->procLatch);
/*
* Try checking the state without the lock first. There's no
@@ -247,11 +244,10 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
}
/*
- * Wait on latch for up to 60 seconds. This allows us to check for
- * cancel/die signal or postmaster death regularly while waiting. Note
- * that timeout here does not necessarily release from loop.
+ * Wait on latch. Any condition that should wake us up will set
+ * the latch, so no need for timeout.
*/
- WaitLatch(&MyProc->waitLatch, WL_LATCH_SET | WL_TIMEOUT, 60000L);
+ WaitLatch(&MyProc->procLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, -1);
}
/*
@@ -322,7 +318,7 @@ SyncRepCancelWait(void)
}
void
-SyncRepCleanupAtProcExit(int code, Datum arg)
+SyncRepCleanupAtProcExit(void)
{
if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
{
@@ -330,8 +326,6 @@ SyncRepCleanupAtProcExit(int code, Datum arg)
SHMQueueDelete(&(MyProc->syncRepLinks));
LWLockRelease(SyncRepLock);
}
-
- DisownLatch(&MyProc->waitLatch);
}
/*
@@ -567,9 +561,7 @@ SyncRepWakeQueue(bool all)
/*
* Wake only when we have set state and removed from queue.
*/
- Assert(SHMQueueIsDetached(&(thisproc->syncRepLinks)));
- Assert(thisproc->syncRepState == SYNC_REP_WAIT_COMPLETE);
- SetLatch(&(thisproc->waitLatch));
+ SetLatch(&(thisproc->procLatch));
numprocs++;
}
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index c24fa87394d..b4ece49a109 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -374,11 +374,15 @@ WalRcvSigHupHandler(SIGNAL_ARGS)
static void
WalRcvShutdownHandler(SIGNAL_ARGS)
{
+ int save_errno = errno;
+
got_SIGTERM = true;
/* Don't joggle the elbow of proc_exit */
if (!proc_exit_inprogress && WalRcvImmediateInterruptOK)
ProcessWalRcvInterrupts();
+
+ errno = save_errno;
}
/*
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 27577529eb3..723d5283304 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1249,18 +1249,26 @@ WalSndRqstFileReload(void)
static void
WalSndSigHupHandler(SIGNAL_ARGS)
{
+ int save_errno = errno;
+
got_SIGHUP = true;
if (MyWalSnd)
SetLatch(&MyWalSnd->latch);
+
+ errno = save_errno;
}
/* SIGTERM: set flag to shut down */
static void
WalSndShutdownHandler(SIGNAL_ARGS)
{
+ int save_errno = errno;
+
walsender_shutdown_requested = true;
if (MyWalSnd)
SetLatch(&MyWalSnd->latch);
+
+ errno = save_errno;
}
/*
@@ -1299,16 +1307,24 @@ WalSndQuickDieHandler(SIGNAL_ARGS)
static void
WalSndXLogSendHandler(SIGNAL_ARGS)
{
+ int save_errno = errno;
+
latch_sigusr1_handler();
+
+ errno = save_errno;
}
/* SIGUSR2: set flag to do a last cycle and shut down afterwards */
static void
WalSndLastCycleHandler(SIGNAL_ARGS)
{
+ int save_errno = errno;
+
walsender_ready_to_stop = true;
if (MyWalSnd)
SetLatch(&MyWalSnd->latch);
+
+ errno = save_errno;
}
/* Set up signal handlers */