From f59175d72ff9b31b4bb486e5396815636abbcfe0 Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Thu, 6 Oct 2005 21:30:39 +0000 Subject: [PATCH] Minor API cleanup for async notifications: we can only register the current backend in pg_listener, so there is little point in making the PID to register part of async.c's public API. Other minor tweaks. --- src/backend/commands/async.c | 33 ++++++++++++--------------------- src/backend/tcop/utility.c | 6 +++--- src/include/commands/async.h | 8 ++++---- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index e2c6203891..da13378896 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.124 2005/08/20 00:39:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.125 2005/10/06 21:30:32 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -146,13 +146,10 @@ static void ClearPendingNotifies(void); * Actual notification happens during transaction commit. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * - * Results: - * XXX - * *-------------------------------------------------------------- */ void -Async_Notify(char *relname) +Async_Notify(const char *relname) { if (Trace_notify) elog(DEBUG1, "Async_Notify(%s)", relname); @@ -180,11 +177,8 @@ Async_Notify(char *relname) * * This is executed by the SQL listen command. * - * Register a backend (identified by its Unix PID) as listening - * on the specified relation. - * - * Results: - * XXX + * Register the current backend as listening on the specified + * relation. * * Side effects: * pg_listener is updated. @@ -192,7 +186,7 @@ Async_Notify(char *relname) *-------------------------------------------------------------- */ void -Async_Listen(char *relname, int pid) +Async_Listen(const char *relname) { Relation lRel; HeapScanDesc scan; @@ -203,7 +197,7 @@ Async_Listen(char *relname, int pid) bool alreadyListener = false; if (Trace_notify) - elog(DEBUG1, "Async_Listen(%s,%d)", relname, pid); + elog(DEBUG1, "Async_Listen(%s,%d)", relname, MyProcPid); lRel = heap_open(ListenerRelationId, ExclusiveLock); @@ -213,7 +207,7 @@ Async_Listen(char *relname, int pid) { Form_pg_listener listener = (Form_pg_listener) GETSTRUCT(tuple); - if (listener->listenerpid == pid && + if (listener->listenerpid == MyProcPid && strncmp(NameStr(listener->relname), relname, NAMEDATALEN) == 0) { alreadyListener = true; @@ -241,7 +235,7 @@ Async_Listen(char *relname, int pid) i = 0; values[i++] = (Datum) relname; - values[i++] = (Datum) pid; + values[i++] = (Datum) MyProcPid; values[i++] = (Datum) 0; /* no notifies pending */ tuple = heap_formtuple(RelationGetDescr(lRel), values, nulls); @@ -271,19 +265,16 @@ Async_Listen(char *relname, int pid) * * This is executed by the SQL unlisten command. * - * Remove the backend from the list of listening backends + * Remove the current backend from the list of listening backends * for the specified relation. * - * Results: - * XXX - * * Side effects: * pg_listener is updated. * *-------------------------------------------------------------- */ void -Async_Unlisten(char *relname, int pid) +Async_Unlisten(const char *relname) { Relation lRel; HeapScanDesc scan; @@ -297,7 +288,7 @@ Async_Unlisten(char *relname, int pid) } if (Trace_notify) - elog(DEBUG1, "Async_Unlisten(%s,%d)", relname, pid); + elog(DEBUG1, "Async_Unlisten(%s,%d)", relname, MyProcPid); lRel = heap_open(ListenerRelationId, ExclusiveLock); @@ -306,7 +297,7 @@ Async_Unlisten(char *relname, int pid) { Form_pg_listener listener = (Form_pg_listener) GETSTRUCT(tuple); - if (listener->listenerpid == pid && + if (listener->listenerpid == MyProcPid && strncmp(NameStr(listener->relname), relname, NAMEDATALEN) == 0) { /* Found the matching tuple, delete it */ diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 10256bbb32..dd89832da8 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.243 2005/08/01 04:03:57 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.244 2005/10/06 21:30:36 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -823,7 +823,7 @@ ProcessUtility(Node *parsetree, { ListenStmt *stmt = (ListenStmt *) parsetree; - Async_Listen(stmt->relation->relname, MyProcPid); + Async_Listen(stmt->relation->relname); } break; @@ -831,7 +831,7 @@ ProcessUtility(Node *parsetree, { UnlistenStmt *stmt = (UnlistenStmt *) parsetree; - Async_Unlisten(stmt->relation->relname, MyProcPid); + Async_Unlisten(stmt->relation->relname); } break; diff --git a/src/include/commands/async.h b/src/include/commands/async.h index b893771b0f..7844043f54 100644 --- a/src/include/commands/async.h +++ b/src/include/commands/async.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/async.h,v 1.28 2005/06/17 22:32:49 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/async.h,v 1.29 2005/10/06 21:30:39 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -16,9 +16,9 @@ extern bool Trace_notify; /* notify-related SQL statements */ -extern void Async_Notify(char *relname); -extern void Async_Listen(char *relname, int pid); -extern void Async_Unlisten(char *relname, int pid); +extern void Async_Notify(const char *relname); +extern void Async_Listen(const char *relname); +extern void Async_Unlisten(const char *relname); /* perform (or cancel) outbound notify processing at transaction commit */ extern void AtCommit_Notify(void);