Beispiel #1
0
/*
 * AuxiliaryProcKill() -- Cut-down version of ProcKill for auxiliary
 *		processes (bgwriter, etc).	The PGPROC and sema are not released, only
 *		marked as not-in-use.
 */
static void
AuxiliaryProcKill(int code, Datum arg)
{
	int			proctype = DatumGetInt32(arg);
	PGPROC	   *auxproc;

	Assert(proctype >= 0 && proctype < NUM_AUXILIARY_PROCS);

	auxproc = &AuxiliaryProcs[proctype];

	Assert(MyProc == auxproc);

	/* Release any LW locks I am holding (see notes above) */
	LWLockReleaseAll();

	/* Update shared estimate of spins_per_delay */
	update_spins_per_delay();

	if (code == 0 || code == 1)
	{
		MyProc->postmasterResetRequired = false;
	}

	/*
	 * If the parent process of this auxiliary process does not exist,
	 * we want to set the proc array entry free here. The postmaster may
	 * not own this process, so that it can't set the entry free. This
	 * could happen to the filerep subprocesses when the filerep main
	 * process dies unexpectedly.
	 */
	if (!ParentProcIsAlive())
	{
		MyProc->pid = 0;
		MyProc->postmasterResetRequired = true;
	}

	/* PGPROC struct isn't mine anymore */
	MyProc = NULL;
	lockHolderProcPtr = NULL;
}
/*
 *  FileRepSubProcess_ProcessSignals()
 *
 */
bool
FileRepSubProcess_ProcessSignals()
{
	bool		processExit = false;

	if (reloadConfigFile)
	{
		reloadConfigFile = false;
		ProcessConfigFile(PGC_SIGHUP);

		FileRep_SetFileRepRetry();
	}

	if (shutdownRequested)
	{
		SegmentState_e segmentState;

		getPrimaryMirrorStatusCodes(NULL, &segmentState, NULL, NULL);

		shutdownRequested = false;

		if (segmentState == SegmentStateShutdownFilerepBackends)
		{
			processExit = FileRepIsBackendSubProcess(fileRepProcessType);
			FileRepSubProcess_SetState(FileRepStateShutdownBackends);
		}
		else
		{
			processExit = true;
			FileRepSubProcess_SetState(FileRepStateShutdown);
		}
	}

	/*
	 * Immediate shutdown if postmaster or main filerep process (parent) is
	 * not alive to avoid manual cleanup.
	 */
	if (!PostmasterIsAlive(false /* amDirectChild */ ) || !ParentProcIsAlive())
	{
		quickdie_impl();
	}

	for (;;)
	{
		/* check to see if change required */
		sig_atomic_t curStateChangeRequestCounter = stateChangeRequestCounter;

		if (curStateChangeRequestCounter == lastChangeRequestProcessCounterValue)
			break;
		lastChangeRequestProcessCounterValue = curStateChangeRequestCounter;

		/* do the change in local memory */
		getFileRepRoleAndState(&fileRepRole, &segmentState, &dataState, NULL, NULL);
		switch (segmentState)
		{

			case SegmentStateNotInitialized:
				FileRepSubProcess_SetState(FileRepStateNotInitialized);
				break;

			case SegmentStateInitialization:
				FileRepSubProcess_SetState(FileRepStateInitialization);
				break;

			case SegmentStateInResyncTransition:
				FileRepSubProcess_SetState(FileRepStateInitialization);
				break;

			case SegmentStateInChangeTrackingTransition:
			case SegmentStateInSyncTransition:
				/* fileRepState remains Ready */
				break;

			case SegmentStateChangeTrackingDisabled:
			case SegmentStateReady:
				FileRepSubProcess_SetState(FileRepStateReady);
				break;

			case SegmentStateFault:
				FileRepSubProcess_SetState(FileRepStateFault);
				break;

			case SegmentStateShutdownFilerepBackends:
				if (fileRepRole == FileRepPrimaryRole)
				{
					FileRepSubProcess_SetState(FileRepStateShutdownBackends);
				}
				else
				{
					processExit = true;
					FileRepSubProcess_SetState(FileRepStateShutdown);
				}
				break;

			case SegmentStateImmediateShutdown:
			case SegmentStateShutdown:
				processExit = true;
				FileRepSubProcess_SetState(FileRepStateShutdown);
				break;

			default:
				Assert(0);
				break;
		} //switch ()

				if (processExit == true)
				{
					FileRep_IpcSignalAll();
				}
	}

	return (processExit);
}