Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 64F33475A75 for ; Thu, 22 Aug 2002 15:37:50 -0400 (EDT) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 5F7834759F5 for ; Thu, 22 Aug 2002 15:37:49 -0400 (EDT) Received: by news.hub.org (Postfix, from userid 8) id DE36C3819D3; Thu, 22 Aug 2002 15:37:48 -0400 (EDT) From: Gerhard Hintermayer X-Newsgroups: comp.databases.postgresql.interfaces Subject: Re: libpgtcl modifications Date: Thu, 22 Aug 2002 21:30:09 -0700 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 97 Message-ID: <3D65BA51.20008@inode.at> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010107030608010200000900" X-Complaints-To: news@hub.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: en-us, en To: pgsql-interfaces@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/72 X-Sequence-Number: 3034 This is a multi-part message in MIME format. --------------010107030608010200000900 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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 --------------010107030608010200000900 Content-Type: application/x-gunzip; name="patch_conn_loss.gz" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="patch_conn_loss.gz" H4sICPiyZT0AA3BhdGNoX2Nvbm5fbG9zcwClWOtz2kYQ/2z+ig2daQQVtgUY 7BDHkzo0w9ST4EfaD03Gc5FOoEaWyJ1ETBP/7929hzgMtpPYYwPW7Xt/+zii JI6hJWCWy2IiuPyctvrb7e2glYtksiNFuJNkBRcxC7ncSZOPs0kRpjvqdTtc 43qIoRbsdViw1/WDvf3aC9iiv4swvTwWnBX8OL+6YlnkKQEznw7pB6A+m1zm 2WWYZxkPiwQ/prmUdYdivInAOfeO04RnxStWsAa8eXdy4oOnFF9Fr3jKCz4W eQhNfdYYoJ17YdDbrT3X9o0/TZBgnkTcGgf1MblUxw/BdqeOLK1Wy7rzAHmX yKOfDzwaLX84+Jqp1g0OWLe9i5bWuu0AP3b8bnuPDN9pgizyGWR5kcQL4HOM F8i8FCGHJqalCZGKFMx4FiXZBKJEmoDDFM9TLpo7JGg8OUc5b5SYIUk5V0I8 Ik4idF0pozjp0Csa6R0dHTUGKCE46B2w4KDf9du7QY+IBS9KkcHF8cnl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a8IGdut5A5SEwR1Fa7uA 3h1Melefyrn73CDkbwRHyqSkZn1+euIixWxfGBbKTpykJgxy24HNE095A7+q 3vjH6GR4Ofxr+ObivLEynHcdlaPY0fJU4srBrTIf/i2xS2FGJ1zPkS/THPUW U5wRrlpliEYiYvPwcH0dCJYa6RWaMMbKJ5jsnJmqKHLgmSwFV5oczzV2Icq5 mlW4cTPcoJgwgsoMEZzhHjuFUm7rh1UztVq8lbvPir2NNdOst1Vdomm4ifFr Hpa4CiuIYwyk25F9mqcsW7gGVPyHqxqdmtU7lW0dt6gcMNG9hMW8wC18ylFi q2VWRIrIlOKRud3DKn5iUqGwbZqmegOFtSmbq7iH+Wyx6jHGnPYAbKShyg2e lRhIGwMJzIqhub224Cv8QFQqIa7gbcOmO/GyBr5zI7LkKyuR2YiWwvxKXZVb x++hduEes+4Gjs6Is/IR6es0/8jS4Zyl1YqytKVBOdCXNl0QZktSF4EoGgqR ixE22eVF4H1Gdybv/fp9X0X1fR1kKJJZ0ajbVY9k/Y66JiLHYlAivRVLbyq3 TLHd45UZM44HK9eGO4Vsrim3/G+q1g928NJ981aLM80dUbkywltOt6cJqJr8 HXN8bVKZWXlvk7dlluV3z2df2RTltE/b3SNbqHboNuENw1vHQem4e6RY4Mvk P57Hq+cG7CbKemxvz+j7msPN084lt40ZnMsqJfKUXFAcnjscTTL1gn36bvhu eHnxcnTScJKoNo3+ftjHpbff26OviManKF2WV3yUzcpiZYNZfjGk4nMfpb00 PbykKVA+bgf90V2fWGrdfdY9WC7Zah37cSgOav8DQxR6UHUUAAA= --------------010107030608010200000900--