Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c48f5d

Browse files
committed
Use standard interrupt handling in logical replication launcher.
Previously the exit handling was only able to exit from within themain loop, and not from within the backend code it calls. Fix that byusing the standard die() SIGTERM handler, and adding the necessaryCHECK_FOR_INTERRUPTS() call.This requires adding yet another process-type-specific branch toProcessInterrupts(), which hints that we probably should generalizethat handling. But that's work for another day.Author: Petr JelinekReviewed-By: Andres FreundDiscussion:https://postgr.es/m/fe072153-babd-3b5d-8052-73527a6eb657@2ndquadrant.com
1 parent5fd56b9 commit2c48f5d

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

‎src/backend/replication/logical/launcher.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static void logicalrep_worker_cleanup(LogicalRepWorker *worker);
8181

8282
/* Flags set by signal handlers */
8383
staticvolatilesig_atomic_tgot_SIGHUP= false;
84-
staticvolatilesig_atomic_tgot_SIGTERM= false;
8584

8685
staticboolon_commit_launcher_wakeup= false;
8786

@@ -634,20 +633,6 @@ logicalrep_worker_onexit(int code, Datum arg)
634633
ApplyLauncherWakeup();
635634
}
636635

637-
/* SIGTERM: set flag to exit at next convenient time */
638-
staticvoid
639-
logicalrep_launcher_sigterm(SIGNAL_ARGS)
640-
{
641-
intsave_errno=errno;
642-
643-
got_SIGTERM= true;
644-
645-
/* Waken anything waiting on the process latch */
646-
SetLatch(MyLatch);
647-
648-
errno=save_errno;
649-
}
650-
651636
/* SIGHUP: set flag to reload configuration at next convenient time */
652637
staticvoid
653638
logicalrep_launcher_sighup(SIGNAL_ARGS)
@@ -809,21 +794,22 @@ ApplyLauncherMain(Datum main_arg)
809794

810795
before_shmem_exit(logicalrep_launcher_onexit, (Datum)0);
811796

797+
Assert(LogicalRepCtx->launcher_pid==0);
798+
LogicalRepCtx->launcher_pid=MyProcPid;
799+
812800
/* Establish signal handlers. */
813801
pqsignal(SIGHUP,logicalrep_launcher_sighup);
814-
pqsignal(SIGTERM,logicalrep_launcher_sigterm);
802+
pqsignal(SIGTERM,die);
815803
BackgroundWorkerUnblockSignals();
816804

817-
LogicalRepCtx->launcher_pid=MyProcPid;
818-
819805
/*
820806
* Establish connection to nailed catalogs (we only ever access
821807
* pg_subscription).
822808
*/
823809
BackgroundWorkerInitializeConnection(NULL,NULL);
824810

825811
/* Enter main loop */
826-
while (!got_SIGTERM)
812+
for (;;)
827813
{
828814
intrc;
829815
List*sublist;
@@ -833,6 +819,8 @@ ApplyLauncherMain(Datum main_arg)
833819
TimestampTznow;
834820
longwait_time=DEFAULT_NAPTIME_PER_CYCLE;
835821

822+
CHECK_FOR_INTERRUPTS();
823+
836824
now=GetCurrentTimestamp();
837825

838826
/* Limit the start retry to once a wal_retrieve_retry_interval */
@@ -909,13 +897,16 @@ ApplyLauncherMain(Datum main_arg)
909897
}
910898
}
911899

912-
LogicalRepCtx->launcher_pid=0;
913-
914-
/* ... and if it returns, we're done */
915-
ereport(DEBUG1,
916-
(errmsg("logical replication launcher shutting down")));
900+
/* Not reachable */
901+
}
917902

918-
proc_exit(0);
903+
/*
904+
* Is current process the logical replication launcher?
905+
*/
906+
bool
907+
IsLogicalLauncher(void)
908+
{
909+
returnLogicalRepCtx->launcher_pid==MyProcPid;
919910
}
920911

921912
/*

‎src/backend/tcop/postgres.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include"pg_getopt.h"
5656
#include"postmaster/autovacuum.h"
5757
#include"postmaster/postmaster.h"
58+
#include"replication/logicallauncher.h"
5859
#include"replication/logicalworker.h"
5960
#include"replication/slot.h"
6061
#include"replication/walsender.h"
@@ -2848,6 +2849,14 @@ ProcessInterrupts(void)
28482849
ereport(FATAL,
28492850
(errcode(ERRCODE_ADMIN_SHUTDOWN),
28502851
errmsg("terminating logical replication worker due to administrator command")));
2852+
elseif (IsLogicalLauncher())
2853+
{
2854+
ereport(DEBUG1,
2855+
(errmsg("logical replication launcher shutting down")));
2856+
2857+
/* The logical replication launcher can be stopped at any time. */
2858+
proc_exit(0);
2859+
}
28512860
elseif (RecoveryConflictPending&&RecoveryConflictRetryable)
28522861
{
28532862
pgstat_report_recovery_conflict(RecoveryConflictReason);

‎src/include/replication/logicallauncher.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ extern void ApplyLauncherShmemInit(void);
2424
externvoidApplyLauncherWakeupAtCommit(void);
2525
externvoidAtEOXact_ApplyLauncher(boolisCommit);
2626

27+
externboolIsLogicalLauncher(void);
28+
2729
#endif/* LOGICALLAUNCHER_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp