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

Function InitProcess

src/backend/storage/lmgr/proc.c:348–626  ·  view source on GitHub ↗

* InitProcess -- initialize a per-process data structure for this backend */

Source from the content-addressed store, hash-verified

346 * InitProcess -- initialize a per-process data structure for this backend
347 */
348void
349InitProcess(void)
350{
351 PGPROC *volatile *procgloballist;
352
353 /*
354 * WAL sender, etc are marked as GP_ROLE_UTILITY to prevent unwanted
355 * GP_ROLE_DISPATCH MyProc settings such as mppSessionId being valid and
356 * mppIsWriter set to true.
357 */
358 if (am_walsender || am_ftshandler || am_faulthandler)
359 Gp_role = GP_ROLE_UTILITY;
360
361 /*
362 * ProcGlobal should be set up already (if we are a backend, we inherit
363 * this by fork() or EXEC_BACKEND mechanism from the postmaster).
364 */
365 if (ProcGlobal == NULL)
366 elog(PANIC, "proc header uninitialized");
367
368 if (MyProc != NULL)
369 elog(ERROR, "you already exist");
370
371 /* Decide which list should supply our PGPROC. */
372 if (IsAnyAutoVacuumProcess())
373 procgloballist = &ProcGlobal->autovacFreeProcs;
374 else if (IsAnyLoginMonitorProcess())
375 procgloballist = &ProcGlobal->lmFreeProcs;
376 else if (IsBackgroundWorker)
377 procgloballist = &ProcGlobal->bgworkerFreeProcs;
378 else if (am_walsender)
379 procgloballist = &ProcGlobal->walsenderFreeProcs;
380 else
381 procgloballist = &ProcGlobal->freeProcs;
382
383 /*
384 * Try to get a proc struct from the appropriate free list. If this
385 * fails, we must be out of PGPROC structures (not to mention semaphores).
386 *
387 * While we are holding the ProcStructLock, also copy the current shared
388 * estimate of spins_per_delay to local storage.
389 */
390 SpinLockAcquire(ProcStructLock);
391
392 set_spins_per_delay(ProcGlobal->spins_per_delay);
393
394 MyProc = *procgloballist;
395
396 if (MyProc != NULL)
397 {
398 *procgloballist = (PGPROC *) MyProc->links.next;
399 SpinLockRelease(ProcStructLock);
400 }
401 else
402 {
403 /*
404 * If we reach here, all the PGPROCs are in use. This is one of the
405 * possible places to detect "too many backends", so give the standard

Callers 8

PostgresMainFunction · 0.85
StartBackgroundWorkerFunction · 0.85
LoginMonitorLauncherMainFunction · 0.85
LoginMonitorWorkerMainFunction · 0.85
SubPostmasterMainFunction · 0.85
AutoVacLauncherMainFunction · 0.85
AutoVacWorkerMainFunction · 0.85
BootstrapModeMainFunction · 0.85

Calls 15

set_spins_per_delayFunction · 0.85
MemoryContextAllocZeroFunction · 0.85
pg_atomic_add_fetch_u32Function · 0.85
SHMQueueElemInitFunction · 0.85
pg_atomic_write_u64Function · 0.85
SHMQueueEmptyFunction · 0.85
pg_atomic_read_u32Function · 0.85
dlist_is_emptyFunction · 0.85

Tested by

no test coverage detected