* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.80 2001/09/08 01:10:20 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.84 2002/05/05 00:03:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
+#include "storage/ipc.h"
#include "tcop/tcopprot.h"
#include "utils/fmgroids.h"
#include "utils/ps_status.h"
/* True if we've registered an on_shmem_exit cleanup */
static bool unlistenExitRegistered = false;
-bool Trace_notify = false;
+bool Trace_notify = false;
static void Async_UnlistenAll(void);
Async_Notify(char *relname)
{
if (Trace_notify)
- elog(DEBUG, "Async_Notify: %s", relname);
+ elog(LOG, "Async_Notify: %s", relname);
/* no point in making duplicate entries in the list ... */
- if (! AsyncExistsPendingNotify(relname))
+ if (!AsyncExistsPendingNotify(relname))
{
/*
- * The name list needs to live until end of transaction, so
- * store it in the top transaction context.
+ * The name list needs to live until end of transaction, so store
+ * it in the top transaction context.
*/
- MemoryContext oldcontext;
+ MemoryContext oldcontext;
oldcontext = MemoryContextSwitchTo(TopTransactionContext);
bool alreadyListener = false;
if (Trace_notify)
- elog(DEBUG, "Async_Listen: %s", relname);
+ elog(LOG, "Async_Listen: %s", relname);
lRel = heap_openr(ListenerRelationName, AccessExclusiveLock);
Form_pg_listener listener = (Form_pg_listener) GETSTRUCT(tuple);
if (listener->listenerpid == pid &&
- strncmp(NameStr(listener->relname), relname, NAMEDATALEN) == 0)
+ strncmp(NameStr(listener->relname), relname, NAMEDATALEN) == 0)
{
alreadyListener = true;
/* No need to scan the rest of the table */
if (alreadyListener)
{
heap_close(lRel, AccessExclusiveLock);
- elog(NOTICE, "Async_Listen: We are already listening on %s", relname);
+ elog(WARNING, "Async_Listen: We are already listening on %s", relname);
return;
}
}
if (Trace_notify)
- elog(DEBUG, "Async_Unlisten %s", relname);
+ elog(LOG, "Async_Unlisten %s", relname);
lRel = heap_openr(ListenerRelationName, AccessExclusiveLock);
Form_pg_listener listener = (Form_pg_listener) GETSTRUCT(tuple);
if (listener->listenerpid == pid &&
- strncmp(NameStr(listener->relname), relname, NAMEDATALEN) == 0)
+ strncmp(NameStr(listener->relname), relname, NAMEDATALEN) == 0)
{
/* Found the matching tuple, delete it */
simple_heap_delete(lRel, &tuple->t_self);
+
/*
- * We assume there can be only one match, so no need
- * to scan the rest of the table
+ * We assume there can be only one match, so no need to scan
+ * the rest of the table
*/
break;
}
ScanKeyData key[1];
if (Trace_notify)
- elog(DEBUG, "Async_UnlistenAll");
+ elog(LOG, "Async_UnlistenAll");
lRel = heap_openr(ListenerRelationName, AccessExclusiveLock);
tdesc = RelationGetDescr(lRel);
}
if (Trace_notify)
- elog(DEBUG, "AtCommit_Notify");
+ elog(LOG, "AtCommit_Notify");
/* preset data to update notify column to MyProcPid */
nulls[0] = nulls[1] = nulls[2] = ' ';
char *relname = NameStr(listener->relname);
int32 listenerPID = listener->listenerpid;
- if (! AsyncExistsPendingNotify(relname))
+ if (!AsyncExistsPendingNotify(relname))
continue;
if (listenerPID == MyProcPid)
{
/*
- * Self-notify: no need to bother with table update.
- * Indeed, we *must not* clear the notification field in
- * this path, or we could lose an outside notify, which'd
- * be bad for applications that ignore self-notify messages.
+ * Self-notify: no need to bother with table update. Indeed,
+ * we *must not* clear the notification field in this path, or
+ * we could lose an outside notify, which'd be bad for
+ * applications that ignore self-notify messages.
*/
if (Trace_notify)
- elog(DEBUG, "AtCommit_Notify: notifying self");
+ elog(LOG, "AtCommit_Notify: notifying self");
NotifyMyFrontEnd(relname, listenerPID);
}
else
{
if (Trace_notify)
- elog(DEBUG, "AtCommit_Notify: notifying pid %d",
+ elog(LOG, "AtCommit_Notify: notifying pid %d",
listenerPID);
/*
* If someone has already notified this listener, we don't
- * bother modifying the table, but we do still send a
- * SIGUSR2 signal, just in case that backend missed the
- * earlier signal for some reason. It's OK to send the
- * signal first, because the other guy can't read
- * pg_listener until we unlock it.
+ * bother modifying the table, but we do still send a SIGUSR2
+ * signal, just in case that backend missed the earlier signal
+ * for some reason. It's OK to send the signal first, because
+ * the other guy can't read pg_listener until we unlock it.
*/
if (kill(listenerPID, SIGUSR2) < 0)
{
/*
- * Get rid of pg_listener entry if it refers to a PID
- * that no longer exists. Presumably, that backend
- * crashed without deleting its pg_listener entries.
- * This code used to only delete the entry if
- * errno==ESRCH, but as far as I can see we should
- * just do it for any failure (certainly at least for
- * EPERM too...)
+ * Get rid of pg_listener entry if it refers to a PID that
+ * no longer exists. Presumably, that backend crashed
+ * without deleting its pg_listener entries. This code
+ * used to only delete the entry if errno==ESRCH, but as
+ * far as I can see we should just do it for any failure
+ * (certainly at least for EPERM too...)
*/
simple_heap_delete(lRel, &lTuple->t_self);
}
ClearPendingNotifies();
if (Trace_notify)
- elog(DEBUG, "AtCommit_Notify: done");
+ elog(LOG, "AtCommit_Notify: done");
}
/*
if (notifyInterruptEnabled)
{
-
/*
* I'm not sure whether some flavors of Unix might allow another
* SIGUSR2 occurrence to recursively interrupt this routine. To
{
/* Here, it is finally safe to do stuff. */
if (Trace_notify)
- elog(DEBUG, "Async_NotifyHandler: perform async notify");
+ elog(LOG, "Async_NotifyHandler: perform async notify");
ProcessIncomingNotify();
if (Trace_notify)
- elog(DEBUG, "Async_NotifyHandler: done");
+ elog(LOG, "Async_NotifyHandler: done");
}
}
}
else
{
-
/*
* In this path it is NOT SAFE to do much of anything, except
* this:
if (notifyInterruptOccurred)
{
if (Trace_notify)
- elog(DEBUG, "EnableNotifyInterrupt: perform async notify");
+ elog(LOG, "EnableNotifyInterrupt: perform async notify");
ProcessIncomingNotify();
if (Trace_notify)
- elog(DEBUG, "EnableNotifyInterrupt: done");
+ elog(LOG, "EnableNotifyInterrupt: done");
}
}
}
nulls[Natts_pg_listener];
if (Trace_notify)
- elog(DEBUG, "ProcessIncomingNotify");
+ elog(LOG, "ProcessIncomingNotify");
set_ps_display("async_notify");
/* Notify the frontend */
if (Trace_notify)
- elog(DEBUG, "ProcessIncomingNotify: received %s from %d",
+ elog(LOG, "ProcessIncomingNotify: received %s from %d",
relname, (int) sourcePID);
NotifyMyFrontEnd(relname, sourcePID);
set_ps_display("idle");
if (Trace_notify)
- elog(DEBUG, "ProcessIncomingNotify: done");
+ elog(LOG, "ProcessIncomingNotify: done");
}
/*
*/
}
else
- elog(NOTICE, "NOTIFY for %s", relname);
+ elog(INFO, "NOTIFY for %s", relname);
}
/* Does pendingNotifies include the given relname? */
ClearPendingNotifies(void)
{
/*
- * We used to have to explicitly deallocate the list members and nodes,
- * because they were malloc'd. Now, since we know they are palloc'd
- * in TopTransactionContext, we need not do that --- they'll go away
- * automatically at transaction exit. We need only reset the list head
- * pointer.
+ * We used to have to explicitly deallocate the list members and
+ * nodes, because they were malloc'd. Now, since we know they are
+ * palloc'd in TopTransactionContext, we need not do that --- they'll
+ * go away automatically at transaction exit. We need only reset the
+ * list head pointer.
*/
pendingNotifies = NIL;
}