9 A collection of functions that recognize common SQL errors of each parser.
11 These functions are typically called by DBConnection, CoreDBConnection and StatementHandle.
15 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
16 Copyright [2016-2024] EMBL-European Bioinformatics Institute
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
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.
29 Please subscribe to the
Hive mailing list: http:
34 package Bio::EnsEMBL::Hive::Utils::SQLErrorParser;
40 =head2 is_connection_lost
42 Description: Return 1
if the error message indicates the connection has been closed without us asking
46 sub is_connection_lost {
47 my ($driver, $error) = @_;
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
53 } elsif ($driver eq
'pgsql') {
54 return 1
if $error =~ /server closed the connection unexpectedly/;
61 =head2 is_server_too_busy
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)
68 sub is_server_too_busy {
69 my ($driver, $error) = @_;
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 ?)
84 Description: Return 1 if the error message indicates the current transaction had to be aborted because
90 my ($driver, $error) = @_;
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/;