*** mogilefsd 2006-03-02 00:05:08.000000000 -0600 --- /usr/bin/mogilefsd 2006-07-28 09:39:30.000000000 -0500 *************** *** 1,4 **** --- 1,7 ---- #!/usr/bin/perl + + eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' + if 0; # not running under some shell # # MogileFS daemon # *************** *** 618,623 **** --- 621,654 ---- } } + sub _write { + my $sock=shift; + my $data=shift; + my $bytesleft = length($data); + + my $win = ''; + vec($win, fileno($sock), 1) = 1; + my $bytessent = 0; + + my $nfound; + while ($bytesleft && ($nfound = select(undef, $win, undef, 3))) { + my $bytesout = syswrite($sock, $data, $bytesleft, $bytessent); + if (defined $bytesout) { + # update our myriad counters + $bytessent += $bytesout; + $bytesleft -= $bytesout; + } else { + # if we get EAGAIN, restart the select loop, else fail + next if $! == EAGAIN; + error("Error: $! error !!!!\n") if $Mgd::DEBUG > 2; + return 0; + } + } + return 1 unless $bytesleft; + error("Error: $! replicate fail !!! bytes left !!!!\n") if $Mgd::DEBUG > 2; + return 0; + } + # copies a file from one Perlbal to another utilizing HTTP sub http_copy { my ($sdevid, $ddevid, $fid) = @_; *************** *** 688,700 **** # now read data and print while we're reading. my ($data, $read, $written) = ('', 0, 0); ! while (!$pipe_closed && (my $bytes = $sock->read($data, $clen - $read))) { # now we've read in $bytes bytes $read += $bytes; ! my $wbytes = $dsock->send($data); ! $written += $wbytes; ! return error("Error: wrote $wbytes; expected to write $bytes; failed putting to $dpath") ! unless $wbytes == $bytes; } return error("Error: wrote $written bytes, expected to write $clen") unless $written == $clen; --- 719,739 ---- # now read data and print while we're reading. my ($data, $read, $written) = ('', 0, 0); ! for (;;) { ! my $bytes; ! my $readlimit = $clen - $read > 5242880 ? 5242880 : $clen - $read; ! $bytes = $sock->read($data, $readlimit); ! ! last if $pipe_closed or $bytes == 0; ! # now we've read in $bytes bytes $read += $bytes; ! ! my $result = _write($dsock,$data); ! return error("Error: fail to write $bytes; failed putting to $dpath") ! unless $result; ! ! $written += $bytes; } return error("Error: wrote $written bytes, expected to write $clen") unless $written == $clen; *************** *** 737,742 **** --- 776,783 ---- die $dbh->errstr if $dbh->err; while (my ($devid) = $sth->fetchrow_array) { my $d = $devs->{$devid}; + print "$d->{hostid}\n\n"; + unless ($d && $d->{status} =~ /^alive|readonly$/) { push @dead_devid, $devid; next; *************** *** 761,766 **** --- 802,810 ---- while ($on_count < $min) { my $need = $min - $on_count; + my @tmp = keys %on_host; + print "on host @tmp\n\n"; + my @good_devids = Mgd::find_deviceid( random => 1, not_on_hosts => [ keys %on_host ],