| 1 | package MogileFS::ReplicationPolicy::MultipleNetworks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base 'MogileFS::ReplicationPolicy'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use MogileFS::Util qw(weighted_list); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use MogileFS::ReplicationRequest qw(ALL_GOOD TOO_GOOD TEMP_NO_ANSWER); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | my %cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | my $age; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 60 | ▶ | sub AVOIDNETWORK { return "AVOIDNETWORK"; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AVOIDNETWORK: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my ($class, $mindevcount) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | return bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | mindevcount => $mindevcount, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new_from_policy_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_policy_args: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ($class, $argref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Note: "MultipleNetworks()" is okay, in which case the 'mindevcount' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # on the class is used. (see below) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $$argref =~ s/^\s* \( \s* (\d*) \s* \) \s*//x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | or die "$class failed to parse args: $$argref"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return $class->new($1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub mindevcount { $_[0]{mindevcount} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mindevcount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 25 | ▶ | sub replicate_to { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replicate_to: called CC=34 SCAR=35.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 25 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 25 | my $fid = delete $args{fid}; # fid scalar to copy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 25 | my $on_devs = delete $args{on_devs}; # arrayref of device objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 25 | my $all_devs = delete $args{all_devs}; # hashref of { devid => MogileFS::Device } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 25 | my $failed = delete $args{failed}; # hashref of { devid => 1 } of failed attempts this round | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # old-style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 25 | my $min = delete $args{min}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 25 | ▶ | $min = $self->{mindevcount} || $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'mindevcount'} || $min
MC/DC0%0/2
$self->{'mindevcount'} || $min
$self->{'mindevcount'}
$min
Truth table33%1/3
A || B
A= $self->{'mindevcount'}B= $min
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 25 | ▶ | warn "Unknown parameters: " . join(", ", sort keys %args) if %args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 25 | ▶ | die "Missing parameters" unless $on_devs && $all_devs && $failed && $fid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$on_devs and $all_devs and $failed and $fid
$on_devs and $all_devs and $failed
$on_devs and $all_devs
MC/DC0%0/4
$on_devs and $all_devs and $failed and $fid
$on_devs
$all_devs
$failed
$fid
Truth table20%1/5
A and B and C and D
A= $on_devsB= $all_devsC= $failedD= $fid
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # number of devices we currently live on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 25 | my $already_on = @$on_devs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # a silly special case, bail out early. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 25 | ▶ | return ALL_GOOD if $min == 1 && $already_on; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$min == 1 and $already_on
MC/DC0%0/2
$min == 1 and $already_on
$min == 1
$already_on
Truth table33%1/3
A and B
A= $min == 1B= $already_on
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # total disks available which are candidates for having files on them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | my $total_disks = scalar grep { $_->dstate->should_have_files } values %$all_devs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # if we have two copies and that's all the disks there are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # anywhere, be happy enough | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 25 | ▶ | return ALL_GOOD if $already_on >= 2 && $already_on == $total_disks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$already_on >= 2 and $already_on == $total_disks
MC/DC0%0/2
$already_on >= 2 and $already_on == $total_disks
$already_on >= 2
$already_on == $total_disks
Truth table66%2/3
A and B
A= $already_on >= 2B= $already_on == $total_disks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # see which and how many unique hosts/networks we're already on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 25 | my %on_dev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | my %on_host; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 25 | my %on_network; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 25 | foreach my $dev (@$on_devs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 43 | $on_host{$dev->hostid} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 43 | $on_dev{$dev->id} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 43 | my $on_ip = $dev->host->ip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 43 | ▶ | if ($on_ip) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 20 | my $network = network_for_ip($on_ip); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 20 | $on_network{$network->desc} = $network; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 25 | my $uniq_hosts_on = scalar keys %on_host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 25 | ▶ | my $uniq_networks_on = scalar keys %on_network || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
scalar keys %on_network || 1
MC/DC100%1/1
scalar keys %on_network || 1
scalar keys %on_network
Truth table100%2/2
A
A= scalar keys %on_network
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 25 | my ($total_uniq_hosts, $total_uniq_networks) = unique_hosts_and_networks($all_devs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # target as many networks as we can, but not more than min | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 25 | ▶ | my $target_networks = ($min < $total_uniq_networks) ? $min : $total_uniq_networks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # we're never good if our copies aren't on as many networks as possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 25 | ▶ | if (($target_networks / $uniq_networks_on) <= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 18 | ▶ | return TOO_GOOD if $uniq_hosts_on > $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 17 | ▶ | return TOO_GOOD if $uniq_hosts_on == $min && $already_on > $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$uniq_hosts_on == $min and $already_on > $min
MC/DC100%2/2
$uniq_hosts_on == $min and $already_on > $min
$uniq_hosts_on == $min
$already_on > $min
Truth table100%3/3
A and B
A= $uniq_hosts_on == $minB= $already_on > $min
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 15 | ▶ | return ALL_GOOD if $uniq_hosts_on == $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | ▶ | return ALL_GOOD if $uniq_hosts_on >= $total_uniq_hosts && $already_on >= $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$uniq_hosts_on >= $total_uniq_hosts and $already_on >= $min
MC/DC100%2/2
$uniq_hosts_on >= $total_uniq_hosts and $already_on >= $min
$uniq_hosts_on >= $total_uniq_hosts
$already_on >= $min
Truth table100%3/3
A and B
A= $uniq_hosts_on >= $total_uniq_hostsB= $already_on >= $min
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # if there are more hosts we're not on yet, we want to exclude devices we're already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # on from our applicable host search. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # also exclude hosts on networks we're already on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 18 | my @skip_network = values %on_network; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 18 | my %skip_host; # hostid => 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 18 | ▶ | if ($uniq_hosts_on < $total_uniq_hosts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 17 | %skip_host = %on_host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 17 | ▶ | if (@skip_network) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # work out hosts from the devs passed to us | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 9 | my %seen_host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 9 | foreach my $device (values %$all_devs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 62 | ▶ | next if ($seen_host{$device->host->id}++); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 31 | foreach my $disliked_network (@skip_network) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 31 | ▶ | if (($disliked_network->match($device->host->ip)) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$disliked_network->match($device->host->ip) and not $skip_host{$device->host->id}
MC/DC100%2/2
$disliked_network->match($device->host->ip) and not $skip_host{$device->host->id}
$disliked_network->match($device->host->ip)
not $skip_host{$device->host->id}
Truth table100%3/3
A and not(B)
A= $disliked_network->match($device->host->ip)B= not $skip_host{$device->host->id}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | (not $skip_host{$device->host->id})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | $skip_host{$device->host->id} = AVOIDNETWORK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | my @all_dests = sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 73 | $b->percent_free <=> $a->percent_free | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 18 | ! $on_dev{$_->devid} && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 102 | ▶ | ! $failed->{$_->devid} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
!($on_dev{$_->devid} || $$failed{$_->devid}) && $_->should_get_replicated_files
$on_dev{$_->devid} || $$failed{$_->devid}
MC/DC66%2/3
!($on_dev{$_->devid} || $$failed{$_->devid}) && $_->should_get_replicated_files
$on_dev{$_->devid}
$$failed{$_->devid}
$_->should_get_replicated_files
Truth table75%3/4
not(A || B) && C
A= $on_dev{$_->devid}B= $$failed{$_->devid}C= $_->should_get_replicated_files
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $_->should_get_replicated_files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } values %$all_devs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 18 | ▶ | return TEMP_NO_ANSWER unless @all_dests; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 18 | my @ideal = grep { ! $skip_host{$_->hostid} } @all_dests; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # wrong network is less desperate than wrong host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 18 | my @network_desp = grep { $skip_host{$_->hostid} && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 64 | ▶ | $skip_host{$_->hostid} eq AVOIDNETWORK } @all_dests; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$skip_host{$_->hostid} && $skip_host{$_->hostid} eq AVOIDNETWORK()
MC/DC100%2/2
$skip_host{$_->hostid} && $skip_host{$_->hostid} eq AVOIDNETWORK()
$skip_host{$_->hostid}
$skip_host{$_->hostid} eq AVOIDNETWORK()
Truth table100%3/3
A && B
A= $skip_host{$_->hostid}B= $skip_host{$_->hostid} eq AVOIDNETWORK()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 18 | my @host_desp = grep { $skip_host{$_->hostid} && | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 64 | ▶ | $skip_host{$_->hostid} ne AVOIDNETWORK } @all_dests; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$skip_host{$_->hostid} && $skip_host{$_->hostid} ne AVOIDNETWORK()
MC/DC100%2/2
$skip_host{$_->hostid} && $skip_host{$_->hostid} ne AVOIDNETWORK()
$skip_host{$_->hostid}
$skip_host{$_->hostid} ne AVOIDNETWORK()
Truth table100%3/3
A && B
A= $skip_host{$_->hostid}B= $skip_host{$_->hostid} ne AVOIDNETWORK()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 18 | @ideal = weighted_list(map { [$_, 100 * $_->percent_free] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | splice(@ideal, 0, 20)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 18 | @network_desp = weighted_list(map { [$_, 100 * $_->percent_free] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | splice(@network_desp, 0, 20)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 18 | @host_desp = weighted_list(map { [$_, 100 * $_->percent_free] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | splice(@host_desp, 0, 20)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 18 | my @desp = (@network_desp, @host_desp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 18 | return MogileFS::ReplicationRequest->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | ideal => \@ideal, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | desperate => \@desp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # can't just scalar keys %cache to count networks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # might include networks for which we have no hosts yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 25 | ▶ | sub unique_hosts_and_networks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unique_hosts_and_networks: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 25 | my ($devs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 25 | my %host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | my %netmask; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 25 | foreach my $devid (keys %$devs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 133 | my $dev = $devs->{$devid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 133 | ▶ | next unless $dev->dstate->should_get_repl_files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 131 | $host{$dev->hostid}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 131 | my $ip = $dev->host->ip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 131 | $netmask{network_for_ip($ip)->desc}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 25 | ▶ | return (scalar keys %host, scalar keys %netmask || 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
scalar keys %netmask || 1
MC/DC0%0/1
scalar keys %netmask || 1
scalar keys %netmask
Truth table50%1/2
A
A= scalar keys %netmask
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | my %cache; # '192.168.0.0/24' => Net::Netmask->new2('192.168.0.0/24'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | my $age; # increments every time we look | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # turn a server ip into a network | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # defaults to /16 ranges | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # this can be overridden with a "zone_$location" setting per network "zone" and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # a lookup field listing all "zones" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # mogadm settings set network_zones location1,location2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # mogadm settings set zone_location1 192.168.0.0/24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # mogadm settings set zone_location2 10.0.0.0/24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # zone names and netmasks must be unique | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 151 | ▶ | sub network_for_ip { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
network_for_ip: called CC=7 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 151 | my ($ip) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 151 | ▶ | if (not $ip) { # can happen in testing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 56 | return Net::Netmask->new('default'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # clear the cache occasionally | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 95 | ▶ | if (($age == 0) or ($age++ > 500)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$age == 0 or $age++ > 500
MC/DC0%0/2
$age == 0 or $age++ > 500
$age == 0
$age++ > 500
Truth table33%1/3
A or B
A= $age == 0B= $age++ > 500
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | clear_and_build_cache(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $age = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 95 | my $network; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 95 | foreach my $zone (keys %cache) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 570 | ▶ | if ($cache{$zone}->match($ip)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 185 | $network = $cache{$zone}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 95 | ▶ | if (not $network) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ($network) = ($ip =~ m/(\d+\.\d+)./); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $network .= '/16'; # default | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $network = Net::Netmask->new2($network); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 95 | return $network; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub clear_and_build_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_and_build_cache: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | undef %cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my @zones = split(/\s*,\s*/,MogileFS::Config->server_setting("network_zones")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | foreach my $zone (@zones) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $netmask = MogileFS::Config->server_setting("zone_".$zone); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if (not $netmask) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | warn "couldn't find network_zone <<zone_".$zone.">> check your server settings"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ($cache{$netmask}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | warn "duplicate netmask <$netmask> in network zones. check your server settings"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $cache{$netmask} = Net::Netmask->new2($netmask); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if (Net::Netmask::errstr()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | warn "couldn't parse <$zone> as a netmask. error was <".Net::Netmask::errstr(). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | ">. check your server settings"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | ▶ | sub stuff_cache { # for testing, or it'll try the db | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stuff_cache: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | my ($self, $ip, $netmask) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 8 | $cache{$ip} = $netmask; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | $age = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # Local Variables: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # mode: perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # c-basic-indent: 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # End: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||