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

Function StartLMWorker

src/backend/postmaster/postmaster.c:6263–6338  ·  view source on GitHub ↗

* StartLMWorker * Start a login monitor worker process. * * Like StartAutovacuumWorker, this function is here. As login monitor * worker process is used like normal process, we set backend_type to * NORMAL. */

Source from the content-addressed store, hash-verified

6261 * NORMAL.
6262 */
6263static void
6264StartLMWorker(void)
6265{
6266 Backend *bn;
6267
6268 /*
6269 * If not in condition to run a process, don't try, but handle it like a
6270 * fork failure. This does not normally happen, since the signal is only
6271 * supposed to be sent by login monitor launcher when it's OK to do it,
6272 * but we have to check to avoid race-condition problems during DB state
6273 * changes.
6274 */
6275 if (canAcceptConnections(BACKEND_TYPE_NORMAL) == CAC_OK)
6276 {
6277 /*
6278 * Compute the cancel key that will be assigned to this session. We
6279 * probably don't need cancel keys for autovac workers, but we'd
6280 * better have something random in the field to prevent unfriendly
6281 * people from sending cancels to them。
6282 */
6283 if (!RandomCancelKey(&MyCancelKey))
6284 {
6285 ereport(LOG,
6286 (errcode(ERRCODE_INTERNAL_ERROR),
6287 errmsg("could not generate random cancel key")));
6288 return;
6289 }
6290
6291 bn = (Backend *) malloc(sizeof(Backend));
6292 if (bn)
6293 {
6294 bn->cancel_key = MyCancelKey;
6295
6296 /* Login monitor workers are not dead_end and need a child slot */
6297 bn->dead_end = false;
6298 bn->child_slot = MyPMChildSlot = AssignPostmasterChildSlot();
6299 bn->bgworker_notify = false;
6300
6301 bn->pid = StartLoginMonitorWorker();
6302 if (bn->pid > 0)
6303 {
6304 bn->bkend_type = BACKEND_TYPE_NORMAL;
6305 dlist_push_head(&BackendList, &bn->elem);
6306#ifdef EXEC_BACKEND
6307 ShmemBackendArrayAdd(bn);
6308#endif
6309
6310 /* all OK */
6311 return;
6312 }
6313
6314 /*
6315 * fork failed, fall through to report -- actual error message was
6316 * logged by StartLoginMonitorWorker
6317 */
6318 (void) ReleasePostmasterChildSlot(bn->child_slot);
6319 free(bn);
6320 }

Callers 1

sigusr1_handlerFunction · 0.85

Calls 10

canAcceptConnectionsFunction · 0.85
RandomCancelKeyFunction · 0.85
StartLoginMonitorWorkerFunction · 0.85
dlist_push_headFunction · 0.85
ShmemBackendArrayAddFunction · 0.85
LoginMonitorWorkerFailedFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected