Changeset 338

Show
Ignore:
Timestamp:
08/11/06 00:37:55 (2 years ago)
Author:
bradfitz
Message:

-- make first test suite test work, uploading a file which propogates.

-- propogate meta caching invalidations between processes. (was required to fix races in test suite)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/server-newrepl/lib/MogileFS/Config.pm

    r323 r338  
    119119    $min_free_space = choose_value( 'min_free_space', 100 ); 
    120120    $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 ); 
    122122    $USE_HTTP       = ! choose_value( 'no_http', 0, 1); 
    123123    $default_mindevcount = choose_value( 'default_mindevcount', 2 ); 
  • branches/server-newrepl/lib/MogileFS/ProcManager.pm

    r328 r338  
    398398    return MogileFS::ProcManager->HandleChildRequest($worker, $line) if !$client; 
    399399 
     400    # FIXME: HOW IS THIS EVER CALLED?  things with colons never go to HandleQueryWorkerResponse. 
     401    #        see MogileFS::Connection::Worker 
    400402    # out-of-band messages (not replies to requests) start with a colon: 
    401403    if ($line =~ /^:state_change (\w+) (\d+) (\w+)/) { 
     
    549551 
    550552        # a no-op 
     553 
     554    } elsif ($cmd =~ /^:invalidate_meta (\w+)/) { 
     555        send_invalidate($1, $child); 
    551556 
    552557    } else { 
     
    628633    #warn "STATE CHANGE: $what<$whatid> = $state\n"; 
    629634    # 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)) { 
    631636        MogileFS::ProcManager->ImmediateSendToChildrenByJob($type, ":state_change $what $whatid $state", $child); 
     637    } 
     638} 
     639 
     640sub 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); 
    632645    } 
    633646} 
  • branches/server-newrepl/lib/MogileFS/Worker.pm

    r322 r338  
    4646    return 1 if $rv == $totallen; 
    4747    die "Error writing: $!" if $!; 
    48      
     48 
    4949    my $remain = $totallen - $rv; 
    5050    my $offset = $rv; 
     
    8282        my $rv = sysread($psock, $buf, 1024); 
    8383        $self->{readbuf} .= $buf; 
    84          
     84 
    8585        while ($self->{readbuf} =~ s/^(.+?)\r?\n//) { 
    8686            my $line = $1; 
     
    148148} 
    149149 
     150sub 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 
    150156# tries to parse generic (not job-specific) commands sent from parent 
    151157# to child.  returns 1 on success, or 0 if comman given isn't generic, 
     
    172178    } 
    173179 
     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 
    174186    # TODO: warn on unknown commands? 
    175187 
  • branches/server-newrepl/lib/MogileFS/Worker/Monitor.pm

    r323 r338  
    2828    every(2.5, sub { 
    2929        $self->parent_ping; 
     30        $self->read_from_parent; 
    3031 
    3132        # get db and note we're starting a run 
  • branches/server-newrepl/lib/MogileFS/Worker/Query.pm

    r334 r338  
    127127    my $args = shift; 
    128128 
    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}; 
    135133 
    136134    return $self->ok_line; 
     
    173171    my (@dests, @hosts); 
    174172    my $devs = Mgd::get_device_summary(); 
     173 
    175174    while (scalar(@dests) < ($multi ? 3 : 1)) { 
    176175        my $devid = Mgd::find_deviceid( 
     
    558557        return $self->err_line("existing_devid"); 
    559558    } 
     559    Mgd::invalidate_device_cache(); 
    560560    return $self->ok_line; 
    561561} 
     
    583583 
    584584    # return the domain id we created 
     585    Mgd::invalidate_domain_cache(); 
    585586    return $self->ok_line({ domain => $domain }); 
    586587} 
     
    615616 
    616617    # return the domain we nuked 
     618    Mgd::invalidate_domain_cache(); 
    617619    return $self->ok_line({ domain => $domain }); 
    618620} 
     
    663665 
    664666    # return success 
     667    Mgd::invalidate_class_cache(); 
    665668    return $self->ok_line({ class => $class, mindevcount => $mindevcount, domain => $domain }); 
    666669} 
     
    704707 
    705708    # return the class we nuked 
     709    Mgd::invalidate_class_cache(); 
    706710    return $self->ok_line({ domain => $domain, class => $class }); 
    707711} 
     
    938942 
    939943    # success, weight changed 
     944    Mgd::invalidate_device_cache(); 
    940945    return $self->ok_line($ret); 
    941946} 
     
    974979 
    975980    # success, state changed 
     981    Mgd::invalidate_device_cache(); 
    976982    return $self->ok_line($ret); 
    977983} 
  • branches/server-newrepl/lib/MogileFS/Worker/Replicate.pm

    r334 r338  
    9595    } @$to_repl; 
    9696 
    97     warn "New repl...\n"; 
    9897 
    9998    foreach my $todo (@$to_repl) { 
    10099        my $fid = $todo->{fid}; 
    101         warn "  new repl: $fid\n"; 
     100 
    102101        my $errcode; 
    103102 
  • branches/server-newrepl/mogilefsd

    r334 r338  
    266266        next if $opts{min_free_space} && $dev->{mb_total} && 
    267267                $dev->{mb_free} < $opts{min_free_space}; 
    268  
    269268        next if $opts{must_be_alive} && 
    270269            (MogileFS->observed_state("host", $dev->{hostid}) ne "reachable" || 
     
    280279        my $rand = int(rand($total_free)); 
    281280        my $cur = 0; 
    282  
    283281        foreach my $devid (@list) { 
    284282            $cur += $devs->{$devid}->{mb_free}; 
     
    308306    # now override device status with host status if the host status is less than the device status 
    309307    Mgd::check_host_cache(); 
     308 
    310309    foreach my $devid (keys %dev) { 
    311310        # makes others have an easier time of finding devices by free space 
    312311        $dev{$devid}->{mb_free} = $dev{$devid}->{mb_total} - $dev{$devid}->{mb_used}; 
    313312 
    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 
    315318        if ($dev{$devid}->{status} eq 'alive' && $host_status ne 'alive') { 
    316319            $dev{$devid}->{status} = $host_status; 
     
    324327} 
    325328 
     329sub invalidate_class_cache { 
     330    # FIXME: no cache yet exists 
     331} 
     332 
     333sub 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 
    326342sub invalidate_device_cache { 
    327343    # so next time it's invalid and won't be used old 
    328344    $cache_device_summary_time = 0; 
    329345    $cache_device_summary = undef; 
     346 
     347    if (my $worker = MogileFS::ProcManager->is_child) { 
     348        $worker->invalidate_meta("device"); 
     349    } 
    330350} 
    331351 
     
    337357    $cache_host_time = 0; 
    338358    %cache_host = (); 
     359 
     360    if (my $worker = MogileFS::ProcManager->is_child) { 
     361        $worker->invalidate_meta("host"); 
     362    } 
    339363} 
    340364 
     
    346370    $sth->execute; 
    347371    while (my $host = $sth->fetchrow_hashref) { 
     372        die unless $host->{status} =~ /^\w+$/; 
    348373        $cache_host{$host->{hostid}} = $host; 
    349374        $cache_host{$host->{hostid}}->{mask} = Net::Netmask->new2($host->{altmask}) 
     
    351376    } 
    352377    $cache_host_time = time(); 
     378    return \%cache_host; 
    353379} 
    354380 
  • branches/server-newrepl/t/00-startup.t

    r336 r338  
    3232ok(!$rv, "database setup ran again without problems"); 
    3333 
     34use File::Temp; 
     35my $mogroot1 = File::Temp::tempdir( CLEANUP => 1 ); 
     36my $mogroot2 = File::Temp::tempdir( CLEANUP => 1 ); 
     37for (1..2) { 
     38    mkdir("$mogroot1/dev$_") or die "Failed to create dev$_ dir: $!"; 
     39} 
     40for (3..4) { 
     41    mkdir("$mogroot2/dev$_") or die "Failed to create dev$_ dir: $!"; 
     42} 
     43my $ms1 = create_mogstored("127.0.1.1", $mogroot1); 
     44my $ms2 = create_mogstored("127.0.1.2", $mogroot2); 
     45 
     46while (! -e "$mogroot1/dev1/usage" && 
     47       ! -e "$mogroot2/dev4/usage") { 
     48    print "Waiting on usage...\n"; 
     49    sleep 1; 
     50} 
     51 
    3452my $tmptrack = create_temp_tracker($tempdb); 
    3553ok($tmptrack); 
     
    3856ok($tmptrack->mogadm("class", "add", "testdom", "2copies", "--mindevcount=2"), "created 2copies class in testdom"); 
    3957 
    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 } 
    4558 
    4659ok($tmptrack->mogadm("host", "add", "hostA", "--ip=127.0.1.1", "--status=alive"), "created hostA"); 
    4760ok($tmptrack->mogadm("host", "add", "hostB", "--ip=127.0.1.2", "--status=alive"), "created hostB"); 
    4861 
    49 my $ms1 = create_mogstored("127.0.1.1", $mogroot); 
    50 my $ms2 = create_mogstored("127.0.1.2", $mogroot); 
    5162 
    5263ok($tmptrack->mogadm("device", "add", "hostA", 1), "created dev1 on hostA"); 
     
    5465ok($tmptrack->mogadm("device", "add", "hostB", 3), "created dev3 on hostB"); 
    5566ok($tmptrack->mogadm("device", "add", "hostB", 4), "created dev4 on hostB"); 
    56  
    57  
    5867 
    5968#ok($tmptrack->mogadm("device", "mark", "hostA", 1, "alive"), "dev1 alive"); 
     
    6574                         domain => "testdom", 
    6675                         hosts  => [ "127.0.0.1:7001" ], 
    67                          ) 
     76                         ); 
    6877 
    6978 
     79sleep 3;  # sleep 3 seconds to wait for monitor to see devices are alive. 
     80 
     81my $fh = $mogc->new_file("file1", "2copies"); 
     82ok($fh, "got filehandle"); 
     83unless ($fh) { 
     84    warn "Error: " . $mogc->errstr; 
     85    sleep 500; 
     86    die; 
     87} 
     88 
     89my $data = "My test file.\n" x 1024; 
     90print $fh $data; 
     91ok(close($fh), "closed file"); 
     92 
     93my $tries = 1; 
     94my @paths; 
     95while ($tries < 10 && (@paths = $mogc->get_paths("file1")) < 2) { 
     96    print "paths: [@paths]\n"; 
     97    sleep 1; 
     98} 
     99is(scalar @paths, 2, "replicated to 2 paths"); 
    70100 
    71101