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.
This commit is contained in:
parent
663476919c
commit
f59175d72f
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user