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

Commit5b00786

Browse files
committed
Pass MyPMChildSlot as an explicit argument to child process
All the other global variables passed from postmaster to child havethe same value in all the processes, while MyPMChildSlot is more likea parameter to each child process.Reviewed-by: Andres Freund <andres@anarazel.de>Discussion:https://www.postgresql.org/message-id/a102f15f-eac4-4ff2-af02-f9ff209ec66f@iki.fi
1 parenta78af04 commit5b00786

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

‎src/backend/postmaster/launch_backend.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ typedef int InheritableSocket;
8888
typedefstruct
8989
{
9090
charDataDir[MAXPGPATH];
91-
intMyPMChildSlot;
9291
#ifndefWIN32
9392
unsigned longUsedShmemSegID;
9493
#else
@@ -130,6 +129,8 @@ typedef struct
130129
charmy_exec_path[MAXPGPATH];
131130
charpkglib_path[MAXPGPATH];
132131

132+
intMyPMChildSlot;
133+
133134
/*
134135
* These are only used by backend processes, but are here because passing
135136
* a socket needs some special handling on Windows. 'client_sock' is an
@@ -151,13 +152,16 @@ typedef struct
151152
staticvoidread_backend_variables(char*id,char**startup_data,size_t*startup_data_len);
152153
staticvoidrestore_backend_variables(BackendParameters*param);
153154

154-
staticboolsave_backend_variables(BackendParameters*param,ClientSocket*client_sock,
155+
staticboolsave_backend_variables(BackendParameters*param,intchild_slot,
156+
ClientSocket*client_sock,
155157
#ifdefWIN32
156158
HANDLEchildProcess,pid_tchildPid,
157159
#endif
158160
char*startup_data,size_tstartup_data_len);
159161

160-
staticpid_tinternal_forkexec(constchar*child_kind,char*startup_data,size_tstartup_data_len,ClientSocket*client_sock);
162+
staticpid_tinternal_forkexec(constchar*child_kind,intchild_slot,
163+
char*startup_data,size_tstartup_data_len,
164+
ClientSocket*client_sock);
161165

162166
#endif/* EXEC_BACKEND */
163167

@@ -215,11 +219,12 @@ PostmasterChildName(BackendType child_type)
215219
* appropriate, and fds and other resources that we've inherited from
216220
* postmaster that are not needed in a child process have been closed.
217221
*
218-
* 'startup_data' is an optional contiguous chunk of data that is passed to
219-
* the child process.
222+
* 'child_slot' is the PMChildFlags array index reserved for the child
223+
* process. 'startup_data' is an optional contiguous chunk of data that is
224+
* passed to the child process.
220225
*/
221226
pid_t
222-
postmaster_child_launch(BackendTypechild_type,
227+
postmaster_child_launch(BackendTypechild_type,intchild_slot,
223228
char*startup_data,size_tstartup_data_len,
224229
ClientSocket*client_sock)
225230
{
@@ -228,7 +233,7 @@ postmaster_child_launch(BackendType child_type,
228233
Assert(IsPostmasterEnvironment&& !IsUnderPostmaster);
229234

230235
#ifdefEXEC_BACKEND
231-
pid=internal_forkexec(child_process_kinds[child_type].name,
236+
pid=internal_forkexec(child_process_kinds[child_type].name,child_slot,
232237
startup_data,startup_data_len,client_sock);
233238
/* the child process will arrive in SubPostmasterMain */
234239
#else/* !EXEC_BACKEND */
@@ -256,6 +261,7 @@ postmaster_child_launch(BackendType child_type,
256261
*/
257262
MemoryContextSwitchTo(TopMemoryContext);
258263

264+
MyPMChildSlot=child_slot;
259265
if (client_sock)
260266
{
261267
MyClientSocket=palloc(sizeof(ClientSocket));
@@ -282,7 +288,8 @@ postmaster_child_launch(BackendType child_type,
282288
* - fork():s, and then exec():s the child process
283289
*/
284290
staticpid_t
285-
internal_forkexec(constchar*child_kind,char*startup_data,size_tstartup_data_len,ClientSocket*client_sock)
291+
internal_forkexec(constchar*child_kind,intchild_slot,
292+
char*startup_data,size_tstartup_data_len,ClientSocket*client_sock)
286293
{
287294
staticunsigned longtmpBackendFileNum=0;
288295
pid_tpid;
@@ -302,7 +309,7 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
302309
*/
303310
paramsz=SizeOfBackendParameters(startup_data_len);
304311
param=palloc0(paramsz);
305-
if (!save_backend_variables(param,client_sock,startup_data,startup_data_len))
312+
if (!save_backend_variables(param,child_slot,client_sock,startup_data,startup_data_len))
306313
{
307314
pfree(param);
308315
return-1;/* log made by save_backend_variables */
@@ -391,7 +398,8 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
391398
* file is complete.
392399
*/
393400
staticpid_t
394-
internal_forkexec(constchar*child_kind,char*startup_data,size_tstartup_data_len,ClientSocket*client_sock)
401+
internal_forkexec(constchar*child_kind,intchild_slot,
402+
char*startup_data,size_tstartup_data_len,ClientSocket*client_sock)
395403
{
396404
intretry_count=0;
397405
STARTUPINFOsi;
@@ -472,7 +480,9 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
472480
return-1;
473481
}
474482

475-
if (!save_backend_variables(param,client_sock,pi.hProcess,pi.dwProcessId,startup_data,startup_data_len))
483+
if (!save_backend_variables(param,child_slot,client_sock,
484+
pi.hProcess,pi.dwProcessId,
485+
startup_data,startup_data_len))
476486
{
477487
/*
478488
* log made by save_backend_variables, but we have to clean up the
@@ -684,7 +694,8 @@ static void read_inheritable_socket(SOCKET *dest, InheritableSocket *src);
684694

685695
/* Save critical backend variables into the BackendParameters struct */
686696
staticbool
687-
save_backend_variables(BackendParameters*param,ClientSocket*client_sock,
697+
save_backend_variables(BackendParameters*param,
698+
intchild_slot,ClientSocket*client_sock,
688699
#ifdefWIN32
689700
HANDLEchildProcess,pid_tchildPid,
690701
#endif
@@ -701,7 +712,7 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
701712

702713
strlcpy(param->DataDir,DataDir,MAXPGPATH);
703714

704-
param->MyPMChildSlot=MyPMChildSlot;
715+
param->MyPMChildSlot=child_slot;
705716

706717
#ifdefWIN32
707718
param->ShmemProtectiveRegion=ShmemProtectiveRegion;

‎src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,8 +3374,7 @@ BackendStartup(ClientSocket *client_sock)
33743374
/* Hasn't asked to be notified about any bgworkers yet */
33753375
bn->bgworker_notify= false;
33763376

3377-
MyPMChildSlot=bn->child_slot;
3378-
pid=postmaster_child_launch(bn->bkend_type,
3377+
pid=postmaster_child_launch(bn->bkend_type,bn->child_slot,
33793378
(char*)&startup_data,sizeof(startup_data),
33803379
client_sock);
33813380
if (pid<0)
@@ -3700,8 +3699,7 @@ StartChildProcess(BackendType type)
37003699
returnNULL;
37013700
}
37023701

3703-
MyPMChildSlot=pmchild->child_slot;
3704-
pid=postmaster_child_launch(type,NULL,0,NULL);
3702+
pid=postmaster_child_launch(type,pmchild->child_slot,NULL,0,NULL);
37053703
if (pid<0)
37063704
{
37073705
/* in parent, fork failed */
@@ -3878,8 +3876,8 @@ StartBackgroundWorker(RegisteredBgWorker *rw)
38783876
(errmsg_internal("starting background worker process \"%s\"",
38793877
rw->rw_worker.bgw_name)));
38803878

3881-
MyPMChildSlot=bn->child_slot;
3882-
worker_pid=postmaster_child_launch(B_BG_WORKER, (char*)&rw->rw_worker,sizeof(BackgroundWorker),NULL);
3879+
worker_pid=postmaster_child_launch(B_BG_WORKER,bn->child_slot,
3880+
(char*)&rw->rw_worker,sizeof(BackgroundWorker),NULL);
38833881
if (worker_pid==-1)
38843882
{
38853883
/* in postmaster, fork failed ... */

‎src/backend/postmaster/syslogger.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,15 @@ SysLogger_Start(int child_slot)
694694
pfree(filename);
695695
}
696696

697-
MyPMChildSlot=child_slot;
698697
#ifdefEXEC_BACKEND
699698
startup_data.syslogFile=syslogger_fdget(syslogFile);
700699
startup_data.csvlogFile=syslogger_fdget(csvlogFile);
701700
startup_data.jsonlogFile=syslogger_fdget(jsonlogFile);
702-
sysloggerPid=postmaster_child_launch(B_LOGGER, (char*)&startup_data,sizeof(startup_data),NULL);
701+
sysloggerPid=postmaster_child_launch(B_LOGGER,child_slot,
702+
(char*)&startup_data,sizeof(startup_data),NULL);
703703
#else
704-
sysloggerPid=postmaster_child_launch(B_LOGGER,NULL,0,NULL);
704+
sysloggerPid=postmaster_child_launch(B_LOGGER,child_slot,
705+
NULL,0,NULL);
705706
#endif/* EXEC_BACKEND */
706707

707708
if (sysloggerPid==-1)

‎src/include/postmaster/postmaster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extern PGDLLIMPORT struct ClientSocket *MyClientSocket;
108108

109109
/* prototypes for functions in launch_backend.c */
110110
externpid_tpostmaster_child_launch(BackendTypechild_type,
111+
intchild_slot,
111112
char*startup_data,
112113
size_tstartup_data_len,
113114
structClientSocket*client_sock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp