Changeset 338
- Timestamp:
- 08/11/06 00:37:55 (2 years ago)
- Files:
-
- branches/server-newrepl/lib/MogileFS/Config.pm (modified) (1 diff)
- branches/server-newrepl/lib/MogileFS/ProcManager.pm (modified) (3 diffs)
- branches/server-newrepl/lib/MogileFS/Worker.pm (modified) (4 diffs)
- branches/server-newrepl/lib/MogileFS/Worker/Monitor.pm (modified) (1 diff)
- branches/server-newrepl/lib/MogileFS/Worker/Query.pm (modified) (9 diffs)
- branches/server-newrepl/lib/MogileFS/Worker/Replicate.pm (modified) (1 diff)
- branches/server-newrepl/mogilefsd (modified) (7 diffs)
- branches/server-newrepl/t/00-startup.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/server-newrepl/lib/MogileFS/Config.pm
r323 r338 119 119 $min_free_space = choose_value( 'min_free_space', 100 ); 120 120 $max_disk_age = choose_value( 'max_disk_age', 5 ); 121 $DEBUG = choose_value( 'debug', 0, 1 );121 $DEBUG = choose_value( 'debug', $ENV{DEBUG} || 0, 1 ); 122 122 $USE_HTTP = ! choose_value( 'no_http', 0, 1); 123 123 $default_mindevcount = choose_value( 'default_mindevcount', 2 ); branches/server-newrepl/lib/MogileFS/ProcManager.pm
r328 r338 398 398 return MogileFS::ProcManager->HandleChildRequest($worker, $line) if !$client; 399 399 400 # FIXME: HOW IS THIS EVER CALLED? things with colons never go to HandleQueryWorkerResponse. 401 # see MogileFS::Connection::Worker 400 402 # out-of-band messages (not replies to requests) start with a colon: 401 403 if ($line =~ /^:state_change (\w+) (\d+) (\w+)/) { … … 549 551 550 552 # a no-op 553 554 } elsif ($cmd =~ /^:invalidate_meta (\w+)/) { 555 send_invalidate($1, $child); 551 556 552 557 } else { … … 628 633 #warn "STATE CHANGE: $what<$whatid> = $state\n"; 629 634 # TODO: can probably send this to all children now, not just certain types 630 for my $type (qw(queryworker replicate delete )) {635 for my $type (qw(queryworker replicate delete monitor)) { 631 636 MogileFS::ProcManager->ImmediateSendToChildrenByJob($type, ":state_change $what $whatid $state", $child); 637 } 638 } 639 640 sub send_invalidate { 641 my ($what, $child) = @_; 642 # TODO: can probably send this to all children now, not just certain types 643 for my $type (qw(queryworker replicate delete monitor)) { 644 MogileFS::ProcManager->ImmediateSendToChildrenByJob($type, ":invalidate_meta_once $what", $child); 632 645 } 633 646 } branches/server-newrepl/lib/MogileFS/Worker.pm
r322 r338 46 46 return 1 if $rv == $totallen; 47 47 die "Error writing: $!" if $!; 48 48 49 49 my $remain = $totallen - $rv; 50 50 my $offset = $rv; … … 82 82 my $rv = sysread($psock, $buf, 1024); 83 83 $self->{readbuf} .= $buf; 84 84 85 85 while ($self->{readbuf} =~ s/^(.+?)\r?\n//) { 86 86 my $line = $1; … … 148 148 } 149 149 150 sub invalidate_meta { 151 my ($self, $what) = @_; 152 return if $Mgd::INVALIDATE_NO_PROPOGATE; # anti recursion 153 $self->send_to_parent(":invalidate_meta $what"); 154 } 155 150 156 # tries to parse generic (not job-specific) commands sent from parent 151 157 # to child. returns 1 on success, or 0 if comman given isn't generic, … … 172 178 } 173 179 180 if ($$lineref =~ /^:invalidate_meta_once (\w+)/) { 181 local $Mgd::INVALIDATE_NO_PROPOGATE = 1; 182 eval("Mgd::invalidate_${1}_cache()"); 183 return 1; 184 } 185 174 186 # TODO: warn on unknown commands? 175 187 branches/server-newrepl/lib/MogileFS/Worker/Monitor.pm
r323 r338 28 28 every(2.5, sub { 29 29 $self->parent_ping; 30 $self->read_from_parent; 30 31 31 32 # get db and note we're starting a run branches/server-newrepl/lib/MogileFS/Worker/Query.pm
r334 r338 127 127 my $args = shift; 128 128 129 if ($args->{devices} || $args->{all}) { 130 Mgd::invalidate_device_cache(); 131 } 132 if ($args->{hosts} || $args->{all}) { 133 Mgd::invalidate_host_cache(); 134 } 129 Mgd::invalidate_device_cache() if $args->{devices} || $args->{all}; 130 Mgd::invalidate_host_cache() if $args->{hosts} || $args->{all}; 131 Mgd::invalidate_class_cache() if $args->{class} || $args->{all}; 132 Mgd::invalidate_domain_cache() if $args->{domain} || $args->{all}; 135 133 136 134 return $self->ok_line; … … 173 171 my (@dests, @hosts); 174 172 my $devs = Mgd::get_device_summary(); 173 175 174 while (scalar(@dests) < ($multi ? 3 : 1)) { 176 175 my $devid = Mgd::find_deviceid( … … 558 557 return $self->err_line("existing_devid"); 559 558 } 559 Mgd::invalidate_device_cache(); 560 560 return $self->ok_line; 561 561 } … … 583 583 584 584 # return the domain id we created 585 Mgd::invalidate_domain_cache(); 585 586 return $self->ok_line({ domain => $domain }); 586 587 } … … 615 616 616 617 # return the domain we nuked 618 Mgd::invalidate_domain_cache(); 617 619 return $self->ok_line({ domain => $domain }); 618 620 } … … 663 665 664 666 # return success 667 Mgd::invalidate_class_cache(); 665 668 return $self->ok_line({ class => $class, mindevcount => $mindevcount, domain => $domain }); 666 669 } … … 704 707 705 708 # return the class we nuked 709 Mgd::invalidate_class_cache(); 706 710 return $self->ok_line({ domain => $domain, class => $class }); 707 711 } … … 938 942 939 943 # success, weight changed 944 Mgd::invalidate_device_cache(); 940 945 return $self->ok_line($ret); 941 946 } … … 974 979 975 980 # success, state changed 981 Mgd::invalidate_device_cache(); 976 982 return $self->ok_line($ret); 977 983 } branches/server-newrepl/lib/MogileFS/Worker/Replicate.pm
r334 r338 95 95 } @$to_repl; 96 96 97 warn "New repl...\n";98 97 99 98 foreach my $todo (@$to_repl) { 100 99 my $fid = $todo->{fid}; 101 warn " new repl: $fid\n"; 100 102 101 my $errcode; 103 102 branches/server-newrepl/mogilefsd
r334 r338 266 266 next if $opts{min_free_space} && $dev->{mb_total} && 267 267 $dev->{mb_free} < $opts{min_free_space}; 268 269 268 next if $opts{must_be_alive} && 270 269 (MogileFS->observed_state("host", $dev->{hostid}) ne "reachable" || … … 280 279 my $rand = int(rand($total_free)); 281 280 my $cur = 0; 282 283 281 foreach my $devid (@list) { 284 282 $cur += $devs->{$devid}->{mb_free}; … … 308 306 # now override device status with host status if the host status is less than the device status 309 307 Mgd::check_host_cache(); 308 310 309 foreach my $devid (keys %dev) { 311 310 # makes others have an easier time of finding devices by free space 312 311 $dev{$devid}->{mb_free} = $dev{$devid}->{mb_total} - $dev{$devid}->{mb_used}; 313 312 314 my $host_status = $cache_host{$dev{$devid}->{hostid}}->{status}; 313 my $host = $cache_host{$dev{$devid}->{hostid}}; 314 die "No host for dev $devid (host $dev{$devid}->{hostid})" unless $host; 315 my $host_status = $host->{status}; 316 die "No status" unless $host_status =~ /^\w+$/; 317 315 318 if ($dev{$devid}->{status} eq 'alive' && $host_status ne 'alive') { 316 319 $dev{$devid}->{status} = $host_status; … … 324 327 } 325 328 329 sub invalidate_class_cache { 330 # FIXME: no cache yet exists 331 } 332 333 sub invalidate_domain_cache { 334 $domaincachetime = 0; 335 %domaincache = (); 336 337 if (my $worker = MogileFS::ProcManager->is_child) { 338 $worker->invalidate_meta("domain"); 339 } 340 } 341 326 342 sub invalidate_device_cache { 327 343 # so next time it's invalid and won't be used old 328 344 $cache_device_summary_time = 0; 329 345 $cache_device_summary = undef; 346 347 if (my $worker = MogileFS::ProcManager->is_child) { 348 $worker->invalidate_meta("device"); 349 } 330 350 } 331 351 … … 337 357 $cache_host_time = 0; 338 358 %cache_host = (); 359 360 if (my $worker = MogileFS::ProcManager->is_child) { 361 $worker->invalidate_meta("host"); 362 } 339 363 } 340 364 … … 346 370 $sth->execute; 347 371 while (my $host = $sth->fetchrow_hashref) { 372 die unless $host->{status} =~ /^\w+$/; 348 373 $cache_host{$host->{hostid}} = $host; 349 374 $cache_host{$host->{hostid}}->{mask} = Net::Netmask->new2($host->{altmask}) … … 351 376 } 352 377 $cache_host_time = time(); 378 return \%cache_host; 353 379 } 354 380 branches/server-newrepl/t/00-startup.t
r336 r338 32 32 ok(!$rv, "database setup ran again without problems"); 33 33 34 use File::Temp; 35 my $mogroot1 = File::Temp::tempdir( CLEANUP => 1 ); 36 my $mogroot2 = File::Temp::tempdir( CLEANUP => 1 ); 37 for (1..2) { 38 mkdir("$mogroot1/dev$_") or die "Failed to create dev$_ dir: $!"; 39 } 40 for (3..4) { 41 mkdir("$mogroot2/dev$_") or die "Failed to create dev$_ dir: $!"; 42 } 43 my $ms1 = create_mogstored("127.0.1.1", $mogroot1); 44 my $ms2 = create_mogstored("127.0.1.2", $mogroot2); 45 46 while (! -e "$mogroot1/dev1/usage" && 47 ! -e "$mogroot2/dev4/usage") { 48 print "Waiting on usage...\n"; 49 sleep 1; 50 } 51 34 52 my $tmptrack = create_temp_tracker($tempdb); 35 53 ok($tmptrack); … … 38 56 ok($tmptrack->mogadm("class", "add", "testdom", "2copies", "--mindevcount=2"), "created 2copies class in testdom"); 39 57 40 use File::Temp;41 my $mogroot = File::Temp::tempdir( CLEANUP => 1 );42 for (1..4) {43 mkdir("$mogroot/dev$_") or die "Failed to create dev$_ dir: $!";44 }45 58 46 59 ok($tmptrack->mogadm("host", "add", "hostA", "--ip=127.0.1.1", "--status=alive"), "created hostA"); 47 60 ok($tmptrack->mogadm("host", "add", "hostB", "--ip=127.0.1.2", "--status=alive"), "created hostB"); 48 61 49 my $ms1 = create_mogstored("127.0.1.1", $mogroot);50 my $ms2 = create_mogstored("127.0.1.2", $mogroot);51 62 52 63 ok($tmptrack->mogadm("device", "add", "hostA", 1), "created dev1 on hostA"); … … 54 65 ok($tmptrack->mogadm("device", "add", "hostB", 3), "created dev3 on hostB"); 55 66 ok($tmptrack->mogadm("device", "add", "hostB", 4), "created dev4 on hostB"); 56 57 58 67 59 68 #ok($tmptrack->mogadm("device", "mark", "hostA", 1, "alive"), "dev1 alive"); … … 65 74 domain => "testdom", 66 75 hosts => [ "127.0.0.1:7001" ], 67 ) 76 ); 68 77 69 78 79 sleep 3; # sleep 3 seconds to wait for monitor to see devices are alive. 80 81 my $fh = $mogc->new_file("file1", "2copies"); 82 ok($fh, "got filehandle"); 83 unless ($fh) { 84 warn "Error: " . $mogc->errstr; 85 sleep 500; 86 die; 87 } 88 89 my $data = "My test file.\n" x 1024; 90 print $fh $data; 91 ok(close($fh), "closed file"); 92 93 my $tries = 1; 94 my @paths; 95 while ($tries < 10 && (@paths = $mogc->get_paths("file1")) < 2) { 96 print "paths: [@paths]\n"; 97 sleep 1; 98 } 99 is(scalar @paths, 2, "replicated to 2 paths"); 70 100 71 101
