check-return-code-for-postmaster-death.patch
application/octet-stream
Filename: check-return-code-for-postmaster-death.patch
Type: application/octet-stream
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/postmaster/pgarch.c | 3 | 1 |
| src/backend/replication/syncrep.c | 9 | 7 |
| src/backend/replication/walreceiver.c | 6 | 8 |
| src/backend/replication/walsender.c | 18 | 27 |
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 1aa6466..00d0808 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -393,6 +393,8 @@ pgarch_MainLoop(void)
timeout * 1000L);
if (rc & WL_TIMEOUT)
wakened = true;
+ if (rc & WL_POSTMASTER_DEATH)
+ time_to_stop = true;
}
else
wakened = true;
@@ -403,7 +405,7 @@ pgarch_MainLoop(void)
* or after completing one more archiving cycle after receiving
* SIGUSR2.
*/
- } while (PostmasterIsAlive() && !time_to_stop);
+ } while (!time_to_stop);
}
/*
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index b442d06..6e10f6e 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -189,6 +189,8 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
*/
for (;;)
{
+ int rc;
+
/* Must reset the latch before testing state. */
ResetLatch(MyLatch);
@@ -242,23 +244,23 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
}
/*
+ * Wait on latch. Any condition that should wake us up will set the
+ * latch, so no need for timeout.
+ */
+ rc = WaitLatch(MyLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, -1);
+
+ /*
* If the postmaster dies, we'll probably never get an
* acknowledgement, because all the wal sender processes will exit. So
* just bail out.
*/
- if (!PostmasterIsAlive())
+ if (rc & WL_POSTMASTER_DEATH)
{
ProcDiePending = true;
whereToSendOutput = DestNone;
SyncRepCancelWait();
break;
}
-
- /*
- * Wait on latch. Any condition that should wake us up will set the
- * latch, so no need for timeout.
- */
- WaitLatch(MyLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, -1);
}
/*
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 413ee3a..6c5714a 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -650,14 +650,9 @@ WalRcvWaitForStartPosition(XLogRecPtr *startpoint, TimeLineID *startpointTLI)
WakeupRecovery();
for (;;)
{
- ResetLatch(&walrcv->latch);
+ int rc;
- /*
- * Emergency bailout if postmaster has died. This is to avoid the
- * necessity for manual cleanup of all postmaster children.
- */
- if (!PostmasterIsAlive())
- exit(1);
+ ResetLatch(&walrcv->latch);
ProcessWalRcvInterrupts();
@@ -685,7 +680,10 @@ WalRcvWaitForStartPosition(XLogRecPtr *startpoint, TimeLineID *startpointTLI)
}
SpinLockRelease(&walrcv->mutex);
- WaitLatch(&walrcv->latch, WL_LATCH_SET | WL_POSTMASTER_DEATH, 0);
+ rc = WaitLatch(&walrcv->latch, WL_LATCH_SET | WL_POSTMASTER_DEATH, 0);
+
+ if (rc & WL_POSTMASTER_DEATH)
+ exit(1);
}
if (update_process_title)
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index c7743da..751d75d 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1096,17 +1096,11 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
for (;;)
{
+ int rc;
int wakeEvents;
long sleeptime;
TimestampTz now;
- /*
- * Emergency bailout if postmaster has died. This is to avoid the
- * necessity for manual cleanup of all postmaster children.
- */
- if (!PostmasterIsAlive())
- exit(1);
-
/* Clear any already-pending wakeups */
ResetLatch(MyLatch);
@@ -1145,8 +1139,11 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
WL_SOCKET_WRITEABLE | WL_SOCKET_READABLE | WL_TIMEOUT;
/* Sleep until something happens or we time out */
- WaitLatchOrSocket(MyLatch, wakeEvents,
- MyProcPort->sock, sleeptime);
+ rc = WaitLatchOrSocket(MyLatch, wakeEvents,
+ MyProcPort->sock, sleeptime);
+
+ if (rc & WL_POSTMASTER_DEATH)
+ exit(1);
}
/* reactivate latch so WalSndLoop knows to continue */
@@ -1180,16 +1177,10 @@ WalSndWaitForWal(XLogRecPtr loc)
for (;;)
{
+ int rc;
long sleeptime;
TimestampTz now;
- /*
- * Emergency bailout if postmaster has died. This is to avoid the
- * necessity for manual cleanup of all postmaster children.
- */
- if (!PostmasterIsAlive())
- exit(1);
-
/* Clear any already-pending wakeups */
ResetLatch(MyLatch);
@@ -1271,8 +1262,11 @@ WalSndWaitForWal(XLogRecPtr loc)
wakeEvents |= WL_SOCKET_WRITEABLE;
/* Sleep until something happens or we time out */
- WaitLatchOrSocket(MyLatch, wakeEvents,
- MyProcPort->sock, sleeptime);
+ rc = WaitLatchOrSocket(MyLatch, wakeEvents,
+ MyProcPort->sock, sleeptime);
+
+ if (rc & WL_POSTMASTER_DEATH)
+ exit(1);
}
/* reactivate latch so WalSndLoop knows to continue */
@@ -1817,13 +1811,6 @@ WalSndLoop(WalSndSendDataCallback send_data)
{
TimestampTz now;
- /*
- * Emergency bailout if postmaster has died. This is to avoid the
- * necessity for manual cleanup of all postmaster children.
- */
- if (!PostmasterIsAlive())
- exit(1);
-
/* Clear any already-pending wakeups */
ResetLatch(MyLatch);
@@ -1911,6 +1898,7 @@ WalSndLoop(WalSndSendDataCallback send_data)
*/
if ((WalSndCaughtUp && !streamingDoneSending) || pq_is_send_pending())
{
+ int rc;
long sleeptime;
int wakeEvents;
@@ -1923,8 +1911,11 @@ WalSndLoop(WalSndSendDataCallback send_data)
wakeEvents |= WL_SOCKET_WRITEABLE;
/* Sleep until something happens or we time out */
- WaitLatchOrSocket(MyLatch, wakeEvents,
- MyProcPort->sock, sleeptime);
+ rc = WaitLatchOrSocket(MyLatch, wakeEvents,
+ MyProcPort->sock, sleeptime);
+
+ if (rc & WL_POSTMASTER_DEATH)
+ exit(1);
}
}
return;