Go to the source code of this file.
Typedefs | |
typedef struct PMSignalData | PMSignalData |
Enumerations | |
enum | PMSignalReason { PMSIGNAL_RECOVERY_STARTED, PMSIGNAL_BEGIN_HOT_STANDBY, PMSIGNAL_WAKEN_ARCHIVER, PMSIGNAL_ROTATE_LOGFILE, PMSIGNAL_START_AUTOVAC_LAUNCHER, PMSIGNAL_START_AUTOVAC_WORKER, PMSIGNAL_START_WALRECEIVER, PMSIGNAL_ADVANCE_STATE_MACHINE, NUM_PMSIGNALS } |
Functions | |
Size | PMSignalShmemSize (void) |
void | PMSignalShmemInit (void) |
void | SendPostmasterSignal (PMSignalReason reason) |
bool | CheckPostmasterSignal (PMSignalReason reason) |
int | AssignPostmasterChildSlot (void) |
bool | ReleasePostmasterChildSlot (int slot) |
bool | IsPostmasterChildWalSender (int slot) |
void | MarkPostmasterChildActive (void) |
void | MarkPostmasterChildInactive (void) |
void | MarkPostmasterChildWalSender (void) |
bool | PostmasterIsAlive (void) |
typedef struct PMSignalData PMSignalData |
Definition at line 38 of file pmsignal.h.
enum PMSignalReason |
Definition at line 23 of file pmsignal.h.
{ PMSIGNAL_RECOVERY_STARTED, /* recovery has started */ PMSIGNAL_BEGIN_HOT_STANDBY, /* begin Hot Standby */ PMSIGNAL_WAKEN_ARCHIVER, /* send a NOTIFY signal to xlog archiver */ PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */ PMSIGNAL_START_AUTOVAC_LAUNCHER, /* start an autovacuum launcher */ PMSIGNAL_START_AUTOVAC_WORKER, /* start an autovacuum worker */ PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */ PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */ NUM_PMSIGNALS /* Must be last value of enum! */ } PMSignalReason;
int AssignPostmasterChildSlot | ( | void | ) |
Definition at line 151 of file pmsignal.c.
References elog, FATAL, PMSignalData::next_child_flag, PMSignalData::num_child_flags, PM_CHILD_UNUSED, PMSignalData::PMChildFlags, and PMSignalState.
Referenced by assign_backendlist_entry(), BackendStartup(), StartAutovacuumWorker(), and StartOneBackgroundWorker().
{ int slot = PMSignalState->next_child_flag; int n; /* * Scan for a free slot. We track the last slot assigned so as not to * waste time repeatedly rescanning low-numbered slots. */ for (n = PMSignalState->num_child_flags; n > 0; n--) { if (--slot < 0) slot = PMSignalState->num_child_flags - 1; if (PMSignalState->PMChildFlags[slot] == PM_CHILD_UNUSED) { PMSignalState->PMChildFlags[slot] = PM_CHILD_ASSIGNED; PMSignalState->next_child_flag = slot; return slot + 1; } } /* Out of slots ... should never happen, else postmaster.c messed up */ elog(FATAL, "no free slots in PMChildFlags array"); return 0; /* keep compiler quiet */ }
bool CheckPostmasterSignal | ( | PMSignalReason | reason | ) |
Definition at line 130 of file pmsignal.c.
References PMSignalData::PMSignalFlags, and PMSignalState.
Referenced by sigusr1_handler().
{ /* Careful here --- don't clear flag if we haven't seen it set */ if (PMSignalState->PMSignalFlags[reason]) { PMSignalState->PMSignalFlags[reason] = false; return true; } return false; }
bool IsPostmasterChildWalSender | ( | int | slot | ) |
Definition at line 207 of file pmsignal.c.
References Assert, PM_CHILD_WALSENDER, PMSignalData::PMChildFlags, and PMSignalState.
Referenced by CountChildren(), and SignalSomeChildren().
{ Assert(slot > 0 && slot <= PMSignalState->num_child_flags); slot--; if (PMSignalState->PMChildFlags[slot] == PM_CHILD_WALSENDER) return true; else return false; }
void MarkPostmasterChildActive | ( | void | ) |
Definition at line 223 of file pmsignal.c.
References Assert, MyPMChildSlot, PM_CHILD_ASSIGNED, PMSignalData::PMChildFlags, and PMSignalState.
Referenced by InitProcess().
{ int slot = MyPMChildSlot; Assert(slot > 0 && slot <= PMSignalState->num_child_flags); slot--; Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ASSIGNED); PMSignalState->PMChildFlags[slot] = PM_CHILD_ACTIVE; }
void MarkPostmasterChildInactive | ( | void | ) |
Definition at line 256 of file pmsignal.c.
References Assert, MyPMChildSlot, PM_CHILD_ACTIVE, PM_CHILD_WALSENDER, PMSignalData::PMChildFlags, and PMSignalState.
Referenced by ProcKill().
{ int slot = MyPMChildSlot; Assert(slot > 0 && slot <= PMSignalState->num_child_flags); slot--; Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ACTIVE || PMSignalState->PMChildFlags[slot] == PM_CHILD_WALSENDER); PMSignalState->PMChildFlags[slot] = PM_CHILD_ASSIGNED; }
void MarkPostmasterChildWalSender | ( | void | ) |
Definition at line 239 of file pmsignal.c.
References am_walsender, Assert, MyPMChildSlot, PM_CHILD_ACTIVE, PMSignalData::PMChildFlags, and PMSignalState.
Referenced by InitWalSender().
{ int slot = MyPMChildSlot; Assert(am_walsender); Assert(slot > 0 && slot <= PMSignalState->num_child_flags); slot--; Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ACTIVE); PMSignalState->PMChildFlags[slot] = PM_CHILD_WALSENDER; }
void PMSignalShmemInit | ( | void | ) |
Definition at line 95 of file pmsignal.c.
References MaxLivePostmasterChildren(), MemSet, PMSignalData::num_child_flags, PMSignalShmemSize(), PMSignalState, and ShmemInitStruct().
Referenced by CreateSharedMemoryAndSemaphores().
{ bool found; PMSignalState = (PMSignalData *) ShmemInitStruct("PMSignalState", PMSignalShmemSize(), &found); if (!found) { MemSet(PMSignalState, 0, PMSignalShmemSize()); PMSignalState->num_child_flags = MaxLivePostmasterChildren(); } }
Size PMSignalShmemSize | ( | void | ) |
Definition at line 80 of file pmsignal.c.
References add_size(), MaxLivePostmasterChildren(), mul_size(), and offsetof.
Referenced by CreateSharedMemoryAndSemaphores(), and PMSignalShmemInit().
{ Size size; size = offsetof(PMSignalData, PMChildFlags); size = add_size(size, mul_size(MaxLivePostmasterChildren(), sizeof(sig_atomic_t))); return size; }
bool PostmasterIsAlive | ( | void | ) |
Definition at line 272 of file pmsignal.c.
References EAGAIN, elog, EWOULDBLOCK, FATAL, postmaster_alive_fds, POSTMASTER_FD_WATCH, and read.
Referenced by HandleStartupProcInterrupts(), pgarch_ArchiverCopyLoop(), pgarch_MainLoop(), SyncRepWaitForLSN(), WaitLatchOrSocket(), WalRcvWaitForStartPosition(), WalReceiverMain(), and WalSndLoop().
{ #ifndef WIN32 char c; ssize_t rc; rc = read(postmaster_alive_fds[POSTMASTER_FD_WATCH], &c, 1); if (rc < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) return true; else elog(FATAL, "read on postmaster death monitoring pipe failed: %m"); } else if (rc > 0) elog(FATAL, "unexpected data in postmaster death monitoring pipe"); return false; #else /* WIN32 */ return (WaitForSingleObject(PostmasterHandle, 0) == WAIT_TIMEOUT); #endif /* WIN32 */ }
bool ReleasePostmasterChildSlot | ( | int | slot | ) |
Definition at line 185 of file pmsignal.c.
References Assert, PMSignalData::PMChildFlags, and PMSignalState.
Referenced by BackendStartup(), CleanupBackend(), CleanupBackgroundWorker(), HandleChildCrash(), and StartAutovacuumWorker().
{ bool result; Assert(slot > 0 && slot <= PMSignalState->num_child_flags); slot--; /* * Note: the slot state might already be unused, because the logic in * postmaster.c is such that this might get called twice when a child * crashes. So we don't try to Assert anything about the state. */ result = (PMSignalState->PMChildFlags[slot] == PM_CHILD_ASSIGNED); PMSignalState->PMChildFlags[slot] = PM_CHILD_UNUSED; return result; }
void SendPostmasterSignal | ( | PMSignalReason | reason | ) |
Definition at line 113 of file pmsignal.c.
References IsUnderPostmaster, PMSignalData::PMSignalFlags, PMSignalState, PostmasterPid, and SIGUSR1.
Referenced by AutoVacLauncherMain(), CheckRecoveryConsistency(), do_start_worker(), GetNewMultiXactId(), GetNewTransactionId(), InitWalSender(), pg_rotate_logfile(), RequestXLogStreaming(), SetMultiXactIdLimit(), SetTransactionIdLimit(), StartupXLOG(), and XLogArchiveNotify().
{ /* If called in a standalone backend, do nothing */ if (!IsUnderPostmaster) return; /* Atomically set the proper flag */ PMSignalState->PMSignalFlags[reason] = true; /* Send signal to postmaster */ kill(PostmasterPid, SIGUSR1); }