Changeset 1152
- Timestamp:
- 02/29/08 00:20:21 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/server/lib/MogileFS/ReplicationPolicy/MultipleNetworks.pm
r1151 r1152 36 36 my $all_devs = delete $args{all_devs}; # hashref of { devid => MogileFS::Device } 37 37 my $failed = delete $args{failed}; # hashref of { devid => 1 } of failed attempts this round 38 38 39 39 # old-style 40 40 my $min = delete $args{min}; 41 41 $min = $self->{mindevcount} || $min; 42 42 43 43 warn "Unknown parameters: " . join(", ", sort keys %args) if %args; 44 44 die "Missing parameters" unless $on_devs && $all_devs && $failed && $fid; 45 45 46 46 # number of devices we currently live on 47 47 my $already_on = @$on_devs; … … 52 52 # total disks available which are candidates for having files on them 53 53 my $total_disks = scalar grep { $_->dstate->should_have_files } values %$all_devs; 54 54 55 55 # if we have two copies and that's all the disks there are 56 56 # anywhere, be happy enough … … 64 64 $on_host{$dev->hostid} = 1; 65 65 $on_dev{$dev->id} = 1; 66 66 67 67 my $on_ip = $dev->host->ip; 68 68 if ($on_ip) { … … 103 103 next if ($seen_host{$device->host->id}++); 104 104 105 foreach my $disliked_network (@skip_network) { 105 foreach my $disliked_network (@skip_network) { 106 106 if (($disliked_network->match($device->host->ip)) and 107 107 (not $skip_host{$device->host->id})) { … … 122 122 123 123 return TEMP_NO_ANSWER unless @all_dests; 124 124 125 125 my @ideal = grep { ! $skip_host{$_->hostid} } @all_dests; 126 126 # wrong network is less desparate than wrong host … … 139 139 140 140 # can't just scalar keys %cache to count networks 141 # might include networks for which we have no hosts yet 141 # might include networks for which we have no hosts yet 142 142 sub unique_hosts_and_networks { 143 143 my ($devs) = @_; … … 148 148 my $dev = $devs->{$devid}; 149 149 next unless $dev->dstate->should_get_repl_files; 150 150 151 151 $host{$dev->hostid}++; 152 152 … … 162 162 my %cache; # '192.168.0.0/24' => Net::Netmask->new2('192.168.0.0/24'); 163 163 my $age; # increments everytime we look 164 164 165 165 # turn a server ip into a network 166 166 # defaults to /16 ranges … … 191 191 } 192 192 } 193 193 194 194 if (not $network) { 195 195 ($network) = ($ip =~ m/(\d+\.\d+)./); … … 197 197 $network = Net::Netmask->new2($network); 198 198 } 199 199 200 200 return $network; 201 201 } … … 205 205 206 206 my @zones = split(",",MogileFS::Config->server_setting("network_zones")); 207 207 208 208 foreach my $zone (@zones) { 209 209 my $netmask = MogileFS::Config->server_setting("zone_".$zone); … … 213 213 next; 214 214 } 215 215 216 216 if ($cache{$netmask}) { 217 217 warn "duplicate netmask <$netmask> in network zones. check your server settings"; 218 218 } 219 219 220 220 $cache{$netmask} = Net::Netmask->new2($netmask); 221 221 222 222 if (Net::Netmask::errstr()) { 223 223 warn "couldn't parse <$zone> as a netmask. error was <".Net::Netmask::errstr(). … … 229 229 sub stuff_cache { # for testing, or it'll try the db 230 230 my ($self, $ip, $netmask) = @_; 231 231 232 232 $cache{$ip} = $netmask; 233 233 $age = 1; 234 } 235 } 236 234 } 235 } 236 237 237 1; 238 238
