diff options
| author | Robert Haas | 2013-08-28 18:08:13 +0000 |
|---|---|---|
| committer | Robert Haas | 2013-08-28 18:08:13 +0000 |
| commit | 090d0f2050647958865cb495dff74af7257d2bb4 (patch) | |
| tree | bcebc38e72a0c90d8cf3c94d00b026e48887075e /src/include/postmaster | |
| parent | c9e2e2db5c2090a880028fd8c1debff474640f50 (diff) | |
Allow discovery of whether a dynamic background worker is running.
Using the infrastructure provided by this patch, it's possible either
to wait for the startup of a dynamically-registered background worker,
or to poll the status of such a worker without waiting. In either
case, the current PID of the worker process can also be obtained.
As usual, worker_spi is updated to demonstrate the new functionality.
Patch by me. Review by Andres Freund.
Diffstat (limited to 'src/include/postmaster')
| -rw-r--r-- | src/include/postmaster/bgworker.h | 21 | ||||
| -rw-r--r-- | src/include/postmaster/bgworker_internals.h | 2 | ||||
| -rw-r--r-- | src/include/postmaster/postmaster.h | 1 |
3 files changed, 23 insertions, 1 deletions
diff --git a/src/include/postmaster/bgworker.h b/src/include/postmaster/bgworker.h index 0bb897b8f3..8bbbeb492c 100644 --- a/src/include/postmaster/bgworker.h +++ b/src/include/postmaster/bgworker.h @@ -80,13 +80,32 @@ typedef struct BackgroundWorker char bgw_library_name[BGW_MAXLEN]; /* only if bgw_main is NULL */ char bgw_function_name[BGW_MAXLEN]; /* only if bgw_main is NULL */ Datum bgw_main_arg; + pid_t bgw_notify_pid; /* SIGUSR1 this backend on start/stop */ } BackgroundWorker; +typedef enum BgwHandleStatus +{ + BGWH_STARTED, /* worker is running */ + BGWH_NOT_YET_STARTED, /* worker hasn't been started yet */ + BGWH_STOPPED, /* worker has exited */ + BGWH_POSTMASTER_DIED /* postmaster died; worker status unclear */ +} BgwHandleStatus; + +struct BackgroundWorkerHandle; +typedef struct BackgroundWorkerHandle BackgroundWorkerHandle; + /* Register a new bgworker during shared_preload_libraries */ extern void RegisterBackgroundWorker(BackgroundWorker *worker); /* Register a new bgworker from a regular backend */ -extern bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker); +extern bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, + BackgroundWorkerHandle **handle); + +/* Query the status of a bgworker */ +extern BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, + pid_t *pidp); +extern BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle * + handle, pid_t *pid); /* This is valid in a running worker */ extern BackgroundWorker *MyBgworkerEntry; diff --git a/src/include/postmaster/bgworker_internals.h b/src/include/postmaster/bgworker_internals.h index 3b53027fd4..6d5ee20dc3 100644 --- a/src/include/postmaster/bgworker_internals.h +++ b/src/include/postmaster/bgworker_internals.h @@ -40,6 +40,8 @@ extern Size BackgroundWorkerShmemSize(void); extern void BackgroundWorkerShmemInit(void); extern void BackgroundWorkerStateChange(void); extern void ForgetBackgroundWorker(slist_mutable_iter *cur); +extern void ReportBackgroundWorkerPID(RegisteredBgWorker *); +extern void BackgroundWorkerStopNotifications(pid_t pid); /* Function to start a background worker, called from postmaster.c */ extern void StartBackgroundWorker(void); diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index c090595a45..5dc6dc5a5f 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -52,6 +52,7 @@ extern void ClosePostmasterPorts(bool am_syslogger); extern int MaxLivePostmasterChildren(void); extern int GetNumShmemAttachedBgworkers(void); +extern bool PostmasterMarkPIDForWorkerNotify(int); #ifdef EXEC_BACKEND extern pid_t postmaster_forkexec(int argc, char *argv[]); |
