Skip to content

Commit 0a69210

Browse files
committed
process startup: Move AuxiliaryProcessMain into its own file.
After the preceding commits the auxprocess code is independent from bootstrap.c - so a dedicated file seems less confusing. Author: Andres Freund <andres@anarazel.de> Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-By: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/20210802164124.ufo5buo4apl6yuvs@alap3.anarazel.de
1 parent 27f7903 commit 0a69210

File tree

7 files changed

+217
-161
lines changed

7 files changed

+217
-161
lines changed

src/backend/bootstrap/bootstrap.c

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333
#include "miscadmin.h"
3434
#include "nodes/makefuncs.h"
3535
#include "pg_getopt.h"
36-
#include "pgstat.h"
37-
#include "postmaster/bgwriter.h"
38-
#include "postmaster/startup.h"
39-
#include "postmaster/walwriter.h"
40-
#include "replication/walreceiver.h"
4136
#include "storage/bufmgr.h"
4237
#include "storage/bufpage.h"
4338
#include "storage/condition_variable.h"
@@ -47,7 +42,6 @@
4742
#include "utils/builtins.h"
4843
#include "utils/fmgroids.h"
4944
#include "utils/memutils.h"
50-
#include "utils/ps_status.h"
5145
#include "utils/rel.h"
5246
#include "utils/relmapper.h"
5347

@@ -56,7 +50,6 @@ uint32 bootstrap_data_checksum_version = 0; /* No checksum */
5650

5751
static void CheckerModeMain(void);
5852
static void bootstrap_signals(void);
59-
static void ShutdownAuxiliaryProcess(int code, Datum arg);
6053
static Form_pg_attribute AllocateAttribute(void);
6154
static void populate_typ_list(void);
6255
static Oid gettype(char *type);
@@ -67,8 +60,6 @@ static void cleanup(void);
6760
* ----------------
6861
*/
6962

70-
AuxProcType MyAuxProcType = NotAnAuxProcess; /* declared in miscadmin.h */
71-
7263
Relation boot_reldesc; /* current relation descriptor */
7364

7465
Form_pg_attribute attrtypes[MAXATTR]; /* points to attribute info */
@@ -184,139 +175,6 @@ typedef struct _IndexList
184175
static IndexList *ILHead = NULL;
185176

186177

187-
/*
188-
* AuxiliaryProcessMain
189-
*
190-
* The main entry point for auxiliary processes, such as the bgwriter,
191-
* walwriter, walreceiver, bootstrapper and the shared memory checker code.
192-
*
193-
* This code is here just because of historical reasons.
194-
*/
195-
void
196-
AuxiliaryProcessMain(AuxProcType auxtype)
197-
{
198-
Assert(IsUnderPostmaster);
199-
200-
MyAuxProcType = auxtype;
201-
202-
switch (MyAuxProcType)
203-
{
204-
case StartupProcess:
205-
MyBackendType = B_STARTUP;
206-
break;
207-
case ArchiverProcess:
208-
MyBackendType = B_ARCHIVER;
209-
break;
210-
case BgWriterProcess:
211-
MyBackendType = B_BG_WRITER;
212-
break;
213-
case CheckpointerProcess:
214-
MyBackendType = B_CHECKPOINTER;
215-
break;
216-
case WalWriterProcess:
217-
MyBackendType = B_WAL_WRITER;
218-
break;
219-
case WalReceiverProcess:
220-
MyBackendType = B_WAL_RECEIVER;
221-
break;
222-
default:
223-
elog(ERROR, "something has gone wrong");
224-
MyBackendType = B_INVALID;
225-
}
226-
227-
init_ps_display(NULL);
228-
229-
SetProcessingMode(BootstrapProcessing);
230-
IgnoreSystemIndexes = true;
231-
232-
BaseInit();
233-
234-
/*
235-
* As an auxiliary process, we aren't going to do the full InitPostgres
236-
* pushups, but there are a couple of things that need to get lit up even
237-
* in an auxiliary process.
238-
*/
239-
240-
/*
241-
* Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case, this
242-
* was already done by SubPostmasterMain().
243-
*/
244-
#ifndef EXEC_BACKEND
245-
InitAuxiliaryProcess();
246-
#endif
247-
248-
/*
249-
* Assign the ProcSignalSlot for an auxiliary process. Since it doesn't
250-
* have a BackendId, the slot is statically allocated based on the
251-
* auxiliary process type (MyAuxProcType). Backends use slots indexed in
252-
* the range from 1 to MaxBackends (inclusive), so we use MaxBackends +
253-
* AuxProcType + 1 as the index of the slot for an auxiliary process.
254-
*
255-
* This will need rethinking if we ever want more than one of a particular
256-
* auxiliary process type.
257-
*/
258-
ProcSignalInit(MaxBackends + MyAuxProcType + 1);
259-
260-
/* finish setting up bufmgr.c */
261-
InitBufferPoolBackend();
262-
263-
/*
264-
* Auxiliary processes don't run transactions, but they may need a
265-
* resource owner anyway to manage buffer pins acquired outside
266-
* transactions (and, perhaps, other things in future).
267-
*/
268-
CreateAuxProcessResourceOwner();
269-
270-
/* Initialize statistics reporting */
271-
pgstat_initialize();
272-
273-
/* Initialize backend status information */
274-
pgstat_beinit();
275-
pgstat_bestart();
276-
277-
/* register a before-shutdown callback for LWLock cleanup */
278-
before_shmem_exit(ShutdownAuxiliaryProcess, 0);
279-
280-
SetProcessingMode(NormalProcessing);
281-
282-
switch (MyAuxProcType)
283-
{
284-
case CheckerProcess:
285-
case BootstrapProcess:
286-
pg_unreachable();
287-
break;
288-
289-
case StartupProcess:
290-
StartupProcessMain();
291-
proc_exit(1);
292-
293-
case ArchiverProcess:
294-
PgArchiverMain();
295-
proc_exit(1);
296-
297-
case BgWriterProcess:
298-
BackgroundWriterMain();
299-
proc_exit(1);
300-
301-
case CheckpointerProcess:
302-
CheckpointerMain();
303-
proc_exit(1);
304-
305-
case WalWriterProcess:
306-
InitXLOGAccess();
307-
WalWriterMain();
308-
proc_exit(1);
309-
310-
case WalReceiverProcess:
311-
WalReceiverMain();
312-
proc_exit(1);
313-
314-
default:
315-
elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
316-
proc_exit(1);
317-
}
318-
}
319-
320178
/*
321179
* In shared memory checker mode, all we really want to do is create shared
322180
* memory and semaphores (just to prove we can do it with the current GUC
@@ -554,21 +412,6 @@ bootstrap_signals(void)
554412
pqsignal(SIGQUIT, SIG_DFL);
555413
}
556414

557-
/*
558-
* Begin shutdown of an auxiliary process. This is approximately the equivalent
559-
* of ShutdownPostgres() in postinit.c. We can't run transactions in an
560-
* auxiliary process, so most of the work of AbortTransaction() is not needed,
561-
* but we do need to make sure we've released any LWLocks we are holding.
562-
* (This is only critical during an error exit.)
563-
*/
564-
static void
565-
ShutdownAuxiliaryProcess(int code, Datum arg)
566-
{
567-
LWLockReleaseAll();
568-
ConditionVariableCancelSleep();
569-
pgstat_report_wait_end();
570-
}
571-
572415
/* ----------------------------------------------------------------
573416
* MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS
574417
* ----------------------------------------------------------------

src/backend/postmaster/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ include $(top_builddir)/src/Makefile.global
1414

1515
OBJS = \
1616
autovacuum.o \
17+
auxprocess.o \
1718
bgworker.o \
1819
bgwriter.o \
1920
checkpointer.o \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy