DBIx-TxnPool

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

  Parameters:
    dbh (Required)
        The dbh to be needed for begin_work & commit method (wrap in a
        transaction).

    size (Optional)
        The size of pool when a commit method will be called when feeding
        reaches the same size.

    block_signals (Optional)
        An arrayref of signals (strings) which should be blocked in slippery
        places for this *pool*. Defaults are [ qw( TERM INT ) ]. You can
        change globaly this list by setting: "$DBIx::TxnPool::BlockSignals =
        [ qw( TERM INT ALARM ... ) ]". For details to see here "SIGNAL
        HANDLING"

    max_repeated_deadlocks (Optional)
        The limit of consecutive deadlocks. The default is 5. After limit to
        be reached the "add" throws exception.

METHODS

lib/DBIx/TxnPool.pm  view on Meta::CPAN

=item dbh B<(Required)>

The dbh to be needed for begin_work & commit method (wrap in a transaction).

=item size B<(Optional)>

The size of pool when a commit method will be called when feeding reaches the same size.

=item block_signals B<(Optional)>

An arrayref of signals (strings) which should be blocked in slippery places for
this I<pool>. Defaults are [ qw( TERM INT ) ]. You can change globaly this list
by setting: C<< $DBIx::TxnPool::BlockSignals = [ qw( TERM INT ALARM ... ) ] >>.
For details to see here L</"SIGNAL HANDLING">

=item max_repeated_deadlocks B<(Optional)>

The limit of consecutive deadlocks. The default is 5. After limit to be reached
the L</add> throws exception.

=back

xt/01_deadlock_demonstration.t  view on Meta::CPAN

b:
    $dbh->begin_work() or die $dbh->errstr;
    $dbh->do( "UPDATE $table SET b=2 WHERE a=2" );

ab:
    if ( ( procname() )[1] eq 'a' ) {
        $dbh->do( "UPDATE $table SET b=1 WHERE a=2" );
    }
    else {
        # Small transactions are preferable for breaking by MySQL: http://dev.mysql.com/doc/refman/5.5/en/innodb-deadlock-detection.html
        # This transaction is small here because the transaction from 'a' already locked 2 rows but this only one row
        dies_ok {
            select( undef, undef, undef, 0.5 );
            $dbh->do( "UPDATE $table SET b=2 WHERE a=1" );
        };
        ok( $DBI::err == 1213 );
    }
a:
    $dbh->commit or die $dbh->errstr;

b:



( run in 0.730 second using v1.01-cache-2.11-cpan-49f99fa48dc )