From e596d524aeda5d4beb3510fba1498dd75231a2bb Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 13 Mar 2012 15:42:35 -0700 Subject: [PATCH] DevFID size caching for fsck with checksumming The digest path relies on having a known file size to calculate the MD5 timeout, so save an HTTP HEAD request since we always check file sizes in fsck before we checksum the file. --- lib/MogileFS/DevFID.pm | 6 ++++-- lib/MogileFS/HTTPFile.pm | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/MogileFS/DevFID.pm b/lib/MogileFS/DevFID.pm index f62c057..e3468cd 100644 --- a/lib/MogileFS/DevFID.pm +++ b/lib/MogileFS/DevFID.pm @@ -63,9 +63,10 @@ sub vivify_directories { sub size_on_disk { my $self = shift; my $url = $self->get_url; + my $httpfile = $self->{_httpfile_get} ||= MogileFS::HTTPFile->at($url); # check that it has size (>0) and is reachable (not undef) - return MogileFS::HTTPFile->at($url)->size; + return $httpfile->size; } # returns -1 on missing, @@ -74,9 +75,10 @@ sub size_on_disk { sub checksum_on_disk { my ($self, $alg, $ping_cb, $reason) = @_; my $url = $self->get_url; + my $httpfile = $self->{_httpfile_get} ||= MogileFS::HTTPFile->at($url); # check that it has size (>0) and is reachable (not undef) - return MogileFS::HTTPFile->at($url)->digest($alg, $ping_cb, $reason); + return $httpfile->digest($alg, $ping_cb, $reason); } # returns true if size seen matches fid's length diff --git a/lib/MogileFS/HTTPFile.pm b/lib/MogileFS/HTTPFile.pm index fa3d7a5..ce26b36 100644 --- a/lib/MogileFS/HTTPFile.pm +++ b/lib/MogileFS/HTTPFile.pm @@ -98,6 +98,9 @@ sub delete { use constant FILE_MISSING => -1; sub size { my $self = shift; + + return $self->{_size} if defined $self->{_size}; + my ($host, $port, $uri, $path) = map { $self->{$_} } qw(host port uri url); return undef if (exists $size_check_retry_after{$host} @@ -118,8 +121,10 @@ sub size { $res->header('server') =~ m/^lighttpd/) { # lighttpd 1.4.x (main release) does not return content-length for # 0 byte files. + $self->{_size} = 0; return 0; } + $self->{_size} = $size; return $size; } else { if ($res->code == 404) { -- 2.11.4.GIT