ensembl-hive  2.6
SQLErrorParser.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 DESCRIPTION
8 
9 A collection of functions that recognize common SQL errors of each parser.
10 
11 These functions are typically called by DBConnection, CoreDBConnection and StatementHandle.
12 
13 =head1 LICENSE
14 
15 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
16 Copyright [2016-2024] EMBL-European Bioinformatics Institute
17 
18 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
19 You may obtain a copy of the License at
20 
21  http://www.apache.org/licenses/LICENSE-2.0
22 
23 Unless required by applicable law or agreed to in writing, software distributed under the License
24 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 See the License for the specific language governing permissions and limitations under the License.
26 
27 =head1 CONTACT
28 
29 Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
30 
31 =cut
32 
33 
34 package Bio::EnsEMBL::Hive::Utils::SQLErrorParser;
35 
36 use strict;
37 use warnings;
38 
39 
40 =head2 is_connection_lost
41 
42  Description: Return 1 if the error message indicates the connection has been closed without us asking
43 
44 =cut
45 
46 sub is_connection_lost {
47  my ($driver, $error) = @_;
48 
49  if ($driver eq 'mysql') {
50  return 1 if $error =~ /MySQL server has gone away/; # test by setting "SET SESSION wait_timeout=5;" and waiting for 10sec
51  return 1 if $error =~ /Lost connection to MySQL server during query/; # a variant of the same error
52 
53  } elsif ($driver eq 'pgsql') {
54  return 1 if $error =~ /server closed the connection unexpectedly/;
55 
56  }
57  return 0;
58 }
59 
60 
61 =head2 is_server_too_busy
62 
63  Description: Return 1 if the error message indicates we can't connect to the server because of a lack
64  of resources (incl. available connections)
65 
66 =cut
67 
68 sub is_server_too_busy {
69  my ($driver, $error) = @_;
70 
71  if ($driver eq 'mysql') {
72  return 1 if $error =~ /Could not connect to database.+?failed: Too many connections/s; # problem on server side (configured with not enough connections)
73  return 1 if $error =~ /Could not connect to database.+?failed: Can't connect to \w+? server on '.+?' \(99\)/s; # problem on client side (cooling down period after a disconnect)
74  return 1 if $error =~ /Could not connect to database.+?failed: Can't connect to \w+? server on '.+?' \(110\)/s; # problem on server side ("Connection timed out"L the server is temporarily dropping connections until it reaches a reasonable load)
75  return 1 if $error =~ /Could not connect to database.+?failed: Lost connection to MySQL server at 'reading authorization packet', system error: 0/s; # problem on server side (server too busy ?)
76 
77  }
78  return 0;
79 }
80 
81 
82 =head2 is_deadlock
83 
84  Description: Return 1 if the error message indicates the current transaction had to be aborted because
85  of concurrency issues
86 
87 =cut
88 
89 sub is_deadlock {
90  my ($driver, $error) = @_;
91 
92  if ($driver eq 'mysql') {
93  return 1 if $error =~ /Deadlock found when trying to get lock; try restarting transaction/;
94  return 1 if $error =~ /Lock wait timeout exceeded; try restarting transaction/;
95  }
96  return 0;
97 }
98 
99 
100 1;
Bio::EnsEMBL::Hive::Utils::SQLErrorParser
Definition: SQLErrorParser.pm:12
Bio::EnsEMBL::Hive::Version
Definition: Version.pm:19
Bio::EnsEMBL::Hive
Definition: Hive.pm:38