[jifty-devel] MySQL: Transparent reconnect

Jesse Vincent jesse at bestpractical.com
Wed Mar 7 14:06:55 EST 2007


Thanks. Applied.

Would you care for a commit bit, so you can commit improvements directly
in the future?

Best,
Jesse


On Sat, Feb 24, 2007 at 04:05:33AM +0200, Alexey Grebenschikov wrote:
> Hello Jesse,
> 
> On Fri, 2006-09-08 at 13:36 -0400, Jesse Vincent wrote:
> > So,
> > 
> > It makes me a little twitchy to start setting environment variables  
> > to get somewhat sketchy side-effects out of them. But I agree that  
> > there ought to be a way to get what you want. So, I've just  
> > refactored Jifty::DBI to allow you to stuff arbitrary arguments into  
> > the database driver connect hash, right next to "database" "user"  
> > "password" and "sid".  This will be in the next release of Jifty::DBI  
> > (and in svn as soon as I push.
> > 
> > How's that sound?
> > 
> > Jesse
> 
> We don't avoid that issues because mysql_auto_reconnect is attribute and
> doesn't set via DSN. I use mysql 5.0.32-Debian_3_log and Jifty (last
> checkout from svn). My investigation shows that we can set the attribute
> mysql_auto_reconnect only as follows: 
> 	$self->dbh->{mysql_auto_reconnect} = 1;
> 
> DBH ignores attributes in the DSN. For me i have written a simple patch.
> I would like to propose it. May be it will be useful. The patch do next:
> 
> - gets all attributes from 
> 	Jifty->config->framework('Database')->{Attributes}
> - sets them up when dbh is arrived.
> 
> etc/config.yml:
> 
>     Driver: mysql
>     Host: localhost
>     Attributes:
>       mysql_auto_reconnect: 1
> 
> 
> Thanks
> Alexey
> 

> Index: Handle.pm
> ===================================================================
> --- Handle.pm   (revision 2834)
> +++ Handle.pm   (working copy)
> @@ -86,12 +86,18 @@
>  
>      my %lc_db_config;
>      # Skip the non-dsn keys, but not anything else
> -    for (grep {!/^checkschema|version|recordbaseclass$/i} keys %db_config) {
> +    for (grep {!/^checkschema|version|recordbaseclass|attributes$/i} keys %db_config) {
>          $lc_db_config{lc($_)} = $db_config{$_};
>      }
>      $self->SUPER::connect( %lc_db_config , %args);
>      $self->{db_config} = { %lc_db_config , %args };
>      $self->dbh->{LongReadLen} = Jifty->config->framework('MaxAttachmentSize') || '10000000';
> +
> +    # setup attributes
> +    my $attributes = Jifty->config->framework('Database')->{Attributes} || {};
> +    for (keys %$attributes) {
> +        $self->dbh->{lc($_)} = $attributes->{$_};
> +    }
>  }
> 

> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel


-- 


More information about the jifty-devel mailing list