Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 63bef4d

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

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
#define SignalChildren(sig) SignalSomeChildren(sig, BACKEND_TYPE_ALL)
417417

418418
static int CountChildren(int target);
419-
static bool assign_backendlist_entry(RegisteredBgWorker *rw);
419+
static Backend *assign_backendlist_entry(void);
420420
static void maybe_start_bgworkers(void);
421421
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname);
422422
static pid_t StartChildProcess(BackendType type);
@@ -4028,6 +4028,7 @@ MaxLivePostmasterChildren(void)
40284028
static bool
40294029
do_start_bgworker(RegisteredBgWorker *rw)
40304030
{
4031+
Backend *bn;
40314032
pid_t worker_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-
static bool
4127-
assign_backendlist_entry(RegisteredBgWorker *rw)
4128+
static Backend *
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-
return false;
4143+
return NULL;
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-
return false;
4152+
return NULL;
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+
return bn;
41624161
}
41634162

41644163
/*

0 commit comments

Comments
 (0)