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

Commit9aceb6a

Browse files
Refactor xlog.c to create src/backend/postmaster/startup.c
Startup process now has its own dedicated file, just like all otherspecial/background processes. Reduces role and size of xlog.c
1 parent86e3364 commit9aceb6a

File tree

7 files changed

+291
-197
lines changed

7 files changed

+291
-197
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 6 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include"miscadmin.h"
4242
#include"pgstat.h"
4343
#include"postmaster/bgwriter.h"
44+
#include"postmaster/startup.h"
4445
#include"replication/walreceiver.h"
4546
#include"replication/walsender.h"
4647
#include"storage/bufmgr.h"
@@ -584,19 +585,6 @@ typedef struct xl_restore_point
584585
charrp_name[MAXFNAMELEN];
585586
}xl_restore_point;
586587

587-
/*
588-
* Flags set by interrupt handlers for later service in the redo loop.
589-
*/
590-
staticvolatilesig_atomic_tgot_SIGHUP= false;
591-
staticvolatilesig_atomic_tshutdown_requested= false;
592-
staticvolatilesig_atomic_tpromote_triggered= false;
593-
594-
/*
595-
* Flag set when executing a restore command, to tell SIGTERM signal handler
596-
* that it's safe to just proc_exit.
597-
*/
598-
staticvolatilesig_atomic_tin_restore_command= false;
599-
600588

601589
staticvoidXLogArchiveNotify(constchar*xlog);
602590
staticvoidXLogArchiveNotifySeg(uint32log,uint32seg);
@@ -3068,21 +3056,16 @@ RestoreArchivedFile(char *path, const char *xlogfname,
30683056
xlogRestoreCmd)));
30693057

30703058
/*
3071-
* Set in_restore_command to tell the signal handler that we should exit
3072-
* right away on SIGTERM. We know that we're at a safe point to do that.
3073-
* Check if we had already received the signal, so that we don't miss a
3074-
* shutdown request received just before this.
3059+
* Check signals before restore command and reset afterwards.
30753060
*/
3076-
in_restore_command= true;
3077-
if (shutdown_requested)
3078-
proc_exit(1);
3061+
PreRestoreCommand();
30793062

30803063
/*
30813064
* Copy xlog from archival storage to XLOGDIR
30823065
*/
30833066
rc=system(xlogRestoreCmd);
30843067

3085-
in_restore_command= false;
3068+
PostRestoreCommand();
30863069

30873070
if (rc==0)
30883071
{
@@ -9946,177 +9929,6 @@ CancelBackup(void)
99469929
}
99479930
}
99489931

9949-
/* ------------------------------------------------------
9950-
*Startup Process main entry point and signal handlers
9951-
* ------------------------------------------------------
9952-
*/
9953-
9954-
/*
9955-
* startupproc_quickdie() occurs when signalled SIGQUIT by the postmaster.
9956-
*
9957-
* Some backend has bought the farm,
9958-
* so we need to stop what we're doing and exit.
9959-
*/
9960-
staticvoid
9961-
startupproc_quickdie(SIGNAL_ARGS)
9962-
{
9963-
PG_SETMASK(&BlockSig);
9964-
9965-
/*
9966-
* We DO NOT want to run proc_exit() callbacks -- we're here because
9967-
* shared memory may be corrupted, so we don't want to try to clean up our
9968-
* transaction. Just nail the windows shut and get out of town. Now that
9969-
* there's an atexit callback to prevent third-party code from breaking
9970-
* things by calling exit() directly, we have to reset the callbacks
9971-
* explicitly to make this work as intended.
9972-
*/
9973-
on_exit_reset();
9974-
9975-
/*
9976-
* Note we do exit(2) not exit(0).This is to force the postmaster into a
9977-
* system reset cycle if some idiot DBA sends a manual SIGQUIT to a random
9978-
* backend. This is necessary precisely because we don't clean up our
9979-
* shared memory state. (The "dead man switch" mechanism in pmsignal.c
9980-
* should ensure the postmaster sees this as a crash, too, but no harm in
9981-
* being doubly sure.)
9982-
*/
9983-
exit(2);
9984-
}
9985-
9986-
9987-
/* SIGUSR1: let latch facility handle the signal */
9988-
staticvoid
9989-
StartupProcSigUsr1Handler(SIGNAL_ARGS)
9990-
{
9991-
intsave_errno=errno;
9992-
9993-
latch_sigusr1_handler();
9994-
9995-
errno=save_errno;
9996-
}
9997-
9998-
/* SIGUSR2: set flag to finish recovery */
9999-
staticvoid
10000-
StartupProcTriggerHandler(SIGNAL_ARGS)
10001-
{
10002-
intsave_errno=errno;
10003-
10004-
promote_triggered= true;
10005-
WakeupRecovery();
10006-
10007-
errno=save_errno;
10008-
}
10009-
10010-
/* SIGHUP: set flag to re-read config file at next convenient time */
10011-
staticvoid
10012-
StartupProcSigHupHandler(SIGNAL_ARGS)
10013-
{
10014-
intsave_errno=errno;
10015-
10016-
got_SIGHUP= true;
10017-
WakeupRecovery();
10018-
10019-
errno=save_errno;
10020-
}
10021-
10022-
/* SIGTERM: set flag to abort redo and exit */
10023-
staticvoid
10024-
StartupProcShutdownHandler(SIGNAL_ARGS)
10025-
{
10026-
intsave_errno=errno;
10027-
10028-
if (in_restore_command)
10029-
proc_exit(1);
10030-
else
10031-
shutdown_requested= true;
10032-
WakeupRecovery();
10033-
10034-
errno=save_errno;
10035-
}
10036-
10037-
/* Handle SIGHUP and SIGTERM signals of startup process */
10038-
void
10039-
HandleStartupProcInterrupts(void)
10040-
{
10041-
/*
10042-
* Check if we were requested to re-read config file.
10043-
*/
10044-
if (got_SIGHUP)
10045-
{
10046-
got_SIGHUP= false;
10047-
ProcessConfigFile(PGC_SIGHUP);
10048-
}
10049-
10050-
/*
10051-
* Check if we were requested to exit without finishing recovery.
10052-
*/
10053-
if (shutdown_requested)
10054-
proc_exit(1);
10055-
10056-
/*
10057-
* Emergency bailout if postmaster has died. This is to avoid the
10058-
* necessity for manual cleanup of all postmaster children.
10059-
*/
10060-
if (IsUnderPostmaster&& !PostmasterIsAlive())
10061-
exit(1);
10062-
}
10063-
10064-
/* Main entry point for startup process */
10065-
void
10066-
StartupProcessMain(void)
10067-
{
10068-
/*
10069-
* If possible, make this process a group leader, so that the postmaster
10070-
* can signal any child processes too.
10071-
*/
10072-
#ifdefHAVE_SETSID
10073-
if (setsid()<0)
10074-
elog(FATAL,"setsid() failed: %m");
10075-
#endif
10076-
10077-
/*
10078-
* Properly accept or ignore signals the postmaster might send us.
10079-
*
10080-
* Note: ideally we'd not enable handle_standby_sig_alarm unless actually
10081-
* doing hot standby, but we don't know that yet. Rely on it to not do
10082-
* anything if it shouldn't.
10083-
*/
10084-
pqsignal(SIGHUP,StartupProcSigHupHandler);/* reload config file */
10085-
pqsignal(SIGINT,SIG_IGN);/* ignore query cancel */
10086-
pqsignal(SIGTERM,StartupProcShutdownHandler);/* request shutdown */
10087-
pqsignal(SIGQUIT,startupproc_quickdie);/* hard crash time */
10088-
if (EnableHotStandby)
10089-
pqsignal(SIGALRM,handle_standby_sig_alarm);/* ignored unless
10090-
* InHotStandby */
10091-
else
10092-
pqsignal(SIGALRM,SIG_IGN);
10093-
pqsignal(SIGPIPE,SIG_IGN);
10094-
pqsignal(SIGUSR1,StartupProcSigUsr1Handler);
10095-
pqsignal(SIGUSR2,StartupProcTriggerHandler);
10096-
10097-
/*
10098-
* Reset some signals that are accepted by postmaster but not here
10099-
*/
10100-
pqsignal(SIGCHLD,SIG_DFL);
10101-
pqsignal(SIGTTIN,SIG_DFL);
10102-
pqsignal(SIGTTOU,SIG_DFL);
10103-
pqsignal(SIGCONT,SIG_DFL);
10104-
pqsignal(SIGWINCH,SIG_DFL);
10105-
10106-
/*
10107-
* Unblock signals (they were blocked when the postmaster forked us)
10108-
*/
10109-
PG_SETMASK(&UnBlockSig);
10110-
10111-
StartupXLOG();
10112-
10113-
/*
10114-
* Exit normally. Exit code 0 tells postmaster that we completed recovery
10115-
* successfully.
10116-
*/
10117-
proc_exit(0);
10118-
}
10119-
101209932
/*
101219933
* Read the XLOG page containing RecPtr into readBuf (if not read already).
101229934
* Returns true if the page is read successfully.
@@ -10564,12 +10376,12 @@ CheckForStandbyTrigger(void)
1056410376
if (triggered)
1056510377
return true;
1056610378

10567-
if (promote_triggered)
10379+
if (IsPromoteTriggered())
1056810380
{
1056910381
ereport(LOG,
1057010382
(errmsg("received promote request")));
1057110383
ShutdownWalRcv();
10572-
promote_triggered= false;
10384+
ResetPromoteTriggered();
1057310385
triggered= true;
1057410386
return true;
1057510387
}

‎src/backend/bootstrap/bootstrap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include"miscadmin.h"
3030
#include"nodes/makefuncs.h"
3131
#include"postmaster/bgwriter.h"
32+
#include"postmaster/startup.h"
3233
#include"postmaster/walwriter.h"
3334
#include"replication/walreceiver.h"
3435
#include"storage/bufmgr.h"

‎src/backend/postmaster/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ top_builddir = ../../..
1313
include$(top_builddir)/src/Makefile.global
1414

1515
OBJS = autovacuum.o bgwriter.o fork_process.o pgarch.o pgstat.o postmaster.o\
16-
syslogger.o walwriter.o checkpointer.o
16+
startup.osyslogger.o walwriter.o checkpointer.o
1717

1818
include$(top_srcdir)/src/backend/common.mk

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp