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

Commitaea5d29

Browse files
committed
Notify bgworker registrant after freeing worker slot.
Tom Lane observed buildfarm failures caused by the select_parallelregression test trying to launch new parallel queries before theworker slots used by the previous ones were freed. Try to fix this byhaving the postmaster free the worker slots before it sends theSIGUSR1 notifications to the registering process. This doesn'tcompletely eliminate the possibility that the user backend might(correctly) observe the worker as dead before the slot is free, but Ibelieve it should make the window significantly narrower.Patch by me, per complaint from Tom Lane. Reviewed by Amit Kapila.Discussion:http://postgr.es/m/30673.1487310734@sss.pgh.pa.us
1 parent5a73e17 commitaea5d29

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

‎src/backend/postmaster/bgworker.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,39 @@ ReportBackgroundWorkerPID(RegisteredBgWorker *rw)
429429
kill(rw->rw_worker.bgw_notify_pid,SIGUSR1);
430430
}
431431

432+
/*
433+
* Report that the PID of a background worker is now zero because a
434+
* previously-running background worker has exited.
435+
*
436+
* This function should only be called from the postmaster.
437+
*/
438+
void
439+
ReportBackgroundWorkerExit(slist_mutable_iter*cur)
440+
{
441+
RegisteredBgWorker*rw;
442+
BackgroundWorkerSlot*slot;
443+
444+
rw=slist_container(RegisteredBgWorker,rw_lnode,cur->cur);
445+
446+
Assert(rw->rw_shmem_slot<max_worker_processes);
447+
slot=&BackgroundWorkerData->slot[rw->rw_shmem_slot];
448+
slot->pid=rw->rw_pid;
449+
450+
/*
451+
* If this worker is slated for deregistration, do that before notifying
452+
* the process which started it. Otherwise, if that process tries to
453+
* reuse the slot immediately, it might not be available yet. In theory
454+
* that could happen anyway if the process checks slot->pid at just the
455+
* wrong moment, but this makes the window narrower.
456+
*/
457+
if (rw->rw_terminate||
458+
rw->rw_worker.bgw_restart_time==BGW_NEVER_RESTART)
459+
ForgetBackgroundWorker(cur);
460+
461+
if (rw->rw_worker.bgw_notify_pid!=0)
462+
kill(rw->rw_worker.bgw_notify_pid,SIGUSR1);
463+
}
464+
432465
/*
433466
* Cancel SIGUSR1 notifications for a PID belonging to an exiting backend.
434467
*

‎src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,9 +3050,9 @@ CleanupBackgroundWorker(int pid,
30503050
intexitstatus)/* child's exit status */
30513051
{
30523052
charnamebuf[MAXPGPATH];
3053-
slist_iteriter;
3053+
slist_mutable_iteriter;
30543054

3055-
slist_foreach(iter,&BackgroundWorkerList)
3055+
slist_foreach_modify(iter,&BackgroundWorkerList)
30563056
{
30573057
RegisteredBgWorker*rw;
30583058

@@ -3126,7 +3126,7 @@ CleanupBackgroundWorker(int pid,
31263126
rw->rw_backend=NULL;
31273127
rw->rw_pid=0;
31283128
rw->rw_child_slot=0;
3129-
ReportBackgroundWorkerPID(rw);/* report child death */
3129+
ReportBackgroundWorkerExit(&iter);/* report child death */
31303130

31313131
LogChildExit(EXIT_STATUS_0(exitstatus) ?DEBUG1 :LOG,
31323132
namebuf,pid,exitstatus);

‎src/include/postmaster/bgworker_internals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern void BackgroundWorkerShmemInit(void);
4242
externvoidBackgroundWorkerStateChange(void);
4343
externvoidForgetBackgroundWorker(slist_mutable_iter*cur);
4444
externvoidReportBackgroundWorkerPID(RegisteredBgWorker*);
45+
externvoidReportBackgroundWorkerExit(slist_mutable_iter*cur);
4546
externvoidBackgroundWorkerStopNotifications(pid_tpid);
4647
externvoidResetBackgroundWorkerCrashTimes(void);
4748

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp