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)
66 return undef unless $self->device->should_read_from;
68 my $url = $self->get_url;
69 my $httpfile = $self->{_httpfile_get
} ||= MogileFS
::HTTPFile
->at($url);
71 # check that it has size (>0) and is reachable (not undef)
72 return $httpfile->size;
75 # returns -1 on missing,
76 # undef on connectivity error,
77 # else checksum of file on disk (after HTTP GET or mogstored read)
78 sub checksum_on_disk
{
79 my ($self, $alg, $ping_cb, $reason) = @_;
81 return undef unless $self->device->should_read_from;
83 my $url = $self->get_url;
84 my $httpfile = $self->{_httpfile_get
} ||= MogileFS
::HTTPFile
->at($url);
86 # check that it has size (>0) and is reachable (not undef)
87 return $httpfile->digest($alg, $ping_cb, $reason);
90 # returns true if size seen matches fid's length
94 my $disk_size = $self->size_on_disk;
96 # Temporary connectivity error with that disk/machine..
97 return 0 unless defined $disk_size;
98 return 0 if $disk_size == MogileFS
::HTTPFile
::FILE_MISSING
;
100 return $disk_size == $fid->length;
103 # returns just the URI path component without scheme/host
106 my $devid = $self->{devid
};
107 my $fidid = $self->{fidid
};
110 my $len = length $fidid;
112 $nfid = '0' x
(10 - $len) . $fidid;
116 my ( $b, $mmm, $ttt, $hto ) = ( $nfid =~ m{(\d)(\d{3})(\d
{3})(\d
{3})} );
118 return "/dev$devid/$b/$mmm/$ttt/$nfid.fid";
122 # set use_get_port to be true to specify to use the get port
123 my ($self, $use_get_port) = @_;
125 # get some information we'll need
126 my $dev = $self->device or return undef;
127 my $host = $dev->host or return undef;
129 my $path = $self->uri_path;
130 my $hostip = $host->ip;
131 my $port = $use_get_port ?
$host->http_get_port : $host->http_port;
133 return "http://$hostip:$port$path";
137 my ($self, $no_lock) = @_;
138 croak
("fidid not non-zero") unless $self->{fidid
};
139 croak
("devid not non-zero") unless $self->{devid
};
141 my $sto = Mgd
::get_store
();
142 if ($sto->add_fidid_to_devid($self->{fidid
}, $self->{devid
})) {
143 if (my $memc = MogileFS
::Config
->memcache_client) {
144 $memc->delete("mogdevids:$self->{fidid}");
146 return $self->fid->update_devcount(no_lock
=> $no_lock);
148 # was already on that device
153 # Destroy a particular replica of a file via HTTP, remove it
154 # from the tracker, and update the replication counts to be
160 my $httpfile = MogileFS
::HTTPFile
->at($self->url)
161 or die "Creation of HTTPFile object failed.";
165 $delete_opts{ignore_missing
} = 1
166 if $opts{ignore_missing
};
168 $httpfile->delete(%delete_opts)
169 or die "Deletion of file via HTTP failed.";
171 my $sto = Mgd
::get_store
();
172 $sto->remove_fidid_from_devid($self->fidid, $self->devid);
173 $self->fid->update_devcount(no_lock
=> 1);
182 MogileFS::DevFID - represents a FID on a device
186 This class represents the (devid, fidid) tuple. That is, a specific
187 version on a file on a specific device. See L<MogileFS::Device> and