gnucash-devel  

Re: Patch for Bug 608032 - MySQL timeout and no attempt reconnect

Phil Longstaff
Thu, 04 Feb 2010 15:06:14 -0800

On Thu, 2010-02-04 at 22:26 +0100, Geert Janssens wrote:
> On Thursday 4 February 2010, Tom Van Braeckel wrote:
> > > 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.
> > 
> Hmm, after giving it some more thought, I think I know why Phil used the 
> string in the first place: MySQL is not the only database supported by dbi. 
> Error code 2006 in MySQL may mean something different in SQLite or Postgresql.
> 
> So using the number only, we risk that a Postgres user gets unexpected 
> behavior if he hits a 2006 error.
> 
> I find your reference to mysql_error_fn very interesting. This is the 
> function 
> that is called whenever something goes wrong when accessing the database, and 
> it is specific to mysql. I wonder if you can't reuse this function instead to 
> handle the reconnection.

This is why I would have a generic "you need to reconnect" flag which is
set by mysql_error_fn if error 2006 happens, is set by pgsql_error_fn
when ... happens, etc.

The error function could do the reconnect, but doesn't have enough
context to redo the operation which encountered the error.

Phil

_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel