MCPcopy Create free account
hub / github.com/apache/cloudberry / PostmasterStateMachine

Function PostmasterStateMachine

src/backend/postmaster/postmaster.c:4313–4608  ·  view source on GitHub ↗

* Advance the postmaster's state machine and take actions as appropriate * * This is common code for pmdie(), reaper() and sigusr1_handler(), which * receive the signals that might mean we need to change state. */

Source from the content-addressed store, hash-verified

4311 * receive the signals that might mean we need to change state.
4312 */
4313static void
4314PostmasterStateMachine(void)
4315{
4316 /* If we're doing a smart shutdown, try to advance that state. */
4317 if (pmState == PM_RUN || pmState == PM_HOT_STANDBY)
4318 {
4319 if (connsAllowed == ALLOW_SUPERUSER_CONNS)
4320 {
4321 /*
4322 * ALLOW_SUPERUSER_CONNS state ends as soon as online backup mode
4323 * is not active.
4324 */
4325 if (!BackupInProgress())
4326 connsAllowed = ALLOW_NO_CONNS;
4327 }
4328
4329 if (connsAllowed == ALLOW_NO_CONNS)
4330 {
4331 /*
4332 * ALLOW_NO_CONNS state ends when we have no normal client
4333 * backends running. Then we're ready to stop other children.
4334 */
4335 if (CountChildren(BACKEND_TYPE_NORMAL) == 0)
4336 pmState = PM_STOP_BACKENDS;
4337 }
4338 }
4339
4340 /*
4341 * If we're ready to do so, signal child processes to shut down. (This
4342 * isn't a persistent state, but treating it as a distinct pmState allows
4343 * us to share this code across multiple shutdown code paths.)
4344 */
4345 if (pmState == PM_STOP_BACKENDS)
4346 {
4347 /*
4348 * Forget any pending requests for background workers, since we're no
4349 * longer willing to launch any new workers. (If additional requests
4350 * arrive, BackgroundWorkerStateChange will reject them.)
4351 */
4352 ForgetUnstartedBackgroundWorkers();
4353
4354 /* Signal all backend children except walsenders */
4355 SignalSomeChildren(SIGTERM,
4356 BACKEND_TYPE_ALL - BACKEND_TYPE_WALSND);
4357 /* and the autovac launcher too */
4358 if (AutoVacPID != 0)
4359 signal_child(AutoVacPID, SIGTERM);
4360 /* and the bgwriter too */
4361 if (BgWriterPID != 0)
4362 signal_child(BgWriterPID, SIGTERM);
4363 /* and the walwriter too */
4364 if (WalWriterPID != 0)
4365 signal_child(WalWriterPID, SIGTERM);
4366 /* If we're in recovery, also stop startup and walreceiver procs */
4367 if (StartupPID != 0)
4368 signal_child(StartupPID, SIGTERM);
4369 if (WalReceiverPID != 0)
4370 signal_child(WalReceiverPID, SIGTERM);

Callers 3

pmdieFunction · 0.85
reaperFunction · 0.85
sigusr1_handlerFunction · 0.85

Calls 15

BackupInProgressFunction · 0.85
CountChildrenFunction · 0.85
SignalSomeChildrenFunction · 0.85
signal_childFunction · 0.85
dlist_is_emptyFunction · 0.85
ExitPostmasterFunction · 0.85
CancelBackupFunction · 0.85
load_auxiliary_librariesFunction · 0.85
RemovePgTempFilesFunction · 0.85
shmem_exitFunction · 0.85

Tested by

no test coverage detected