line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::TryAgain::db; |
2
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
97
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2396
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our @ISA = 'DBI::db'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our %defaults = ( |
8
|
|
|
|
|
|
|
private_dbix_try_again_algorithm => 'fibonacci', # or exponential or linear or constant |
9
|
|
|
|
|
|
|
private_dbix_try_again_max_retries => 5, |
10
|
|
|
|
|
|
|
private_dbix_try_again_on_messages => [ qr/database is locked/i ], |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub try_again_algorithm { |
14
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
15
|
1
|
|
|
|
|
3
|
my $attr = 'private_dbix_try_again_algorithm'; |
16
|
1
|
50
|
33
|
|
|
21
|
return $self->{$attr} || $defaults{$attr} unless @_; |
17
|
0
|
|
|
|
|
0
|
$self->{$attr} = shift; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub try_again_max_retries { |
21
|
4
|
|
|
4
|
0
|
9140
|
my $self = shift; |
22
|
4
|
|
|
|
|
7
|
my $attr = 'private_dbix_try_again_max_retries'; |
23
|
4
|
100
|
66
|
|
|
60
|
return $self->{$attr} || $defaults{$attr} unless @_; |
24
|
2
|
|
|
|
|
22
|
$self->{$attr} = shift; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub try_again_on_messages { |
28
|
2
|
|
|
2
|
0
|
13
|
my $self = shift; |
29
|
2
|
|
|
|
|
5
|
my $attr = 'private_dbix_try_again_on_messages'; |
30
|
2
|
100
|
33
|
|
|
33
|
return $self->{$attr} || $defaults{$attr} unless @_; |
31
|
1
|
50
|
|
|
|
8
|
die "messages should be an array ref" if ref($_[0]) ne 'ARRAY'; |
32
|
1
|
|
|
|
|
8
|
$self->{$attr} = shift; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub try_again_on_prepare { |
36
|
18
|
|
|
18
|
0
|
43
|
my $self = shift; |
37
|
18
|
|
|
|
|
38
|
my $attr = 'private_dbix_try_again_on_prepare'; |
38
|
18
|
100
|
66
|
|
|
220
|
return $self->{$attr} || $defaults{$attr} unless @_; |
39
|
1
|
|
|
|
|
7
|
$self->{$attr} = shift; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _should_try_again { |
43
|
8
|
|
|
8
|
|
1580
|
my $self = shift; |
44
|
8
|
50
|
|
|
|
29
|
return unless $self->try_again_on_prepare; |
45
|
8
|
|
|
|
|
60
|
return $self->DBIx::TryAgain::st::_should_try_again(@_); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _sleep { |
49
|
8
|
|
|
8
|
|
42
|
return shift->DBIx::TryAgain::st::_sleep(@_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub prepare { |
53
|
8
|
|
|
8
|
0
|
7831
|
my $self = shift; |
54
|
8
|
|
|
|
|
25
|
my @args = @_; |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
|
|
32
|
for (keys %defaults) { |
57
|
24
|
100
|
|
|
|
212
|
$self->{$_} = $defaults{$_} unless defined($self->{$_}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
8
|
|
|
|
|
70
|
my $sth = $self->SUPER::prepare(@args); |
61
|
|
|
|
|
|
|
|
62
|
8
|
100
|
|
|
|
1462
|
if ($self->try_again_on_prepare) { |
63
|
2
|
|
|
|
|
8
|
$self->_sleep('init'); |
64
|
2
|
|
|
|
|
12
|
$self->{private_dbix_try_again_tries} = 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
8
|
|
100
|
|
|
133
|
while (!$sth && $self->_should_try_again) { |
68
|
6
|
|
|
|
|
88
|
$self->{private_dbix_try_again_tries}++; |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
58
|
for ("DBIx::TryAgain [$$] prepare attempt number ".$self->{private_dbix_try_again_tries}."\n") { |
71
|
6
|
|
|
|
|
17
|
DBI->trace_msg($_); |
72
|
6
|
50
|
|
|
|
68
|
warn $_ if $self->{PrintError}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
6
|
|
|
|
|
22
|
$self->_sleep; |
76
|
6
|
|
|
|
|
143
|
$self->set_err(undef, undef); |
77
|
6
|
|
|
|
|
89
|
$sth = $self->SUPER::prepare(@args); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
8
|
100
|
|
|
|
37
|
return unless $sth; |
81
|
6
|
|
|
|
|
189
|
$sth->{$_} = $self->{$_} for keys %defaults; |
82
|
6
|
|
|
|
|
37
|
return $sth; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|