Thu Sep 23 18:29:15 PDT 2004
- Previous message: [Slony1-commit] By wieck: Added function cleanupListener(), which is called at slon
- Next message: [Slony1-commit] By darcyb: fix brain dead moment of forgetting test returns 0 on GOOD
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Log Message: ----------- Added function cleanupListener(), which is called at slon startup and removes all stale entries from pg_listener. Jan Modified Files: -------------- slony1-engine/src/backend: slony1_funcs.c (r1.20 -> r1.21) slony1_funcs.sql (r1.26 -> r1.27) slony1-engine/src/slon: local_listen.c (r1.23 -> r1.24) -------------- next part -------------- Index: slony1_funcs.sql =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.sql,v retrieving revision 1.26 retrieving revision 1.27 diff -Lsrc/backend/slony1_funcs.sql -Lsrc/backend/slony1_funcs.sql -u -w -r1.26 -r1.27 --- src/backend/slony1_funcs.sql +++ src/backend/slony1_funcs.sql @@ -219,6 +219,16 @@ 'not yet documented'; +-- ---------------------------------------------------------------------- +-- FUNCTION cleanupListener () +-- +-- +-- ---------------------------------------------------------------------- +create or replace function @NAMESPACE at .cleanupListener () returns int4 + as '$libdir/slony1_funcs', '_Slony_I_cleanupListener' + language C; + + -- ********************************************************************** -- * PL/pgSQL functions for administrative tasks -- ********************************************************************** Index: slony1_funcs.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.c,v retrieving revision 1.20 retrieving revision 1.21 diff -Lsrc/backend/slony1_funcs.c -Lsrc/backend/slony1_funcs.c -u -w -r1.20 -r1.21 --- src/backend/slony1_funcs.c +++ src/backend/slony1_funcs.c @@ -18,6 +18,7 @@ #include "parser/parse_type.h" #include "executor/spi.h" #include "commands/trigger.h" +#include "commands/async.h" #include "access/xact.h" #include "utils/builtins.h" #include "utils/elog.h" @@ -38,6 +39,7 @@ PG_FUNCTION_INFO_V1(_Slony_I_denyAccess); PG_FUNCTION_INFO_V1(_Slony_I_lockedSet); PG_FUNCTION_INFO_V1(_Slony_I_terminateNodeConnections); +PG_FUNCTION_INFO_V1(_Slony_I_cleanupListener); Datum _Slony_I_createEvent(PG_FUNCTION_ARGS); Datum _Slony_I_getLocalNodeId(PG_FUNCTION_ARGS); @@ -48,6 +50,7 @@ Datum _Slony_I_denyAccess(PG_FUNCTION_ARGS); Datum _Slony_I_lockedSet(PG_FUNCTION_ARGS); Datum _Slony_I_terminateNodeConnections(PG_FUNCTION_ARGS); +Datum _Slony_I_cleanupListener(PG_FUNCTION_ARGS); #ifdef CYGWIN extern DLLIMPORT Node *newNodeMacroHolder; @@ -960,6 +963,55 @@ } +Datum +_Slony_I_cleanupListener(PG_FUNCTION_ARGS) +{ + static void *plan = NULL; + int i; + int32 pid; + char *relname; + bool isnull; + + + if (SPI_connect() < 0) + elog(ERROR, "Slony-I: SPI_connect() failed in cleanupListener()"); + + if (plan == NULL) + { + plan = SPI_saveplan(SPI_prepare("select relname, listenerpid " + " from \"pg_catalog\".pg_listener; ", + 0, NULL)); + if (plan == NULL) + elog(ERROR, "Slony-I: SPI_prepare() failed in cleanupListener()"); + } + + if (SPI_execp(plan, NULL, NULL, 0) != SPI_OK_SELECT) + elog(ERROR, "Slony-I: SPI_execp() failed in cleanupListener()"); + + for (i = 0; i < SPI_processed; i++) + { + pid = DatumGetInt32(SPI_getbinval(SPI_tuptable->vals[i], + SPI_tuptable->tupdesc, 2, &isnull)); + if (kill(pid, 0) < 0) + { + if (errno == ESRCH) + { + relname = SPI_getvalue(SPI_tuptable->vals[i], + SPI_tuptable->tupdesc, 1); + + elog(NOTICE, "Slony-I: removing stale pg_listener entry " + "for pid %d, relname %s", pid, relname); + Async_Unlisten(relname, pid); + } + } + } + + SPI_finish(); + + return (Datum)0; +} + + static char * slon_quote_literal(char *str) { Index: local_listen.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/local_listen.c,v retrieving revision 1.23 retrieving revision 1.24 diff -Lsrc/slon/local_listen.c -Lsrc/slon/local_listen.c -u -w -r1.23 -r1.24 --- src/slon/local_listen.c +++ src/slon/local_listen.c @@ -69,8 +69,10 @@ * Listen for local events */ slon_mkquery(&query1, + "select %s.cleanupListener(); " "listen \"_%s_Event\"; " "listen \"_%s_Restart\"; ", + rtcfg_namespace, rtcfg_cluster_name, rtcfg_cluster_name); res = PQexec(dbconn, dstring_data(&query1)); if (PQresultStatus(res) != PGRES_COMMAND_OK)
- Previous message: [Slony1-commit] By wieck: Added function cleanupListener(), which is called at slon
- Next message: [Slony1-commit] By darcyb: fix brain dead moment of forgetting test returns 0 on GOOD
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list