[Mimedefang] MySQL connection per slave
David F. Skoll
dfs at roaringpenguin.com
Mon Jul 14 08:39:00 EDT 2003
On Mon, 14 Jul 2003, Chris Masters wrote:
> Now this does not address error conditions such as
> disconnecting if the slave dies (make sure that
> connections don't remain open) or how to re-connect if
> the connection is lost during the slave lifecycle.
Our CanIt product works something like this:
undef $PersistentDatabaseConnection;
sub get_db_connection () {
if (defined($PersistentDatabaseConnection)) {
if (simple_query_succeeds($PersistentDatabaseConnection)) {
return $PersistentDatabaseConnection;
}
undef $PersistentDatabaseConnection;
}
$PersistentDatabaseConnection = connect_to_database();
return $PersistentDatabaseConnection;
}
Whenever we need the connection handle, we call get_db_connection().
This lazily maintains a per-slave connection. We also run a simple
query ("SELECT 1") on the connection to make sure it's alive before
returning it. You need to trade off how long you keep the connection
in a local variable vs. calling the function, because each function
call runs the simple query.
This doesn't require any changes to mimedefang.pl or any special
initialization function.
--
David.
More information about the MIMEDefang
mailing list