Changeset 342

Show
Ignore:
Timestamp:
08/11/06 03:20:15 (2 years ago)
Author:
bradfitz
Message:

make create_close insert into files_to_replicate, and make the
replicator job use that, then make the test suite verify it was used.

Files:

Legend:

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

    r338 r342  
    11package MogileFS::Worker::Monitor; 
    2 # deletes files 
    32 
    43use strict; 
     
    2827    every(2.5, sub { 
    2928        $self->parent_ping; 
    30         $self->read_from_parent; 
    3129 
    3230        # get db and note we're starting a run 
  • branches/server-newrepl/lib/MogileFS/Worker/Query.pm

    r338 r342  
    325325                      $fid, $dmid, $key, $size, $trow->{classid}); 
    326326    return $self->err_line("db_error") unless $rv; 
     327 
     328    # mark it as needing replicating: 
     329    $dbh->do("INSERT IGNORE INTO file_to_replicate ". 
     330             "SET fid=?, fromdevid=?, nexttry=0", undef, $fid, $devid); 
     331    return $self->err_line("db_error") if $dbh->err; 
    327332 
    328333    $dbh->do("DELETE FROM tempfile WHERE fid=?", undef, $fid); 
  • branches/server-newrepl/lib/MogileFS/Worker/Replicate.pm

    r338 r342  
    9595    } @$to_repl; 
    9696 
    97  
    9897    foreach my $todo (@$to_repl) { 
    9998        my $fid = $todo->{fid}; 
     99        warn "to repl (new): $fid\n"; 
    100100 
    101101        my $errcode; 
    102102 
    103         if (my $status = replicate($dbh, $fid, undef, \$errcode)) { 
     103        my ($status, $unlock) = replicate($dbh, $fid, errref => \$errcode, no_unlock => 1); 
     104        if ($status) { 
    104105            # $status is either 0 (failure, handled below), 1 (success, we actually 
    105106            # replicated this file), or 2 (success, but someone else replicated it). 
     107 
    106108            # so if it's 2, we just want to go to the next fid.  this file is done. 
     109            # somebody else presumably took care of the file_to_replicate maintenance 
     110            if ($status == 2) { 
     111                $unlock->() if $unlock; 
     112                next; 
     113            } 
     114 
     115            # replicate was a success, so cleanup table, then unlock 
    107116            warn "  new repl: $fid status = $status\n"; 
    108             next if $status == 2; 
     117            $dbh->do("DELETE FROM file_to_replicate WHERE fid=?", undef, $fid); 
     118            $unlock->(); 
     119 
    109120        } else { 
    110121            warn "  new repl: $fid status = 0\n"; 
    111122            error("ERROR CODE: $errcode"); 
     123            $unlock->() if $unlock; 
    112124        } 
    113125    } 
     
    170182                $self->read_from_parent; 
    171183 
    172                 if (my $status = replicate($dbh, $fid, $mclass)) { 
     184                if (my $status = replicate($dbh, $fid, class => $mclass)) { 
    173185                    # $status is either 0 (failure, handled below), 1 (success, we actually 
    174186                    # replicated this file), or 2 (success, but someone else replicated it). 
     
    205217# $policy_class is optional (perl classname representing replication policy).  if present, used.  if not, looked up based on $fid. 
    206218sub replicate { 
    207     my ($dbh, $fid, $mclass, $errref) = @_; 
     219    my ($dbh, $fid, %opts) = @_; 
     220    my $errref = delete $opts{'errref'}; 
     221    my $mclass = delete $opts{'class'}; 
     222    my $no_unlock = delete $opts{'no_unlock'}; 
     223    die if %opts; 
     224 
    208225    $mclass ||= MogileFS::Class->of_fid($fid); 
    209226 
     
    213230        return error("Failed to load policy class: $policy_class: $@"); 
    214231    } 
     232 
     233    # hashref of devid -> $device_row_href  (where devid is alive) 
     234    my $devs = Mgd::get_device_summary(); 
     235    return error("Device information from get_device_summary is empty") 
     236        unless $devs && %$devs; 
    215237 
    216238    my $lockname = "mgfs:fid:$fid:replicate"; 
     
    219241    return error("Unable to obtain lock $lockname") 
    220242        unless $lock; 
    221  
    222     # hashref of devid -> $device_row_href  (where devid is alive) 
    223     my $devs = Mgd::get_device_summary(); 
    224     return error("Device information from get_device_summary is empty") 
    225         unless $devs && %$devs; 
    226243 
    227244    # learn what devices this file is already on 
     
    245262    } 
    246263 
     264    my $unlock = sub { 
     265        $dbh->selectrow_array("SELECT RELEASE_LOCK(?)", undef, $lockname); 
     266    }; 
     267 
    247268    my $retunlock = sub { 
    248269        my $rv = shift; 
     
    254275        } 
    255276        $$errref = $errcode if $errref; 
    256         $dbh->selectrow_array("SELECT RELEASE_LOCK(?)", undef, $lockname); 
    257         return $rv ? $rv : error($errmsg); 
     277 
     278        my $ret = $rv ? $rv : error($errmsg); 
     279        if ($no_unlock) { 
     280            return ($ret, $unlock); 
     281        } else { 
     282            $unlock->(); 
     283            return $ret; 
     284        } 
    258285    }; 
    259286 
  • branches/server-newrepl/t/00-startup.t

    r341 r342  
    2424my $tempdb = create_temp_db(); 
    2525isa_ok $tempdb, "DBHandle"; 
     26my $dbh = $tempdb->dbh; 
    2627 
    2728my $rv; 
     
    9798my $tries = 1; 
    9899my @urls; 
    99 while ($tries < 10 && (@urls = $mogc->get_paths("file1")) < 2) { 
     100while ($tries++ < 10 && (@urls = $mogc->get_paths("file1")) < 2) { 
    100101    sleep 1; 
    101102} 
     
    112113ok(unlink($path1), "deleted path $path1"); 
    113114my $dead_url = $urls[0]; 
    114 for (1..20) { 
     115for (1..10) { 
    115116    @urls = $mogc->get_paths("file1"); 
    116     isnt($urls[0], $dead_url, "didn't return dead url first"); 
     117    isnt($urls[0], $dead_url, "didn't return dead url first (try $_)"); 
    117118} 
    118119 
     120my $to_repl_rows = $dbh->selectrow_array("SELECT COUNT(*) FROM file_to_replicate"); 
     121is($to_repl_rows, 0, "no more files to replicate"); 
    119122 
    120123 
    121