1 package MogileFS
::DevFID
;
5 use overload
'""' => \
&as_string
;
9 my ($class, $devarg, $fidarg) = @_;
11 devid
=> ref $devarg ?
$devarg->id : $devarg,
12 dev
=> ref $devarg ?
$devarg : undef,
13 fidid
=> ref $fidarg ?
$fidarg->id : $fidarg,
14 fid
=> ref $fidarg ?
$fidarg : undef,
18 # --------------------------------------------------------------------------
20 sub devid
{ $_[0]{devid
} }
21 sub fidid
{ $_[0]{fidid
} }
24 "DevFID[d=" . $_[0]{devid
} . ";f=" . $_[0]{fidid
} . "]";
29 return $self->{dev
} ||= Mgd
::device_factory
()->get_by_id($self->{devid
});
34 return $self->{fid
} ||= MogileFS
::FID
->new($self->{fidid
});
37 # returns true if DevFID actually exists in database
41 return (grep { $_ == $self->{devid
} } $fid->devids) ?
1 : 0;
46 return $self->_make_full_url(0);
51 return $self->_make_full_url(1);
54 sub vivify_directories
{
57 $self->device()->vivify_directories($url);
60 # returns 0 on missing,
61 # undef on connectivity error,
62 # else size of file on disk (after HTTP HEAD or mogstored stat)
65 my $url = $self->get_url;
67 # check that it has size (>0) and is reachable (not undef)
68 return MogileFS
::HTTPFile
->at($url)->size;
71 # returns -1 on missing,
72 # undef on connectivity error,
73 # else checksum of file on disk (after HTTP GET or mogstored read)
74 sub checksum_on_disk
{
75 my ($self, $alg, $ping_cb, $reason) = @_;
76 my $url = $self->get_url;
78 # check that it has size (>0) and is reachable (not undef)
79 return MogileFS
::HTTPFile
->at($url)->digest($alg, $ping_cb, $reason);
82 # returns true if size seen matches fid's length
86 my $disk_size = $self->size_on_disk;
88 # Temporary connectivity error with that disk/machine..
89 return 0 unless defined $disk_size;
90 return 0 if $disk_size == MogileFS
::HTTPFile
::FILE_MISSING
;
92 return $disk_size == $fid->length;
95 # returns just the URI path component without scheme/host
98 my $devid = $self->{devid
};
99 my $fidid = $self->{fidid
};
102 my $len = length $fidid;
104 $nfid = '0' x
(10 - $len) . $fidid;
108 my ( $b, $mmm, $ttt, $hto ) = ( $nfid =~ m{(\d)(\d{3})(\d
{3})(\d
{3})} );
110 return "/dev$devid/$b/$mmm/$ttt/$nfid.fid";
114 # set use_get_port to be true to specify to use the get port
115 my ($self, $use_get_port) = @_;
117 # get some information we'll need
118 my $dev = $self->device or return undef;
119 my $host = $dev->host or return undef;
121 my $path = $self->uri_path;
122 my $hostip = $host->ip;
123 my $port = $use_get_port ?
$host->http_get_port : $host->http_port;
125 return "http://$hostip:$port$path";
129 my ($self, $no_lock) = @_;
130 croak
("fidid not non-zero") unless $self->{fidid
};
131 croak
("devid not non-zero") unless $self->{devid
};
133 my $sto = Mgd
::get_store
();
134 if ($sto->add_fidid_to_devid($self->{fidid
}, $self->{devid
})) {
135 return $self->fid->update_devcount(no_lock
=> $no_lock);
137 # was already on that device
142 # Destroy a particular replica of a file via HTTP, remove it
143 # from the tracker, and update the replication counts to be
149 my $httpfile = MogileFS
::HTTPFile
->at($self->url)
150 or die "Creation of HTTPFile object failed.";
154 $delete_opts{ignore_missing
} = 1
155 if $opts{ignore_missing
};
157 $httpfile->delete(%delete_opts)
158 or die "Deletion of file via HTTP failed.";
160 my $sto = Mgd
::get_store
();
161 $sto->remove_fidid_from_devid($self->fidid, $self->devid);
162 $sto->update_devcount($self->fidid);
171 MogileFS::DevFID - represents a FID on a device
175 This class represents the (devid, fidid) tuple. That is, a specific
176 version on a file on a specific device. See L<MogileFS::Device> and