Tom Van Braeckel
Thu, 04 Feb 2010 08:26:47 -0800
> > On Thursday 4 February 2010, Tom Van Braeckel wrote: > > Hi guys, > > > > Here's another patch - my first *code* patch to GnuCash ! > > > > Rationale: When we try to open a database transaction, and the database > > reports that the "server has gone away", we try to reconnect before > failing > > hard. > > > Hi, > > Thanks you for your patch. It looks like a good start, but to my limited > knowledge of the sql backend, it seems incomplete. > > Here are my thoughts on the patch: > * you test for an error by comparing with a string. I think it would > probably > be safer and definitely be more efficient to simply test for the error > number > returned by dbi_conn_error. It's possible that the error strings returned > by > MySQL are translated into other languages on other systems, so your string > wouldn't always match. >
Thanks for the feedback !
You're right - I've corrected this in the attached patch and cleaned it up a
bit - hope you like it :-)
Note that such string-based error checking is also done in other places
(such as the "mysql_error_fn" function in gnc-backend-dbi.c), perhaps I'll
rectify that in a future patch.
>
> * what happens if not only the connection had timed out, but something else
> changed as well (an administrator changed the login password for example) ?
> I
> mean you don't check the results of dbi_connect or the second
> dbi_conn_queryf.
>
Good question. When that happens, GnuCash will behave as it did before
("Could not save..." error). There's room for improvement there (such as
asking for the new login password) but I feel like that's a different issue.
>
> * I also think there may be more useful places to check for a connection
> timeout, not only at the beginning of transactions. I found several
> occurences
> of dbi_conn_query and dbi_conn_queryf some of which could be called passed
> a
> timeout.
>
Well, normally these timeouts have high values (8 hours in a default MySQL
installation). Since a database query normally begins with a "begin
transaction" (as it should) and a transaction is typically very short lived,
I don't think the connection will ever time out between "begin transaction"
and an actual statement. Unless I'm missing something...
>
> As said in the beginning, I'm not the dbi expert, so maybe my comments are
> off
> mark or plain silly.
>
> > I've also attached it to the bug report, and taken the liberty to add
> > myself to the AUTHORS file.
> > I hope that's customary here, and I apologise if it's not...
> >
> I think this is quite ok. I would just like to ask you to put your name in
> alpabetical order which I think would put you between Richard -Gilligan-
> Uschold and Matthew Vanecek.
>
Done :-)
>
>
> > Thanks again for this great software,
> >
> Keep submitting patches !
> > Tom Van Braeckel
> > GSM: 0032 (0) 486 63 58 04
> >
>
> Geert
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel@gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
>
Index: AUTHORS
===================================================================
--- AUTHORS (revision 18610)
+++ AUTHORS (working copy)
@@ -269,6 +269,7 @@
Diane Trout <detr...@earthlink.net> scheme QIF import patch
Nicolae Turcan <nictur...@gmail.com> Romanian translation
Richard -Gilligan- Uschold <usch...@cs.ucf.edu> tax report & txf export
+Tom Van Braeckel <tomvanbraec...@gmail.com> MySQL timeout reconnect patch
Matthew Vanecek <mevane...@yahoo.com> lots of postgres backend work
Didier Vidal <didier-de...@9online.fr> various G2 fixes.
Oliver Vollmer <o...@mx.lihas.de> German account templates SKR03
Index: src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- src/backend/dbi/gnc-backend-dbi.c (revision 18610)
+++ src/backend/dbi/gnc-backend-dbi.c (working copy)
@@ -1377,6 +1377,14 @@
DEBUG( "BEGIN\n" );
result = dbi_conn_queryf( dbi_conn->conn, "BEGIN" );
+
+ /* Handle MySQL connection timeouts with reconnect */
+ if (result == NULL && dbi_conn_error( dbi_conn->conn, NULL ) == 2006 ) {
+ DEBUG( "MySQL server has gone away, reconnecting and retrying...\n" );
+ (void)dbi_conn_connect( dbi_conn->conn );
+ result = dbi_conn_queryf( dbi_conn->conn, "BEGIN" );
+ }
+
status = dbi_result_free( result );
if( status < 0 ) {
PERR( "Error in dbi_result_free() result\n" );
_______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel