mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Provide a reliable mechanism for terminating a background worker.
Although previously-introduced APIs allow the process that registers a background worker to obtain the worker's PID, there's no way to prevent a worker that is not currently running from being restarted. This patch introduces a new API TerminateBackgroundWorker() that prevents the background worker from being restarted, terminates it if it is currently running, and causes it to be unregistered if or when it is not running. Patch by me. Review by Michael Paquier and KaiGai Kohei.
This commit is contained in:
@ -184,13 +184,18 @@ typedef struct BackgroundWorker
|
||||
argument to <function>RegisterDynamicBackgroundWorker</function>. If the
|
||||
worker is successfully registered, this pointer will be initialized with an
|
||||
opaque handle that can subsequently be passed to
|
||||
<function>GetBackgroundWorkerPid(<parameter>BackgroundWorkerHandle *</parameter>, <parameter>pid_t *</parameter>)</function>.
|
||||
This function can be used to poll the status of the worker: a return
|
||||
value of <literal>BGWH_NOT_YET_STARTED</> indicates that the worker has not
|
||||
yet been started by the postmaster; <literal>BGWH_STOPPED</literal>
|
||||
indicates that it has been started but is no longer running; and
|
||||
<literal>BGWH_STARTED</literal> indicates that it is currently running.
|
||||
In this last case, the PID will also be returned via the second argument.
|
||||
<function>GetBackgroundWorkerPid(<parameter>BackgroundWorkerHandle *</parameter>, <parameter>pid_t *</parameter>)</function> or
|
||||
<function>TerminateBackgroundWorker(<parameter>BackgroundWorkerHandle *</parameter>)</function>.
|
||||
<function>GetBackgroundWorker</> can be used to poll the status of the
|
||||
worker: a return value of <literal>BGWH_NOT_YET_STARTED</> indicates that
|
||||
the worker has not yet been started by the postmaster;
|
||||
<literal>BGWH_STOPPED</literal> indicates that it has been started but is
|
||||
no longer running; and <literal>BGWH_STARTED</literal> indicates that it is
|
||||
currently running. In this last case, the PID will also be returned via the
|
||||
second argument.
|
||||
<function>TerminateBackgroundWorker</> causes the postmaster to send
|
||||
<literal>SIGTERM</> to the worker if it is running, and to unregister it
|
||||
as soon as it is not.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
Reference in New Issue
Block a user