Skip site navigation (1) Skip section navigation (2)

Re: libpgtcl modifications

From: Gerhard Hintermayer <g(dot)hintermayer(at)inode(dot)at>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: libpgtcl modifications
Date: 2002-08-23 04:30:09
Message-ID: 3D65BA51.20008@inode.at (view raw or flat)
Thread:
Lists: pgsql-committerspgsql-interfacespgsql-patches
Revision 2 was not so quick, but also not so dirty. Here's my first draft.
I have modified:
- Version number of Pgtcl changed to 1.4 (to reflect the additional command)
- added a command pg_on_connection_loss
   Syntax: pg_on_connection_loss conn ?callback?
   Use no callback parameter to query the actuall callback script and 
with parameter to set/change callback. The callback is evaluated 
whenever the connection to the backend gets lost (eof condition ?).

I do this by checking for a false return value from PQconsumeInput. 
Today I did some quick testing, no segfaults, no errors. Broken backends 
are detected both in idle connections and when you're in a COPY command 
(these are the two possibilities, where PQconsumeInput is called).
I'm using the same readable fileevent on the database connection as 
pg_listen does internally. The structure Pg_ConnectionId was extended by 
two fields : char *conn_loss to store the callback and Tcl_Interp 
*interp to store the interpreter, in which context the callback will be 
  evaluated.
Can someone with more experience on Tcl event programming take a look at 
this, I mananged to write some Tcl extensions, but am new to modifying 
the Tcl event-loop. (what I did, was copying most of the pg_listen stuff).
Basically  PgStartNotifyEventSource() is called, when a callback proc is 
supplied to pg_on_connection_loss, which (unmodified) does install a 
readable fileevent on the db connection, then I check for false return 
value of PQconsumeInput and add a ConnLossEvent type to the event queue.
(pg_)listen callbacks are deleted immediately from the the event queue 
when the db connection is broken, just like in the unpatch version. What 
  This a point worth to discuss: Which commands will dump core when used 
in the disconnect handler ? pg_disconnect works, but the best thing 
might be to invoke pg_disconnect as the first command  within the 
disconnect handler per default (in C code, not in Tcl) so possible 
subsequent operations on the just closed connection would at least 
trigger a "... is not a valid postgresql connection" error, but not run 
into any segfaults.

I will do some more testing tomorrow, but since I only can post via 
google at work, I'd like to get some feedback more quickly.

Gerhard

PS: I need my patch also for an older version of Postgresql (7.0.2), can 
I copy the whole libpgtcl directory into the 7.0.2 source path without 
any risk ?

-- 
Gerhard Hintermayer
http://www.inode.at/g.hintermayer

Attachment: patch_conn_loss.gz
Description: application/x-gunzip (1.8 KB)

In response to

pgsql-committers by date

Next:From: Tatsuo IshiiDate: 2002-08-23 08:19:49
Subject: pgsql-server/contrib/pgstattuple README.pgstat ...
Previous:From: Bruce Momjian - CVSDate: 2002-08-23 04:27:19
Subject: pgsql-server/doc/src/sgml syntax.sgml

pgsql-interfaces by date

Next:From: Greg CopelandDate: 2002-08-23 12:47:56
Subject: Re: [HACKERS] ODBC Driver moved to GBorg ...
Previous:From: Marc G. FournierDate: 2002-08-22 22:46:03
Subject: ODBC Driver moved to GBorg ...

pgsql-patches by date

Next:From: Bruce MomjianDate: 2002-08-23 04:35:43
Subject: Re: Point in time recovery 20020822_01_pitr.patch
Previous:From: Tom LaneDate: 2002-08-23 04:29:42
Subject: Re: Point in time recovery 20020822_01_pitr.patch

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group