|
155 | 155 | * they will never become live backends. dead_end children are not assigned a
|
156 | 156 | * PMChildSlot.
|
157 | 157 | *
|
158 |
| - * Background workers that request shared memory access during registration are |
159 |
| - * in this list, too. |
| 158 | + * Background workers are in this list, too. |
160 | 159 | */
|
161 | 160 | typedef struct bkend
|
162 | 161 | {
|
@@ -404,13 +403,11 @@ static long PostmasterRandom(void);
|
404 | 403 | static void RandomSalt(char *md5Salt);
|
405 | 404 | static void signal_child(pid_t pid, int signal);
|
406 | 405 | static bool SignalSomeChildren(int signal, int targets);
|
407 |
| -static bool SignalUnconnectedWorkers(int signal); |
408 | 406 | static void TerminateChildren(int signal);
|
409 | 407 |
|
410 | 408 | #define SignalChildren(sig) SignalSomeChildren(sig, BACKEND_TYPE_ALL)
|
411 | 409 |
|
412 | 410 | static int CountChildren(int target);
|
413 |
| -static int CountUnconnectedWorkers(void); |
414 | 411 | static void maybe_start_bgworker(void);
|
415 | 412 | static bool CreateOptsFile(int argc, char *argv[], char *fullprogname);
|
416 | 413 | static pid_t StartChildProcess(AuxProcType type);
|
@@ -2414,7 +2411,6 @@ SIGHUP_handler(SIGNAL_ARGS)
|
2414 | 2411 | (errmsg("received SIGHUP, reloading configuration files")));
|
2415 | 2412 | ProcessConfigFile(PGC_SIGHUP);
|
2416 | 2413 | SignalChildren(SIGHUP);
|
2417 |
| - SignalUnconnectedWorkers(SIGHUP); |
2418 | 2414 | if (StartupPID != 0)
|
2419 | 2415 | signal_child(StartupPID, SIGHUP);
|
2420 | 2416 | if (BgWriterPID != 0)
|
@@ -2491,7 +2487,6 @@ pmdie(SIGNAL_ARGS)
|
2491 | 2487 | /* and bgworkers too; does this need tweaking? */
|
2492 | 2488 | SignalSomeChildren(SIGTERM,
|
2493 | 2489 | BACKEND_TYPE_AUTOVAC | BACKEND_TYPE_BGWORKER);
|
2494 |
| - SignalUnconnectedWorkers(SIGTERM); |
2495 | 2490 | /* and the autovac launcher too */
|
2496 | 2491 | if (AutoVacPID != 0)
|
2497 | 2492 | signal_child(AutoVacPID, SIGTERM);
|
@@ -2543,11 +2538,11 @@ pmdie(SIGNAL_ARGS)
|
2543 | 2538 | signal_child(BgWriterPID, SIGTERM);
|
2544 | 2539 | if (WalReceiverPID != 0)
|
2545 | 2540 | signal_child(WalReceiverPID, SIGTERM);
|
2546 |
| - SignalUnconnectedWorkers(SIGTERM); |
2547 | 2541 | if (pmState == PM_RECOVERY)
|
2548 | 2542 | {
|
| 2543 | + SignalSomeChildren(SIGTERM, BACKEND_TYPE_BGWORKER); |
2549 | 2544 | /*
|
2550 |
| - * Only startup, bgwriter, walreceiver, unconnected bgworkers, |
| 2545 | + * Only startup, bgwriter, walreceiver, possibly bgworkers, |
2551 | 2546 | * and/or checkpointer should be active in this state; we just
|
2552 | 2547 | * signaled the first four, and we don't want to kill
|
2553 | 2548 | * checkpointer yet.
|
@@ -2999,25 +2994,21 @@ CleanupBackgroundWorker(int pid,
|
2999 | 2994 | }
|
3000 | 2995 |
|
3001 | 2996 | /* Get it out of the BackendList and clear out remaining data */
|
3002 |
| - if (rw->rw_backend) |
3003 |
| - { |
3004 |
| - Assert(rw->rw_worker.bgw_flags & BGWORKER_BACKEND_DATABASE_CONNECTION); |
3005 |
| - dlist_delete(&rw->rw_backend->elem); |
| 2997 | + dlist_delete(&rw->rw_backend->elem); |
3006 | 2998 | #ifdef EXEC_BACKEND
|
3007 |
| - ShmemBackendArrayRemove(rw->rw_backend); |
| 2999 | + ShmemBackendArrayRemove(rw->rw_backend); |
3008 | 3000 | #endif
|
3009 | 3001 |
|
3010 |
| - /* |
3011 |
| - * It's possible that this background worker started some OTHER |
3012 |
| - * background worker and asked to be notified when that worker |
3013 |
| - * started or stopped. If so, cancel any notifications destined |
3014 |
| - * for the now-dead backend. |
3015 |
| - */ |
3016 |
| - if (rw->rw_backend->bgworker_notify) |
3017 |
| - BackgroundWorkerStopNotifications(rw->rw_pid); |
3018 |
| - free(rw->rw_backend); |
3019 |
| - rw->rw_backend = NULL; |
3020 |
| - } |
| 3002 | + /* |
| 3003 | + * It's possible that this background worker started some OTHER |
| 3004 | + * background worker and asked to be notified when that worker |
| 3005 | + * started or stopped. If so, cancel any notifications destined |
| 3006 | + * for the now-dead backend. |
| 3007 | + */ |
| 3008 | + if (rw->rw_backend->bgworker_notify) |
| 3009 | + BackgroundWorkerStopNotifications(rw->rw_pid); |
| 3010 | + free(rw->rw_backend); |
| 3011 | + rw->rw_backend = NULL; |
3021 | 3012 | rw->rw_pid = 0;
|
3022 | 3013 | rw->rw_child_slot = 0;
|
3023 | 3014 | ReportBackgroundWorkerPID(rw); /* report child death */
|
@@ -3160,15 +3151,12 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
|
3160 | 3151 | * Found entry for freshly-dead worker, so remove it.
|
3161 | 3152 | */
|
3162 | 3153 | (void) ReleasePostmasterChildSlot(rw->rw_child_slot);
|
3163 |
| - if (rw->rw_backend) |
3164 |
| - { |
3165 |
| - dlist_delete(&rw->rw_backend->elem); |
| 3154 | + dlist_delete(&rw->rw_backend->elem); |
3166 | 3155 | #ifdef EXEC_BACKEND
|
3167 |
| - ShmemBackendArrayRemove(rw->rw_backend); |
| 3156 | + ShmemBackendArrayRemove(rw->rw_backend); |
3168 | 3157 | #endif
|
3169 |
| - free(rw->rw_backend); |
3170 |
| - rw->rw_backend = NULL; |
3171 |
| - } |
| 3158 | + free(rw->rw_backend); |
| 3159 | + rw->rw_backend = NULL; |
3172 | 3160 | rw->rw_pid = 0;
|
3173 | 3161 | rw->rw_child_slot = 0;
|
3174 | 3162 | /* don't reset crashed_at */
|
@@ -3505,7 +3493,6 @@ PostmasterStateMachine(void)
|
3505 | 3493 | * process.
|
3506 | 3494 | */
|
3507 | 3495 | if (CountChildren(BACKEND_TYPE_NORMAL | BACKEND_TYPE_WORKER) == 0 &&
|
3508 |
| - CountUnconnectedWorkers() == 0 && |
3509 | 3496 | StartupPID == 0 &&
|
3510 | 3497 | WalReceiverPID == 0 &&
|
3511 | 3498 | BgWriterPID == 0 &&
|
@@ -3727,39 +3714,6 @@ signal_child(pid_t pid, int signal)
|
3727 | 3714 | #endif
|
3728 | 3715 | }
|
3729 | 3716 |
|
3730 |
| -/* |
3731 |
| - * Send a signal to bgworkers that did not request backend connections |
3732 |
| - * |
3733 |
| - * The reason this is interesting is that workers that did request connections |
3734 |
| - * are considered by SignalChildren; this function complements that one. |
3735 |
| - */ |
3736 |
| -static bool |
3737 |
| -SignalUnconnectedWorkers(int signal) |
3738 |
| -{ |
3739 |
| - slist_iter iter; |
3740 |
| - bool signaled = false; |
3741 |
| - |
3742 |
| - slist_foreach(iter, &BackgroundWorkerList) |
3743 |
| - { |
3744 |
| - RegisteredBgWorker *rw; |
3745 |
| - |
3746 |
| - rw = slist_container(RegisteredBgWorker, rw_lnode, iter.cur); |
3747 |
| - |
3748 |
| - if (rw->rw_pid == 0) |
3749 |
| - continue; |
3750 |
| - /* ignore connected workers */ |
3751 |
| - if (rw->rw_backend != NULL) |
3752 |
| - continue; |
3753 |
| - |
3754 |
| - ereport(DEBUG4, |
3755 |
| - (errmsg_internal("sending signal %d to process %d", |
3756 |
| - signal, (int) rw->rw_pid))); |
3757 |
| - signal_child(rw->rw_pid, signal); |
3758 |
| - signaled = true; |
3759 |
| - } |
3760 |
| - return signaled; |
3761 |
| -} |
3762 |
| - |
3763 | 3717 | /*
|
3764 | 3718 | * Send a signal to the targeted children (but NOT special children;
|
3765 | 3719 | * dead_end children are never signaled, either).
|
@@ -3832,7 +3786,6 @@ TerminateChildren(int signal)
|
3832 | 3786 | signal_child(PgArchPID, signal);
|
3833 | 3787 | if (PgStatPID != 0)
|
3834 | 3788 | signal_child(PgStatPID, signal);
|
3835 |
| - SignalUnconnectedWorkers(signal); |
3836 | 3789 | }
|
3837 | 3790 |
|
3838 | 3791 | /*
|
@@ -5093,33 +5046,6 @@ PostmasterRandom(void)
|
5093 | 5046 | return random();
|
5094 | 5047 | }
|
5095 | 5048 |
|
5096 |
| -/* |
5097 |
| - * Count up number of worker processes that did not request backend connections |
5098 |
| - * See SignalUnconnectedWorkers for why this is interesting. |
5099 |
| - */ |
5100 |
| -static int |
5101 |
| -CountUnconnectedWorkers(void) |
5102 |
| -{ |
5103 |
| - slist_iter iter; |
5104 |
| - int cnt = 0; |
5105 |
| - |
5106 |
| - slist_foreach(iter, &BackgroundWorkerList) |
5107 |
| - { |
5108 |
| - RegisteredBgWorker *rw; |
5109 |
| - |
5110 |
| - rw = slist_container(RegisteredBgWorker, rw_lnode, iter.cur); |
5111 |
| - |
5112 |
| - if (rw->rw_pid == 0) |
5113 |
| - continue; |
5114 |
| - /* ignore connected workers */ |
5115 |
| - if (rw->rw_backend != NULL) |
5116 |
| - continue; |
5117 |
| - |
5118 |
| - cnt++; |
5119 |
| - } |
5120 |
| - return cnt; |
5121 |
| -} |
5122 |
| - |
5123 | 5049 | /*
|
5124 | 5050 | * Count up number of child processes of specified types (dead_end chidren
|
5125 | 5051 | * are always excluded).
|
@@ -5520,8 +5446,7 @@ do_start_bgworker(RegisteredBgWorker *rw)
|
5520 | 5446 | #endif
|
5521 | 5447 | default:
|
5522 | 5448 | rw->rw_pid = worker_pid;
|
5523 |
| - if (rw->rw_backend) |
5524 |
| - rw->rw_backend->pid = rw->rw_pid; |
| 5449 | + rw->rw_backend->pid = rw->rw_pid; |
5525 | 5450 | ReportBackgroundWorkerPID(rw);
|
5526 | 5451 | }
|
5527 | 5452 | }
|
@@ -5684,30 +5609,19 @@ maybe_start_bgworker(void)
|
5684 | 5609 | rw->rw_crashed_at = 0;
|
5685 | 5610 |
|
5686 | 5611 | /*
|
5687 |
| - * If necessary, allocate and assign the Backend element. Note we |
| 5612 | + * Allocate and assign the Backend element. Note we |
5688 | 5613 | * must do this before forking, so that we can handle out of
|
5689 | 5614 | * memory properly.
|
5690 |
| - * |
5691 |
| - * If not connected, we don't need a Backend element, but we still |
5692 |
| - * need a PMChildSlot. |
5693 | 5615 | */
|
5694 |
| - if (rw->rw_worker.bgw_flags & BGWORKER_BACKEND_DATABASE_CONNECTION) |
5695 |
| - { |
5696 |
| - if (!assign_backendlist_entry(rw)) |
5697 |
| - return; |
5698 |
| - } |
5699 |
| - else |
5700 |
| - rw->rw_child_slot = MyPMChildSlot = AssignPostmasterChildSlot(); |
| 5616 | + if (!assign_backendlist_entry(rw)) |
| 5617 | + return; |
5701 | 5618 |
|
5702 | 5619 | do_start_bgworker(rw); /* sets rw->rw_pid */
|
5703 | 5620 |
|
5704 |
| - if (rw->rw_backend) |
5705 |
| - { |
5706 |
| - dlist_push_head(&BackendList, &rw->rw_backend->elem); |
| 5621 | + dlist_push_head(&BackendList, &rw->rw_backend->elem); |
5707 | 5622 | #ifdef EXEC_BACKEND
|
5708 |
| - ShmemBackendArrayAdd(rw->rw_backend); |
| 5623 | + ShmemBackendArrayAdd(rw->rw_backend); |
5709 | 5624 | #endif
|
5710 |
| - } |
5711 | 5625 |
|
5712 | 5626 | /*
|
5713 | 5627 | * Have ServerLoop call us again. Note that there might not
|
|
0 commit comments