[PATCH] Don't delete files accidentally during tempfile table cleanup.

4 views
Skip to first unread message

dormando

unread,
Aug 11, 2008, 12:56:21 AM8/11/08
to mog...@googlegroups.com, dormando
If a tempfile row's fidid has a file row, don't delete the file, just remove the tempfile row. This should reduce or remove the confusing issue of having file rows with no corresponding file_on rows...
---
trunk/server/lib/MogileFS/Worker/Delete.pm | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/trunk/server/lib/MogileFS/Worker/Delete.pm b/trunk/server/lib/MogileFS/Worker/Delete.pm
index d04c993..1f5a3d3 100644
--- a/trunk/server/lib/MogileFS/Worker/Delete.pm
+++ b/trunk/server/lib/MogileFS/Worker/Delete.pm
@@ -98,7 +98,17 @@ sub process_tempfiles {
# now expunged (or soon to be) rows from tempfile
my (@devfids, @fidids);
foreach my $row (@$tempfiles) {
- push @fidids, $row->[0];
+
+ # If FID is still loadable, we've arrived here due to a bug or race
+ # condition elsewhere. Remove the tempfile row but don't delete the
+ # file!
+ my $fidid = $row->[0];
+ my $fid = MogileFS::FID->new($fidid);
+ if ($fid->exists) {
+ $sto->dbh->do("DELETE FROM tempfile WHERE fid = ?", {}, $fidid);
+ next;
+ }
+ push @fidids, $fidid;

# sanity check the string column.
my $devids = $row->[1];
--
1.5.3.8

Reply all
Reply to author
Forward
0 new messages