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

Commit63bef4d

Browse files
committed
Minor refactoring of assign_backendlist_entry()
Make assign_backendlist_entry() responsible just for allocating theBackend struct. Linking it to the RegisteredBgWorker is the caller'sresponsibility now. Seems more clear that way.Discussion:https://www.postgresql.org/message-id/835232c0-a5f7-4f20-b95b-5b56ba57d741@iki.fi
1 parentef4c35b commit63bef4d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ static void TerminateChildren(int signal);
416416
#defineSignalChildren(sig) SignalSomeChildren(sig, BACKEND_TYPE_ALL)
417417

418418
staticintCountChildren(inttarget);
419-
staticboolassign_backendlist_entry(RegisteredBgWorker*rw);
419+
staticBackend*assign_backendlist_entry(void);
420420
staticvoidmaybe_start_bgworkers(void);
421421
staticboolCreateOptsFile(intargc,char*argv[],char*fullprogname);
422422
staticpid_tStartChildProcess(BackendTypetype);
@@ -4028,6 +4028,7 @@ MaxLivePostmasterChildren(void)
40284028
staticbool
40294029
do_start_bgworker(RegisteredBgWorker*rw)
40304030
{
4031+
Backend*bn;
40314032
pid_tworker_pid;
40324033

40334034
Assert(rw->rw_pid==0);
@@ -4042,11 +4043,14 @@ do_start_bgworker(RegisteredBgWorker *rw)
40424043
* tried again right away, most likely we'd find ourselves hitting the
40434044
* same resource-exhaustion condition.
40444045
*/
4045-
if (!assign_backendlist_entry(rw))
4046+
bn=assign_backendlist_entry();
4047+
if (bn==NULL)
40464048
{
40474049
rw->rw_crashed_at=GetCurrentTimestamp();
40484050
return false;
40494051
}
4052+
rw->rw_backend=bn;
4053+
rw->rw_child_slot=bn->child_slot;
40504054

40514055
ereport(DEBUG1,
40524056
(errmsg_internal("starting background worker process \"%s\"",
@@ -4119,12 +4123,10 @@ bgworker_should_start_now(BgWorkerStartTime start_time)
41194123
* Allocate the Backend struct for a connected background worker, but don't
41204124
* add it to the list of backends just yet.
41214125
*
4122-
* On failure, return false without changing any worker state.
4123-
*
4124-
* Some info from the Backend is copied into the passed rw.
4126+
* On failure, return NULL.
41254127
*/
4126-
staticbool
4127-
assign_backendlist_entry(RegisteredBgWorker*rw)
4128+
staticBackend*
4129+
assign_backendlist_entry(void)
41284130
{
41294131
Backend*bn;
41304132

@@ -4138,7 +4140,7 @@ assign_backendlist_entry(RegisteredBgWorker *rw)
41384140
ereport(LOG,
41394141
(errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
41404142
errmsg("no slot available for new background worker process")));
4141-
returnfalse;
4143+
returnNULL;
41424144
}
41434145

41444146
bn=palloc_extended(sizeof(Backend),MCXT_ALLOC_NO_OOM);
@@ -4147,18 +4149,15 @@ assign_backendlist_entry(RegisteredBgWorker *rw)
41474149
ereport(LOG,
41484150
(errcode(ERRCODE_OUT_OF_MEMORY),
41494151
errmsg("out of memory")));
4150-
returnfalse;
4152+
returnNULL;
41514153
}
41524154

41534155
bn->child_slot=MyPMChildSlot=AssignPostmasterChildSlot();
41544156
bn->bkend_type=BACKEND_TYPE_BGWORKER;
41554157
bn->dead_end= false;
41564158
bn->bgworker_notify= false;
41574159

4158-
rw->rw_backend=bn;
4159-
rw->rw_child_slot=bn->child_slot;
4160-
4161-
return true;
4160+
returnbn;
41624161
}
41634162

41644163
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp