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

Function BackendStartup

src/backend/postmaster/postmaster.c:4732–4840  ·  view source on GitHub ↗

* BackendStartup -- start backend process * * returns: STATUS_ERROR if the fork failed, STATUS_OK otherwise. * * Note: if you change this code, also consider StartAutovacuumWorker. */

Source from the content-addressed store, hash-verified

4730 * Note: if you change this code, also consider StartAutovacuumWorker.
4731 */
4732static int
4733BackendStartup(Port *port)
4734{
4735 Backend *bn; /* for backend cleanup */
4736 pid_t pid;
4737
4738 /*
4739 * Create backend data structure. Better before the fork() so we can
4740 * handle failure cleanly.
4741 */
4742 bn = (Backend *) malloc(sizeof(Backend));
4743 if (!bn)
4744 {
4745 ereport(LOG,
4746 (errcode(ERRCODE_OUT_OF_MEMORY),
4747 errmsg("out of memory")));
4748 return STATUS_ERROR;
4749 }
4750
4751 /*
4752 * Compute the cancel key that will be assigned to this backend. The
4753 * backend will have its own copy in the forked-off process' value of
4754 * MyCancelKey, so that it can transmit the key to the frontend.
4755 */
4756 if (!RandomCancelKey(&MyCancelKey))
4757 {
4758 free(bn);
4759 ereport(LOG,
4760 (errcode(ERRCODE_INTERNAL_ERROR),
4761 errmsg("could not generate random cancel key")));
4762 return STATUS_ERROR;
4763 }
4764
4765 bn->cancel_key = MyCancelKey;
4766
4767 /* Pass down canAcceptConnections state */
4768 port->canAcceptConnections = canAcceptConnections(BACKEND_TYPE_NORMAL);
4769 bn->dead_end = (port->canAcceptConnections != CAC_OK &&
4770 port->canAcceptConnections != CAC_SUPERUSER &&
4771 port->canAcceptConnections != CAC_MIRROR_READY);
4772
4773 /*
4774 * Unless it's a dead_end child, assign it a child slot number
4775 */
4776 if (!bn->dead_end)
4777 bn->child_slot = MyPMChildSlot = AssignPostmasterChildSlot();
4778 else
4779 bn->child_slot = 0;
4780
4781 /* Hasn't asked to be notified about any bgworkers yet */
4782 bn->bgworker_notify = false;
4783
4784#ifdef EXEC_BACKEND
4785 pid = backend_forkexec(port);
4786#else /* !EXEC_BACKEND */
4787 pid = fork_process();
4788 if (pid == 0) /* child */
4789 {

Callers 1

ServerLoopFunction · 0.85

Calls 15

RandomCancelKeyFunction · 0.85
canAcceptConnectionsFunction · 0.85
backend_forkexecFunction · 0.85
fork_processFunction · 0.85
InitPostmasterChildFunction · 0.85
ClosePostmasterPortsFunction · 0.85
BackendInitializeFunction · 0.85
BackendRunFunction · 0.85
dlist_push_headFunction · 0.85

Tested by

no test coverage detected