Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7214a8

Browse files
committed
What I have done for libpgtcl:
Everytime if I do PQconsumeInput (when the backend channel getsreadable) I check for the return value. (0 == error) and generate anotification manually, e.g. fixed string connection_closed) and pass it to theTCL event queue. The only other thing I had to do is to comment out removingall pending events in PgStopNotifyEventSource whenever the connection wasunexpectedly closed (so the manually generated event will not be deleted).A broken backend connection triggers a notify event to the client (fixednotification string "connection_closed") so proper action can be taken to switchto another database server etc. Remember that this is event driven. If you haveapplications, that have idle database connections most of the time, you'll getimmediate feedback of a dying server. Upon connection to the server issue apg_notify for notify event "connection_closed" and whenever the backend crashes(which it does do in very very rare cases) you get an event driven recovery. (ofcourse the Tcl-Event loop has to be processed). Issuing a notification"connection_closed" on a still working database could be used for switching toanother db-server (which I've actually impelemented right now).Gerhard Hintermayer
1 parentb813554 commitb7214a8

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

‎src/interfaces/libpgtcl/pgtclCmds.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.62 2002/06/20 20:29:53 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.63 2002/08/17 12:19:31 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -419,8 +419,11 @@ Pg_disconnect(ClientData cData, Tcl_Interp *interp, int argc, char *argv[])
419419

420420
#ifTCL_MAJOR_VERSION >=8
421421
conn=PgGetConnectionId(interp,argv[1],&connid);
422-
if (connid->notifier_channel!=NULL)
422+
if (connid->notifier_channel!=NULL) {
423+
/* stop listening for NOTIFY events on that channel */
424+
PgStopNotifyEventSource(connid,1);
423425
Tcl_UnregisterChannel(interp,connid->notifier_channel);
426+
}
424427
#endif
425428

426429
returnTcl_UnregisterChannel(interp,conn_chan);

‎src/interfaces/libpgtcl/pgtclId.c‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.30 2002/06/20 20:29:53 momjian Exp $
16+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.31 2002/08/17 12:19:31 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -277,7 +277,7 @@ PgDelConnectionId(DRIVER_DEL_PROTO)
277277
* Turn off the Tcl event source for this connection, and delete any
278278
* pending notify events.
279279
*/
280-
PgStopNotifyEventSource(connid);
280+
PgStopNotifyEventSource(connid,1);
281281

282282
/* Close the libpq connection too */
283283
PQfinish(connid->conn);
@@ -441,7 +441,7 @@ PgGetConnByResultId(Tcl_Interp *interp, char *resid_c)
441441
*mark='.';
442442
if (conn_chan&&Tcl_GetChannelType(conn_chan)==&Pg_ConnType)
443443
{
444-
Tcl_SetResult(interp,Tcl_GetChannelName(conn_chan),TCL_VOLATILE);
444+
Tcl_SetResult(interp,(char*)Tcl_GetChannelName(conn_chan),TCL_VOLATILE);
445445
returnTCL_OK;
446446
}
447447

@@ -611,7 +611,9 @@ PgNotifyTransferEvents(Pg_ConnectionId * connid)
611611
* closed socket descriptor.
612612
*/
613613
if (PQsocket(connid->conn)<0)
614-
PgStopNotifyEventSource(connid);
614+
/* do not remove any pending events, so that the virtual notification
615+
connection_closed will be processed */
616+
PgStopNotifyEventSource(connid,0);
615617
}
616618

617619
/*
@@ -675,7 +677,17 @@ Pg_Notify_FileHandler(ClientData clientData, int mask)
675677
* it internally to libpq; but it will clear the read-ready
676678
* condition).
677679
*/
678-
PQconsumeInput(connid->conn);
680+
if (!PQconsumeInput(connid->conn)) {
681+
NotifyEvent*event= (NotifyEvent*)ckalloc(sizeof(NotifyEvent));
682+
683+
PGnotify*closed= (PGnotify*)ckalloc(sizeof(PGnotify));
684+
strcpy(closed->relname,"connection_closed");
685+
event->header.proc=Pg_Notify_EventProc;
686+
event->info=*closed;
687+
event->connid=connid;
688+
Tcl_QueueEvent((Tcl_Event*)event,TCL_QUEUE_TAIL);
689+
ckfree((void*)closed);
690+
}
679691

680692
/* Transfer notify events from libpq to Tcl event queue. */
681693
PgNotifyTransferEvents(connid);
@@ -724,7 +736,7 @@ PgStartNotifyEventSource(Pg_ConnectionId * connid)
724736
}
725737

726738
void
727-
PgStopNotifyEventSource(Pg_ConnectionId*connid)
739+
PgStopNotifyEventSource(Pg_ConnectionId*connid,intremove_pending)
728740
{
729741
/* Remove the event source */
730742
if (connid->notifier_running)
@@ -743,5 +755,5 @@ PgStopNotifyEventSource(Pg_ConnectionId * connid)
743755
}
744756

745757
/* Kill any queued Tcl events that reference this channel */
746-
Tcl_DeleteEvents(NotifyEventDeleteProc, (ClientData)connid);
758+
if (remove_pending)Tcl_DeleteEvents(NotifyEventDeleteProc, (ClientData)connid);
747759
}

‎src/interfaces/libpgtcl/pgtclId.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $Id: pgtclId.h,v 1.18 2002/06/20 20:29:53 momjian Exp $
13+
* $Id: pgtclId.h,v 1.19 2002/08/17 12:19:31 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -44,7 +44,7 @@ extern PGresult *PgGetResultId(Tcl_Interp *interp, char *id);
4444
externvoidPgDelResultId(Tcl_Interp*interp,char*id);
4545
externintPgGetConnByResultId(Tcl_Interp*interp,char*resid);
4646
externvoidPgStartNotifyEventSource(Pg_ConnectionId*connid);
47-
externvoidPgStopNotifyEventSource(Pg_ConnectionId*connid);
47+
externvoidPgStopNotifyEventSource(Pg_ConnectionId*connid,intremove_pend);
4848
externvoidPgNotifyTransferEvents(Pg_ConnectionId*connid);
4949
externvoidPgNotifyInterpDelete(ClientDataclientData,Tcl_Interp*interp);
5050

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp