| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MogileFS::Factory; |
|
2
|
21
|
|
|
21
|
|
113
|
use strict; |
|
|
21
|
|
|
|
|
33
|
|
|
|
21
|
|
|
|
|
728
|
|
|
3
|
21
|
|
|
21
|
|
80
|
use warnings; |
|
|
21
|
|
|
|
|
32
|
|
|
|
21
|
|
|
|
|
7357
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
MogileFS::MogFactory - singleton class for holding some common objects. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 ABOUT |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
This module holds a singleton for caching objects which are common but |
|
12
|
|
|
|
|
|
|
relatively low in number. Such as devices, compared to fids. |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
This singleton is to be maintained by the parent process, and inherited to |
|
15
|
|
|
|
|
|
|
children during fork. Post-fork, the cache is updated by natural commands, or |
|
16
|
|
|
|
|
|
|
a monitor process pushing changes through the parent. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
The purpose is to provide a fresh cache, without forcing new children to |
|
19
|
|
|
|
|
|
|
wait for a monitoring run before becoming useful. It also should greatly |
|
20
|
|
|
|
|
|
|
reduce the number of simple DB queries, as those should only happen |
|
21
|
|
|
|
|
|
|
periodically directly from the monitor job. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %singleton; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Rename to new maybe? |
|
28
|
|
|
|
|
|
|
sub get_factory { |
|
29
|
258
|
|
|
258
|
0
|
274
|
my $class = shift; |
|
30
|
258
|
100
|
|
|
|
454
|
if (!exists $singleton{$class}) { |
|
31
|
60
|
|
|
|
|
200
|
$singleton{$class} = bless { |
|
32
|
|
|
|
|
|
|
by_id => {}, |
|
33
|
|
|
|
|
|
|
by_name => {}, |
|
34
|
|
|
|
|
|
|
}, $class; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
258
|
|
|
|
|
418
|
return $singleton{$class}; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Allow unit tests to blow us up. |
|
40
|
|
|
|
|
|
|
sub t_wipe { |
|
41
|
60
|
|
|
60
|
0
|
101
|
my $class = shift; |
|
42
|
60
|
|
|
|
|
101
|
delete $singleton{$class}; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# because 'add' means bail if already exists. |
|
46
|
|
|
|
|
|
|
sub set { |
|
47
|
198
|
|
|
198
|
0
|
153
|
my $self = shift; |
|
48
|
198
|
|
|
|
|
151
|
my $obj = shift; |
|
49
|
198
|
|
|
|
|
381
|
$self->{by_id}->{$obj->id} = $obj; |
|
50
|
198
|
|
|
|
|
404
|
$self->{by_name}->{$obj->name} = $obj; |
|
51
|
198
|
|
|
|
|
391
|
return $obj; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub remove { |
|
55
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
56
|
0
|
|
|
|
|
0
|
my $obj = shift; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
0
|
if (exists $self->{by_id}->{$obj->id}) { |
|
59
|
0
|
|
|
|
|
0
|
delete $self->{by_id}->{$obj->id}; |
|
60
|
0
|
|
|
|
|
0
|
delete $self->{by_name}->{$obj->name}; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get_by_id { |
|
65
|
104
|
|
|
104
|
0
|
87
|
my ($self, $id) = @_; |
|
66
|
104
|
|
|
|
|
198
|
return $self->{by_id}->{$id}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_by_name { |
|
70
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
|
71
|
0
|
|
|
|
|
|
return $self->{by_name}->{$name}; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_ids { |
|
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
76
|
0
|
|
|
|
|
|
return keys %{$self->{by_id}}; |
|
|
0
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub get_names { |
|
80
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
81
|
0
|
|
|
|
|
|
return keys %{$self->{by_name}}; |
|
|
0
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_all { |
|
85
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
86
|
0
|
|
|
|
|
|
return values %{$self->{by_id}}; |
|
|
0
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub map_by_id { |
|
90
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
91
|
0
|
|
|
|
|
|
my $set = $self->{by_id}; |
|
92
|
0
|
|
|
|
|
|
return { map { $_ => $set->{$_} } keys %{$set} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub map_by_name { |
|
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
97
|
0
|
|
|
|
|
|
my $set = $self->{by_name}; |
|
98
|
0
|
|
|
|
|
|
return { map { $_ => $set->{$_} } keys %{$set} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |