Changeset 1242 for branches

Show
Ignore:
Timestamp:
12/23/08 13:33:08 (11 months ago)
Author:
hachi
Message:

Empty files work now

Location:
branches/empty-files/server
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/empty-files/server/lib/MogileFS/DevFID.pm

    r1147 r1242  
    7272    my $self = shift; 
    7373    my $fid = $self->fid; 
    74     my $disk_size = $self->size_on_disk 
    75         or return 0; 
     74    my $disk_size = $self->size_on_disk; 
     75 
     76    return 0 if $disk_size == MogileFS::HTTPFile::FILE_MISSING; 
     77 
    7678    return $disk_size == $fid->length; 
    7779} 
  • branches/empty-files/server/lib/MogileFS/HTTPFile.pm

    r1198 r1242  
    120120# returns 0 on file missing (404 or -1 from sidechannel), 
    121121# returns undef on connectivity error 
    122 use constant FILE_MISSING => 0; 
     122use constant FILE_MISSING => -1; 
    123123sub size { 
    124124    my $self = shift; 
  • branches/empty-files/server/lib/MogileFS/Worker/Query.pm

    r1239 r1242  
    99use MogileFS::Util qw(error error_code first weighted_list 
    1010                      device_state eurl decode_url_args); 
     11use MogileFS::HTTPFile; 
    1112 
    1213sub new { 
     
    386387    my $size = MogileFS::HTTPFile->at($path)->size; 
    387388 
    388     if ($args->{size} > 0 && ! $size) { 
    389         # size is either: 0 (file doesn't exist) or undef (host unreachable) 
     389    if ($args->{size} >= 0 && (!defined($size) || $size == MogileFS::HTTPFile::FILE_MISSING)) { 
     390        # size check has been requested and that storage node is unreachable or the file is missing 
    390391        my $type    = defined $size ? "missing" : "cantreach"; 
    391392        my $lasterr = MogileFS::Util::last_error(); 
     
    397398 
    398399    # TODO: check for EIO? 
    399     return $self->err_line("empty_file") unless $size; 
    400400 
    401401    # insert file_on row 
  • branches/empty-files/server/lib/MogileFS/Worker/Replicate.pm

    r1238 r1242  
    838838        $clen = $1; 
    839839    } 
    840     return $error_unreachable->("File $spath has a content-length of 0; unable to replicate") 
    841         unless $clen; 
    842840    return $error_unreachable->("File $spath has unexpected content-length of $clen, not $expected_clen") 
    843841        if defined $expected_clen && $clen != $expected_clen; 
     
    857855    my $finished_read = 0; 
    858856 
    859     while (!$pipe_closed && (my $bytes = $sock->read($data, $bytes_to_read))) { 
    860         # now we've read in $bytes bytes 
    861         $remain -= $bytes; 
    862         $bytes_to_read = $remain if $remain < $bytes_to_read; 
    863  
    864         my $wbytes = $dsock->send($data); 
    865         $written  += $wbytes; 
    866         return $dest_error->("Error: wrote $wbytes; expected to write $bytes; failed putting to $dpath") 
    867             unless $wbytes == $bytes; 
    868         $intercopy_cb->(); 
    869  
    870         die if $bytes_to_read < 0; 
    871         next if $bytes_to_read; 
     857    if ($bytes_to_read) { 
     858        while (!$pipe_closed && (my $bytes = $sock->read($data, $bytes_to_read))) { 
     859            # now we've read in $bytes bytes 
     860            $remain -= $bytes; 
     861            $bytes_to_read = $remain if $remain < $bytes_to_read; 
     862 
     863            my $wbytes = $dsock->send($data); 
     864            $written  += $wbytes; 
     865            return $dest_error->("Error: wrote $wbytes; expected to write $bytes; failed putting to $dpath") 
     866                unless $wbytes == $bytes; 
     867            $intercopy_cb->(); 
     868 
     869            die if $bytes_to_read < 0; 
     870            next if $bytes_to_read; 
     871            $finished_read = 1; 
     872            last; 
     873        } 
     874    } else { 
     875        # 0 byte file copy. 
    872876        $finished_read = 1; 
    873         last; 
    874877    } 
    875878    return $dest_error->("closed pipe writing to destination")     if $pipe_closed; 
  • branches/empty-files/server/t/00-startup.t

    r1169 r1242  
    2121my $sto = eval { temp_store(); }; 
    2222if ($sto) { 
    23     plan tests => 59; 
     23    plan tests => 64; 
    2424} else { 
    2525    plan skip_all => "Can't create temporary test database: $@"; 
     
    109109} 
    110110 
     111{ 
     112    my $fh = $mogc->new_file('no_content', "2copies"); 
     113    ok(close($fh), "closed file"); 
     114} 
     115 
     116{ 
     117    my $fh = $mogc->new_file('no_content', "2copies"); 
     118    ok(close($fh), "closed file"); 
     119} 
     120 
     121# wait for it to replicate 
     122ok(try_for(10, sub { 
     123    my @urls = $mogc->get_paths("no_content"); 
     124    my $nloc = @urls; 
     125    if ($nloc < 2) { 
     126        diag("no_content still only on $nloc devices"); 
     127        return 0; 
     128    } 
     129    return 1; 
     130}), "replicated to 2 paths"); 
     131 
     132ok(try_for(3, sub { 
     133    my $to_repl_rows = $dbh->selectrow_array("SELECT COUNT(*) FROM file_to_replicate"); 
     134    return $to_repl_rows == 0; 
     135}), "no more files to replicate"); 
     136 
     137# quick delete test 
     138ok($mogc->delete("no_content"), "deleted no_content") 
     139    or die "Error: " . $mogc->errstr; 
     140 
    111141# create two sample files 
    112142my $data = "My test file.\n" x 1024;