On Nov 28, 2006, at 3:04 PM, Robert Landrum wrote:

Lev Lvovsky wrote:
In testing out persistent connections while using transactions, we've noticed that while in a loop which continuously begins and ends a transaction, killing the persistent connection which Apache::DBI is maintaining causes the still-running handler to report things like: error: DBD driver has not implemented the AutoCommit attribute at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/ DBI.pm line 1668.
1 -> STORE for DBD::mysql::db (DBI::db=HASH(0x9bf49cc)~INNER 'AutoCommit' 0) thr#915dc30
    --> do_error
Turning off AutoCommit failed error 21 recorded: Turning off AutoCommit failed
    <-- do_error
    STORE DBI::db=HASH(0x9bf49cc) 'AutoCommit' => 0
    !! ERROR: 21 CLEARED by call to begin_work method
-> begin_work for DBD::mysql::db (DBI::db=HASH(0x9b8678c) ~0x9bf49cc) thr#915dc30

So, your code is calling begin_work, fetching a value, storing a value, and committing? The store will fail if the database connection goes away, and it'll do so when it attempts communicate with the server to set AutoCommit to 0.

You might want to call $dbh->ping before calling your store routine. Either way, the way to make this fault tolerant is with eval.

Once you've determined that there's been a fault, and that the fault means that the database is down, try to reconnect. Continue to try to reconnect until the database comes back online. Then retry the original failed transaction.

Once you reconnect, the connection is persistent again. At least, that's been my experience with postgresql.

This is exactly what I've been thinking to do, but I've not seen anything within Apache::DBI that allows me to reconnect per se. How do I perform that action?

Also, forgive this question if it seems a little obtuse, but in the startup.pl file, I do something like this:

Apache::DBI->connect_on_init(...)

how do I then get the database handle that this establishes, so that I can pass it around to the mod_perl hanlders, and the subsequent DBI stuff? get_handlers() from the Apache2::ServerUtil class?

thanks very much!
-lev

Reply via email to