line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Plugin::AnyCache::Backend::Replicator; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
11
|
use Mojo::Base 'MojoX::Plugin::AnyCache::Backend'; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub init { |
8
|
2
|
|
|
2
|
0
|
3
|
my ($self) = @_; |
9
|
2
|
|
|
|
|
22
|
$self->{nodes} = undef; |
10
|
2
|
|
|
|
|
6
|
$self->get_nodes; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub get_nodes { |
14
|
2
|
|
|
2
|
0
|
3
|
my ($self) = @_; |
15
|
|
|
|
|
|
|
|
16
|
2
|
50
|
|
|
|
7
|
if(!$self->{nodes}) { |
17
|
2
|
|
|
|
|
4
|
$self->{nodes} = []; |
18
|
2
|
|
|
|
|
54
|
$self->support_sync(1); |
19
|
2
|
|
|
|
|
62
|
$self->support_async(1); |
20
|
2
|
|
|
|
|
13
|
for my $node (@{$self->config->{nodes}}) { |
|
2
|
|
|
|
|
44
|
|
21
|
8
|
|
|
|
|
19
|
eval { |
22
|
8
|
|
|
|
|
469
|
eval "require $node->{backend};"; |
23
|
8
|
0
|
33
|
|
|
254
|
warn("Require failed: $@") if $self->config->{debug} && $@; |
24
|
8
|
|
|
|
|
84
|
my $backend = "$node->{backend}"->new; |
25
|
8
|
|
|
|
|
199
|
$backend->config($node); |
26
|
8
|
50
|
|
|
|
239
|
$self->support_sync(0) if !$backend->support_sync; |
27
|
8
|
50
|
|
|
|
219
|
$self->support_async(0) if !$backend->support_async; |
28
|
8
|
|
|
|
|
66
|
push @{$self->{nodes}}, $backend; |
|
8
|
|
|
|
|
20
|
|
29
|
|
|
|
|
|
|
}; |
30
|
8
|
50
|
|
|
|
23
|
die("Failed to create backend node $node->{backend}: $@") if $@; |
31
|
|
|
|
|
|
|
} |
32
|
2
|
0
|
33
|
|
|
40
|
warn "No support for sync or async operations" if !$self->support_sync && !$self->support_async; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
17
|
return @{$self->{nodes}}; |
|
2
|
|
|
|
|
9
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get { |
39
|
17
|
100
|
|
17
|
0
|
629
|
my $cb = ref($_[-1]) eq 'CODE' ? pop : undef; |
40
|
17
|
|
|
|
|
31
|
my ($self, $key) = @_; |
41
|
17
|
|
|
|
|
35
|
my $node = $self->{nodes}->[rand @{$self->{nodes}}]; |
|
17
|
|
|
|
|
68
|
|
42
|
17
|
100
|
|
|
|
73
|
if(my $serialiser = $node->get_serialiser) { |
43
|
|
|
|
|
|
|
return $node->get($key, sub { |
44
|
4
|
|
|
4
|
|
161
|
$cb->($serialiser->deserialise(shift)); |
45
|
7
|
100
|
|
|
|
276
|
}) if $cb; |
46
|
3
|
|
|
|
|
11
|
return $serialiser->deserialise($node->get($key)); |
47
|
|
|
|
|
|
|
} else { |
48
|
10
|
|
|
|
|
100
|
return $node->get($key, $cb); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub set { |
53
|
8
|
100
|
|
8
|
0
|
112
|
my $cb = ref($_[-1]) eq 'CODE' ? pop : undef; |
54
|
8
|
|
|
|
|
25
|
my ($self, $key, $value, $ttl) = @_; |
55
|
8
|
100
|
|
|
|
26
|
if($cb) { |
56
|
4
|
|
|
|
|
23
|
my $delay = Mojo::IOLoop->delay($cb); |
57
|
4
|
100
|
|
|
|
2692
|
$_->set($key, ($_->get_serialiser ? $_->get_serialiser->serialise($value) : $value), $ttl, $delay->begin) for @{$self->{nodes}}; |
|
4
|
|
|
|
|
32
|
|
58
|
4
|
|
|
|
|
464
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
4
|
100
|
|
|
|
7
|
$_->set($key, ($_->get_serialiser ? $_->get_serialiser->serialise($value) : $value), $ttl) for @{$self->{nodes}}; |
|
4
|
|
|
|
|
20
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub ttl { |
64
|
4
|
100
|
|
4
|
0
|
48
|
my $cb = ref($_[-1]) eq 'CODE' ? pop : undef; |
65
|
4
|
|
|
|
|
10
|
my ($self, $key) = @_; |
66
|
4
|
|
|
|
|
12
|
$self->{nodes}->[rand @{$self->{nodes}}]->ttl($key, $cb) |
|
4
|
|
|
|
|
110
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub incr { |
70
|
4
|
100
|
|
4
|
0
|
59
|
my $cb = ref($_[-1]) eq 'CODE' ? pop : undef; |
71
|
4
|
|
|
|
|
13
|
my ($self, $key, $amount) = @_; |
72
|
4
|
100
|
|
|
|
18
|
if($cb) { |
73
|
2
|
|
|
|
|
20
|
my $delay = Mojo::IOLoop->delay($cb); |
74
|
2
|
|
|
|
|
591
|
$_->incr($key, $amount, $delay->begin) for @{$self->{nodes}}; |
|
2
|
|
|
|
|
16
|
|
75
|
2
|
|
|
|
|
1019
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
2
|
|
|
|
|
6
|
$_->incr($key, $amount) for @{$self->{nodes}}; |
|
2
|
|
|
|
|
20
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub decr { |
81
|
4
|
100
|
|
4
|
0
|
61
|
my $cb = ref($_[-1]) eq 'CODE' ? pop : undef; |
82
|
4
|
|
|
|
|
11
|
my ($self, $key, $amount) = @_; |
83
|
4
|
100
|
|
|
|
16
|
if($cb) { |
84
|
2
|
|
|
|
|
13
|
my $delay = Mojo::IOLoop->delay($cb); |
85
|
2
|
|
|
|
|
442
|
$_->decr($key, $amount, $delay->begin) for @{$self->{nodes}}; |
|
2
|
|
|
|
|
14
|
|
86
|
2
|
|
|
|
|
831
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
2
|
|
|
|
|
4
|
$_->decr($key, $amount) for @{$self->{nodes}}; |
|
2
|
|
|
|
|
18
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub del { |
92
|
4
|
100
|
|
4
|
0
|
47
|
my $cb = ref($_[-1]) eq 'CODE' ? pop : undef; |
93
|
4
|
|
|
|
|
9
|
my ($self, $key) = @_; |
94
|
4
|
100
|
|
|
|
16
|
if($cb) { |
95
|
2
|
|
|
|
|
14
|
my $delay = Mojo::IOLoop->delay($cb); |
96
|
2
|
|
|
|
|
432
|
$_->del($key, $delay->begin) for @{$self->{nodes}}; |
|
2
|
|
|
|
|
14
|
|
97
|
2
|
|
|
|
|
456
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
2
|
|
|
|
|
5
|
$_->del($key) for @{$self->{nodes}}; |
|
2
|
|
|
|
|
14
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |