Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 82bd7c7

Browse files
hlinnakaCommitfest Bot
authored and
Commitfest Bot
committed
Apply walrcv_shutdown_deblocking_v2-2.patch
From https://www.postgresql.org/message-id/20240123.172410.1596193222420636986.horikyota.ntt%40gmail.com Plus couple of fixes from review: - use of AmWalReceiverProcess - use of die
1 parent 279a908 commit 82bd7c7

File tree

3 files changed

+12
-38
lines changed

3 files changed

+12
-38
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ libpqrcv_PQgetResult(PGconn *streamConn)
823823
if (rc & WL_LATCH_SET)
824824
{
825825
ResetLatch(MyLatch);
826-
ProcessWalRcvInterrupts();
826+
CHECK_FOR_INTERRUPTS();
827827
}
828828

829829
/* Consume whatever data is available from the socket */
@@ -1175,7 +1175,7 @@ libpqrcv_processTuples(PGresult *pgres, WalRcvExecResult *walres,
11751175
{
11761176
char *cstrs[MaxTupleAttributeNumber];
11771177

1178-
ProcessWalRcvInterrupts();
1178+
CHECK_FOR_INTERRUPTS();
11791179

11801180
/* Do the allocations in temporary context. */
11811181
oldcontext = MemoryContextSwitchTo(rowcontext);

src/backend/replication/walreceiver.c

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "storage/proc.h"
7272
#include "storage/procarray.h"
7373
#include "storage/procsignal.h"
74+
#include "tcop/tcopprot.h"
7475
#include "utils/acl.h"
7576
#include "utils/builtins.h"
7677
#include "utils/guc.h"
@@ -145,38 +146,6 @@ static void XLogWalRcvSendHSFeedback(bool immed);
145146
static void ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime);
146147
static void WalRcvComputeNextWakeup(WalRcvWakeupReason reason, TimestampTz now);
147148

148-
/*
149-
* Process any interrupts the walreceiver process may have received.
150-
* This should be called any time the process's latch has become set.
151-
*
152-
* Currently, only SIGTERM is of interest. We can't just exit(1) within the
153-
* SIGTERM signal handler, because the signal might arrive in the middle of
154-
* some critical operation, like while we're holding a spinlock. Instead, the
155-
* signal handler sets a flag variable as well as setting the process's latch.
156-
* We must check the flag (by calling ProcessWalRcvInterrupts) anytime the
157-
* latch has become set. Operations that could block for a long time, such as
158-
* reading from a remote server, must pay attention to the latch too; see
159-
* libpqrcv_PQgetResult for example.
160-
*/
161-
void
162-
ProcessWalRcvInterrupts(void)
163-
{
164-
/*
165-
* Although walreceiver interrupt handling doesn't use the same scheme as
166-
* regular backends, call CHECK_FOR_INTERRUPTS() to make sure we receive
167-
* any incoming signals on Win32, and also to make sure we process any
168-
* barrier events.
169-
*/
170-
CHECK_FOR_INTERRUPTS();
171-
172-
if (ShutdownRequestPending)
173-
{
174-
ereport(FATAL,
175-
(errcode(ERRCODE_ADMIN_SHUTDOWN),
176-
errmsg("terminating walreceiver process due to administrator command")));
177-
}
178-
}
179-
180149

181150
/* Main entry point for walreceiver process */
182151
void
@@ -280,7 +249,7 @@ WalReceiverMain(const void *startup_data, size_t startup_data_len)
280249
pqsignal(SIGHUP, SignalHandlerForConfigReload); /* set flag to read config
281250
* file */
282251
pqsignal(SIGINT, SIG_IGN);
283-
pqsignal(SIGTERM, SignalHandlerForShutdownRequest); /* request shutdown */
252+
pqsignal(SIGTERM, die); /* request shutdown */
284253
/* SIGQUIT handler was already set up by InitPostmasterChild */
285254
pqsignal(SIGALRM, SIG_IGN);
286255
pqsignal(SIGPIPE, SIG_IGN);
@@ -459,7 +428,7 @@ WalReceiverMain(const void *startup_data, size_t startup_data_len)
459428
errmsg("cannot continue WAL streaming, recovery has already ended")));
460429

461430
/* Process any requests or signals received recently */
462-
ProcessWalRcvInterrupts();
431+
CHECK_FOR_INTERRUPTS();
463432

464433
if (ConfigReloadPending)
465434
{
@@ -555,7 +524,7 @@ WalReceiverMain(const void *startup_data, size_t startup_data_len)
555524
if (rc & WL_LATCH_SET)
556525
{
557526
ResetLatch(MyLatch);
558-
ProcessWalRcvInterrupts();
527+
CHECK_FOR_INTERRUPTS();
559528

560529
if (walrcv->force_reply)
561530
{
@@ -704,7 +673,7 @@ WalRcvWaitForStartPosition(XLogRecPtr *startpoint, TimeLineID *startpointTLI)
704673
{
705674
ResetLatch(MyLatch);
706675

707-
ProcessWalRcvInterrupts();
676+
CHECK_FOR_INTERRUPTS();
708677

709678
SpinLockAcquire(&walrcv->mutex);
710679
Assert(walrcv->walRcvState == WALRCV_RESTARTING ||

src/backend/tcop/postgres.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "replication/logicallauncher.h"
5959
#include "replication/logicalworker.h"
6060
#include "replication/slot.h"
61+
#include "replication/walreceiver.h"
6162
#include "replication/walsender.h"
6263
#include "rewrite/rewriteHandler.h"
6364
#include "storage/bufmgr.h"
@@ -3335,6 +3336,10 @@ ProcessInterrupts(void)
33353336
*/
33363337
proc_exit(1);
33373338
}
3339+
else if (AmWalReceiverProcess())
3340+
ereport(FATAL,
3341+
(errcode(ERRCODE_ADMIN_SHUTDOWN),
3342+
errmsg("terminating walreceiver process due to administrator command")));
33383343
else if (AmBackgroundWorkerProcess())
33393344
ereport(FATAL,
33403345
(errcode(ERRCODE_ADMIN_SHUTDOWN),

0 commit comments

Comments
 (0)