pgsql: Allow background workers to be started dynamically.
pgsql: Allow background workers to be started dynamically.
От:
Robert Haas <rhaas@postgresql.org>
Дата:
Allow background workers to be started dynamically. There is a new API, RegisterDynamicBackgroundWorker, which allows an ordinary user backend to register a new background writer during normal running. This means that it's no longer necessary for all background workers to be registered during processing of shared_preload_libraries, although the option of registering workers at that time remains available. When a background worker exits and will not be restarted, the slot previously used by that background worker is automatically released and becomes available for reuse. Slots used by background workers that are configured for automatic restart can't (yet) be released without shutting down the system. This commit adds a new source file, bgworker.c, and moves some of the existing control logic for background workers there. Previously, there was little enough logic that it made sense to keep everything in postmaster.c, but not any more. This commit also makes the worker_spi contrib module into an extension and adds a new function, worker_spi_launch, which can be used to demonstrate the new facility. Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/7f7485a0cde92aa4ba235a1ffe4dda0ca0b6cc9a Modified Files -------------- contrib/worker_spi/Makefile | 3 + contrib/worker_spi/worker_spi--1.0.sql | 9 + contrib/worker_spi/worker_spi.c | 66 +++- contrib/worker_spi/worker_spi.control | 5 + doc/src/sgml/bgworker.sgml | 55 ++- src/backend/postmaster/Makefile | 4 +- src/backend/postmaster/bgworker.c | 483 +++++++++++++++++++++++++++ src/backend/postmaster/postmaster.c | 227 +++---------- src/backend/storage/ipc/ipci.c | 3 + src/include/postmaster/bgworker.h | 14 +- src/include/postmaster/bgworker_internals.h | 48 +++ src/include/storage/lwlock.h | 1 + src/include/storage/pmsignal.h | 1 + 13 files changed, 710 insertions(+), 209 deletions(-)
Re: pgsql: Allow background workers to be started dynamically.
От:
Andres Freund <andres@2ndquadrant.com>
Дата:
Hi,
On 2013-07-16 17:02:47 +0000, Robert Haas wrote:
> Allow background workers to be started dynamically.
> ...
> src/include/postmaster/bgworker.h | 14 +-
The changes here make it impossible to write a bgworker which properly
works in 9.3 and 9.4. Was that intended? If so, the commit message
should mention the compatibility break...
That causes warnings like:
/home/andres/src/postgresql/contrib/bdr/bdr.c:655:24: warning: assignment from incompatible pointer type [enabled by default]
apply_worker.bgw_main = bdr_apply_main;
^
/home/andres/src/postgresql/contrib/bdr/bdr.c:744:25: error: incompatible types when assigning to type ‘char[64]’ from type ‘char *’
apply_worker.bgw_name = fullname;
And the bgw_name change will probably actually cause crashes...
If it was intended I propose changing the signature for 9.3 as
well. There's just no point in releasing 9.3 when we already know which
trivial but breaking change will be required for 9.4
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services