Handle deadlocks properly in query_table.pl.

This commit is contained in:
vagrant
2012-11-21 07:57:25 -08:00
parent 537b36c73c
commit e37d59877f

View File

@@ -22,7 +22,7 @@ my $dbh = DBI->connect(
{RaiseError => 1, AutoCommit => 0, ShowErrorStatement => 1, PrintError => 0}, {RaiseError => 1, AutoCommit => 0, ShowErrorStatement => 1, PrintError => 0},
); );
$sleep ||= 0.001; $sleep ||= 0.01;
my $cnt = 0; my $cnt = 0;
my (@del, %del); my (@del, %del);
@@ -32,8 +32,14 @@ my (@ins, %ins);
use constant TYPE_DELETE => 1; use constant TYPE_DELETE => 1;
use constant TYPE_UPDATE => 2; use constant TYPE_UPDATE => 2;
my $start_xa = "START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */"; sub new_transaction {
$dbh->do($start_xa); @del = ();
@ins = ();
@upd = ();
$cnt = 0;
$dbh->do("START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */");
}
sub commit { sub commit {
eval { eval {
@@ -41,19 +47,17 @@ sub commit {
}; };
if ( $EVAL_ERROR ) { if ( $EVAL_ERROR ) {
Test::More::diag($EVAL_ERROR); Test::More::diag($EVAL_ERROR);
$dbh->do("ROLLBACK");
} }
else { else {
map { $del{$_}++ } @del; map { $del{$_}++ } @del;
map { $ins{$_}++ } @ins; map { $ins{$_}++ } @ins;
map { $upd{$_}++ } @upd; map { $upd{$_}++ } @upd;
} }
@del = (); new_transaction();
@ins = ();
@upd = ();
$cnt = 0;
} }
new_transaction(); # first transaction
for my $i ( 1..5_000 ) { for my $i ( 1..5_000 ) {
last if -f $stop_file; last if -f $stop_file;
my $id = 0; my $id = 0;
@@ -87,15 +91,16 @@ for my $i ( 1..5_000 ) {
}; };
if ( $EVAL_ERROR ) { if ( $EVAL_ERROR ) {
Test::More::diag($EVAL_ERROR); Test::More::diag($EVAL_ERROR);
sleep $sleep; new_transaction();
} }
# COMMIT every N statements. With PXC this can fail. # COMMIT every N statements. With PXC this can fail.
if ( $cnt++ > 5 ) { if ( $cnt++ > 5 ) {
commit(); commit();
sleep($sleep); new_transaction();
$dbh->do($start_xa);
} }
sleep($sleep);
} }
commit(); commit();