line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MogileFS::ReplicationPolicy; |
2
|
21
|
|
|
21
|
|
122
|
use strict; |
|
21
|
|
|
|
|
33
|
|
|
21
|
|
|
|
|
15114
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
MogileFS::ReplicationPolicy - base class for file replication policies |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 DESCRIPTION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
A MogileFS replication policy class implements policy for how files |
11
|
|
|
|
|
|
|
should be replicated around. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
.... |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# parse a policy description string, instantiating object(s) along the way |
18
|
|
|
|
|
|
|
# given $str can be either a scalar, or a scalarref that's eaten away as it's parsed. |
19
|
|
|
|
|
|
|
sub new_from_policy_string { |
20
|
23
|
|
|
23
|
0
|
6388
|
my ($class, $str_a) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# simple case for normal callers: they give us a scalar, but internally |
23
|
|
|
|
|
|
|
# we work with it as a scalarref that we eat away while parsing. |
24
|
23
|
100
|
|
|
|
44
|
my $strref = ref $str_a ? $str_a : \$str_a; |
25
|
|
|
|
|
|
|
|
26
|
23
|
50
|
|
|
|
98
|
$$strref =~ s/^\s*([\w:]+)// or die "Failed to parse policy string: $$strref"; |
27
|
23
|
|
|
|
|
41
|
my ($polclass) = ($1); |
28
|
23
|
50
|
|
|
|
57
|
$polclass = "MogileFS::ReplicationPolicy::$polclass" unless $polclass =~ /:/; |
29
|
|
|
|
|
|
|
|
30
|
23
|
|
|
1
|
|
1292
|
my $rv = eval "use $polclass; 1"; |
|
1
|
|
|
1
|
|
8
|
|
|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
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
31
|
23
|
50
|
33
|
|
|
95
|
if ($@ || !$rv) { |
32
|
0
|
|
|
|
|
0
|
die "Failed to load replication policy class $polclass: $@\n"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
23
|
|
|
|
|
68
|
return $polclass->new_from_policy_args($strref); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# returns: |
39
|
|
|
|
|
|
|
# 0: replication sufficient |
40
|
|
|
|
|
|
|
# undef: no suitable recommendations currently. |
41
|
|
|
|
|
|
|
# >0: devid to replicate to. |
42
|
|
|
|
|
|
|
sub replicate_to { |
43
|
0
|
|
|
0
|
0
|
0
|
my ($self, %args) = @_; |
44
|
0
|
|
|
|
|
0
|
my $fid = delete $args{fid}; # fid scalar to copy |
45
|
0
|
|
|
|
|
0
|
my $on_devs = delete $args{on_devs}; # arrayref of device objects |
46
|
0
|
|
|
|
|
0
|
my $all_devs = delete $args{all_devs}; # hashref of { devid => MogileFS::Device } |
47
|
0
|
|
|
|
|
0
|
my $failed = delete $args{failed}; # hashref of { devid => 1 } of failed attempts this round |
48
|
0
|
|
|
|
|
0
|
my $min = delete $args{min}; # configured min devcount for this class |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
0
|
warn "Unknown parameters: " . join(", ", sort keys %args) if %args; |
51
|
0
|
0
|
0
|
|
|
0
|
die "Missing parameters" unless $on_devs && $all_devs && $failed && $fid; |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
0
|
|
|
0
|
die "UNIMPLEMENTED 'replicate_to' in " . (ref($self) || $self); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |