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

Commitd162c3a

Browse files
committed
Pass CAC as an argument to the backend process
We used to smuggle it to the child process in the Port struct, but itseems better to pass it down as a separate argument. This paves theway for the next commit, which moves the initialization of the Portstruct to the backend process, after forking.Reviewed-by: Tristan Partin, Andres FreundDiscussion:https://www.postgresql.org/message-id/7a59b073-5b5b-151e-7ed3-8b01ff7ce9ef@iki.fi
1 parent73f7fb2 commitd162c3a

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,19 @@ static void HandleChildCrash(int pid, int exitstatus, const char *procname);
418418
staticvoidLogChildExit(intlev,constchar*procname,
419419
intpid,intexitstatus);
420420
staticvoidPostmasterStateMachine(void);
421-
staticvoidBackendInitialize(Port*port);
421+
422+
/* Return value of canAcceptConnections() */
423+
typedefenumCAC_state
424+
{
425+
CAC_OK,
426+
CAC_STARTUP,
427+
CAC_SHUTDOWN,
428+
CAC_RECOVERY,
429+
CAC_NOTCONSISTENT,
430+
CAC_TOOMANY,
431+
}CAC_state;
432+
433+
staticvoidBackendInitialize(Port*port,CAC_statecac);
422434
staticvoidBackendRun(Port*port)pg_attribute_noreturn();
423435
staticvoidExitPostmaster(intstatus)pg_attribute_noreturn();
424436
staticintServerLoop(void);
@@ -477,7 +489,7 @@ typedef struct
477489
}win32_deadchild_waitinfo;
478490
#endif/* WIN32 */
479491

480-
staticpid_tbackend_forkexec(Port*port);
492+
staticpid_tbackend_forkexec(Port*port,CAC_statecac);
481493
staticpid_tinternal_forkexec(intargc,char*argv[],Port*port,BackgroundWorker*worker);
482494

483495
/* Type for a socket that can be inherited to a client process */
@@ -4087,6 +4099,7 @@ BackendStartup(Port *port)
40874099
{
40884100
Backend*bn;/* for backend cleanup */
40894101
pid_tpid;
4102+
CAC_statecac;
40904103

40914104
/*
40924105
* Create backend data structure. Better before the fork() so we can
@@ -4118,8 +4131,8 @@ BackendStartup(Port *port)
41184131
bn->cancel_key=MyCancelKey;
41194132

41204133
/* Pass down canAcceptConnections state */
4121-
port->canAcceptConnections=canAcceptConnections(BACKEND_TYPE_NORMAL);
4122-
bn->dead_end= (port->canAcceptConnections!=CAC_OK);
4134+
cac=canAcceptConnections(BACKEND_TYPE_NORMAL);
4135+
bn->dead_end= (cac!=CAC_OK);
41234136

41244137
/*
41254138
* Unless it's a dead_end child, assign it a child slot number
@@ -4133,7 +4146,7 @@ BackendStartup(Port *port)
41334146
bn->bgworker_notify= false;
41344147

41354148
#ifdefEXEC_BACKEND
4136-
pid=backend_forkexec(port);
4149+
pid=backend_forkexec(port,cac);
41374150
#else/* !EXEC_BACKEND */
41384151
pid=fork_process();
41394152
if (pid==0)/* child */
@@ -4145,7 +4158,7 @@ BackendStartup(Port *port)
41454158
ClosePostmasterPorts(false);
41464159

41474160
/* Perform additional initialization and collect startup packet */
4148-
BackendInitialize(port);
4161+
BackendInitialize(port,cac);
41494162

41504163
/* And run the backend */
41514164
BackendRun(port);
@@ -4232,7 +4245,7 @@ report_fork_failure_to_client(Port *port, int errnum)
42324245
* but have not yet set up most of our local pointers to shmem structures.
42334246
*/
42344247
staticvoid
4235-
BackendInitialize(Port*port)
4248+
BackendInitialize(Port*port,CAC_statecac)
42364249
{
42374250
intstatus;
42384251
intret;
@@ -4367,7 +4380,7 @@ BackendInitialize(Port *port)
43674380
*/
43684381
if (status==STATUS_OK)
43694382
{
4370-
switch (port->canAcceptConnections)
4383+
switch (cac)
43714384
{
43724385
caseCAC_STARTUP:
43734386
ereport(FATAL,
@@ -4506,15 +4519,19 @@ postmaster_forkexec(int argc, char *argv[])
45064519
* returns the pid of the fork/exec'd process, or -1 on failure
45074520
*/
45084521
staticpid_t
4509-
backend_forkexec(Port*port)
4522+
backend_forkexec(Port*port,CAC_statecac)
45104523
{
4511-
char*av[4];
4524+
char*av[5];
45124525
intac=0;
4526+
charcacbuf[10];
45134527

45144528
av[ac++]="postgres";
45154529
av[ac++]="--forkbackend";
45164530
av[ac++]=NULL;/* filled in by internal_forkexec */
45174531

4532+
snprintf(cacbuf,sizeof(cacbuf),"%d", (int)cac);
4533+
av[ac++]=cacbuf;
4534+
45184535
av[ac]=NULL;
45194536
Assert(ac<lengthof(av));
45204537

@@ -4921,7 +4938,10 @@ SubPostmasterMain(int argc, char *argv[])
49214938
/* Run backend or appropriate child */
49224939
if (strcmp(argv[1],"--forkbackend")==0)
49234940
{
4924-
Assert(argc==3);/* shouldn't be any more args */
4941+
CAC_statecac;
4942+
4943+
Assert(argc==4);
4944+
cac= (CAC_state)atoi(argv[3]);
49254945

49264946
/*
49274947
* Need to reinitialize the SSL library in the backend, since the
@@ -4955,7 +4975,7 @@ SubPostmasterMain(int argc, char *argv[])
49554975
* PGPROC slots, we have already initialized libpq and are able to
49564976
* report the error to the client.
49574977
*/
4958-
BackendInitialize(port);
4978+
BackendInitialize(port,cac);
49594979

49604980
/* Restore basic shared memory pointers */
49614981
InitShmemAccess(UsedShmemSegAddr);

‎src/include/libpq/libpq-be.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ typedef struct
5858
#include"libpq/pqcomm.h"
5959

6060

61-
typedefenumCAC_state
62-
{
63-
CAC_OK,
64-
CAC_STARTUP,
65-
CAC_SHUTDOWN,
66-
CAC_RECOVERY,
67-
CAC_NOTCONSISTENT,
68-
CAC_TOOMANY,
69-
}CAC_state;
70-
71-
7261
/*
7362
* GSSAPI specific state information
7463
*/
@@ -156,7 +145,6 @@ typedef struct Port
156145
intremote_hostname_resolv;/* see above */
157146
intremote_hostname_errcode;/* see above */
158147
char*remote_port;/* text rep of remote port */
159-
CAC_statecanAcceptConnections;/* postmaster connection status */
160148

161149
/*
162150
* Information that needs to be saved from the startup packet and passed

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp