DBIx::PgLink::Roles::Reconnect - detect connection loss, reconnect and restart DBI call
The role wraps some calls to DBI methods so that operation that fails due to connection break ( server shutdown, network troubles, etc), is automatically reconnected.
Failed operation will be repeated if AutoCommit mode on (no transaction). If transaction in progress than exception always raised, but connection has restored anyway.
DBI calls that needs protection must be executed via
dbi_method in base Adapter class.
Adapter class that does the role must implement following methods:
Must check supplied exception and return true value for disconnection error and false for any 'normal' database error.
Must return true if there is transaction in progress.
Adapter class may implement following methods:
Return SQL query that always executed successfully ('SELECT 1').
Restore database session state (SET options, create temporary tables, etc).
$self->dbi_method($handle, $func_name, @_)
Execute $func_name method of $handle object (DBI database or statement handle). Check for disconnection error, reconnect and retry the function (unless in transaction).
Check if $exception is disconnection error and try to reconnect. If not $exception specified, can execute
always_valid_querySQL query to ensure the valid connection status.
Try to reconnect
reconnect_intervalpause between attempts. Die if connection cannot be established or timed out.
Max number of tries before giving up.
Seconds to sleep after reconnection attempt fails
Timeout (in seconds) for waiting the database to accept connection.
- All prepared statements are re-prepared at once, may cause heavy load
- Transaction retry does not implemented
Lazy prepare after reconnect (install subrole to Adapter::st)
Test reconnect timeout (SIGALRM) on different platforms
Alexey Sharafutdinov <firstname.lastname@example.org>
Based on DBIx::RetryOverDisconnects module by Oleg Pronin <email@example.com>
COPYRIGHT AND LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.