DBIx-Connector-Retry-MySQL
view release on metacpan or search on metacpan
lib/DBIx/Connector/Retry/MySQL.pm view on Meta::CPAN
package DBIx::Connector::Retry::MySQL;
# ABSTRACT: MySQL-specific DBIx::Connector with retry support
use version;
our $VERSION = 'v1.0.1'; # VERSION
use strict;
use warnings;
use Moo;
extends 'DBIx::Connector::Retry';
use Scalar::Util qw( weaken );
use Storable qw( dclone );
use Types::Standard qw( Bool HashRef InstanceOf ClassName );
use Types::Common::Numeric qw( PositiveOrZeroNum PositiveOrZeroInt );
use Time::HiRes qw( sleep );
use Algorithm::Backoff::RetryTimeouts;
use DBIx::ParseError::MySQL;
use namespace::clean; # don't export the above
#pod =head1 SYNOPSIS
#pod
#pod my $conn = DBIx::Connector::Retry::MySQL->new(
#pod connect_info => [ 'dbi:Driver:database=foobar', $user, $pass, \%args ],
#pod retry_debug => 1,
#pod timer_options => {
#pod # Default options from Algorithm::Backoff::RetryTimeouts
#pod max_attempts => 8,
#pod max_actual_duration => 50,
#pod jitter_factor => 0.1,
#pod timeout_jitter_factor => 0.1,
#pod adjust_timeout_factor => 0.5,
#pod min_adjust_timeout => 5,
#pod # ...among others
#pod },
#pod );
#pod
#pod # Keep retrying/reconnecting on errors
#pod my ($count) = $conn->run(ping => sub {
#pod $_->do('UPDATE foobar SET updated = 1 WHERE active = ?', undef, 'on');
#pod $_->selectrow_array('SELECT COUNT(*) FROM foobar WHERE updated = 1');
#pod });
#pod
#pod my ($count) = $conn->txn(fixup => sub {
#pod $_->selectrow_array('SELECT COUNT(*) FROM barbaz');
#pod });
#pod
#pod # Plus everything else in DBIx::Connector::Retry and DBIx::Connector
#pod
#pod =head1 DESCRIPTION
#pod
#pod DBIx::Connector::Retry::MySQL is a subclass of L<DBIx::Connector::Retry> that will
#pod explicitly retry on MySQL-specific transient error messages, as identified by
#pod L<DBIx::ParseError::MySQL>, using L<Algorithm::Backoff::RetryTimeouts> as its retry
#pod algorithm. This connector should be much better at handling deadlocks, connection
#pod errors, and Galera node flips to ensure the transaction always goes through.
#pod
#pod It is essentially a DBIx::Connector version of L<DBIx::Class::Storage::DBI::mysql::Retryable>.
#pod
#pod =head1 INHERITED ATTRIBUTES
#pod
#pod This inherits all of the attributes of L<DBIx::Connector::Retry>:
#pod
#pod =head2 L<connect_info|DBIx::Connector::Retry/connect_info>
#pod
#pod =head2 L<mode|DBIx::Connector::Retry/mode>
#pod
#pod =head2 L<disconnect_on_destroy|DBIx::Connector::Retry/disconnect_on_destroy>
#pod
#pod =head2 max_attempts
( run in 0.499 second using v1.01-cache-2.11-cpan-39bf76dae61 )