Commit 2e99a429 authored by Leo Gordon's avatar Leo Gordon
Browse files

added a new protected_prepare_execute() method to avoid deadlocks and used it...

added a new protected_prepare_execute() method to avoid deadlocks and used it twice in AnalysisJobAdaptor, to fix Stephen's deadlocks
parent 0ec4ee16
......@@ -396,9 +396,8 @@ sub increase_semaphore_count_for_jobid { # used in semaphore propagation
WHERE job_id=? AND status='SEMAPHORED'
};
my $sth = $self->prepare($sql);
$sth->execute($inc, $jobid);
$sth->finish;
# This particular query is infamous for collisions and 'deadlock' situations; let's wait and retry:
$self->dbc->protected_prepare_execute( $sql, $inc, $jobid );
}
......@@ -429,23 +428,8 @@ sub update_status {
$sql .= " WHERE job_id='".$job->dbID."' ";
# This particular query is infamous for collisions and 'deadlock' situations; let's make them wait and retry.
foreach (0..3) {
eval {
my $sth = $self->prepare($sql);
$sth->execute();
$sth->finish;
1;
} or do {
if($@ =~ /Deadlock found when trying to get lock; try restarting transaction/) { # ignore this particular error
sleep 1;
next;
}
die $@; # but definitely report other errors
};
last;
}
die "After 3 retries still in a deadlock: $@" if($@);
# This particular query is infamous for collisions and 'deadlock' situations; let's wait and retry:
$self->dbc->protected_prepare_execute( $sql );
}
......
......@@ -71,5 +71,29 @@ sub url {
}
sub protected_prepare_execute { # try to resolve certain mysql "Deadlocks" by trying again (a useful workaround even in mysql 5.1.61)
my $self = shift @_;
my $sql = shift @_;
my $retries = 3;
foreach (0..$retries) {
eval {
my $sth = $self->prepare($sql);
$sth->execute( @_ );
$sth->finish;
1;
} or do {
if($@ =~ /Deadlock found when trying to get lock; try restarting transaction/) { # ignore this particular error
sleep 1;
next;
}
die $@; # but definitely report other errors
};
last;
}
die "After $retries retries still in a deadlock: $@" if($@);
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment