Commit 4be8a0fb authored by Leo Gordon's avatar Leo Gordon
Browse files

log deadlocks and retries in log_message

parent bbd03412
......@@ -116,11 +116,13 @@ sub protected_prepare_execute { # try to resolve certain mysql "Deadlocks" b
my $self = shift @_;
my $sql = shift @_;
my $retries = 3;
my $attempts = 4;
my $sleep_secs = 1;
my $log_message_adaptor;
my $retval;
foreach (0..$retries) {
foreach my $attempt (1..$attempts) {
eval {
my $sth = $self->prepare($sql);
$retval = $sth->execute( @_ );
......@@ -128,14 +130,25 @@ sub protected_prepare_execute { # try to resolve certain mysql "Deadlocks" b
1;
} or do {
if($@ =~ /Deadlock found when trying to get lock; try restarting transaction/) { # ignore this particular error
sleep 1;
unless($log_message_adaptor) {
require Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
my $slave_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
-dbconn => $self,
-no_sql_schema_version_check => 1,
);
$log_message_adaptor = $slave_dba->get_LogMessageAdaptor();
}
$log_message_adaptor->store_hive_message( "Caught a DEADLOCK when trying to execute '$sql' (attempt #$attempt), retrying in $sleep_secs sec", 0 );
sleep $sleep_secs;
next;
}
die $@; # but definitely report other errors
};
last;
}
die "After $retries retries the query '$sql' is still in a deadlock: $@" if($@);
die "After $attempts attempts the query '$sql' is still in a deadlock: $@" if($@);
return $retval;
}
......
......@@ -90,5 +90,21 @@ sub store_worker_message {
$sth->finish();
}
1;
sub store_hive_message {
my ($self, $msg, $is_error) = @_;
chomp $msg; # we don't want that last "\n" in the database
my $table_name = $self->table_name();
# Note: the timestamp 'time' column will be set automatically
my $sql = qq{
INSERT INTO $table_name (status, msg, is_error) VALUES ('UNKNOWN', ?, ?)
};
my $sth = $self->prepare( $sql );
$sth->execute( $msg, $is_error ? 1 : 0 );
$sth->finish();
}
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