Fix for object auditor. It doesn't close files that are quarantined for certain reasons, zero byte files for one, which will cause it to eventually crash due to keeping too many files open. Thanks David Kranz for finding / reporting this!!

This commit is contained in:
David Goetz
2011-08-31 15:17:26 +00:00
committed by Tarmac
2 changed files with 47 additions and 24 deletions

View File

@@ -134,31 +134,34 @@ class AuditorWorker(object):
df = object_server.DiskFile(self.devices, device, partition, df = object_server.DiskFile(self.devices, device, partition,
account, container, obj, self.logger, account, container, obj, self.logger,
keep_data_fp=True) keep_data_fp=True)
if df.data_file is None:
# file is deleted, we found the tombstone
return
try: try:
obj_size = df.get_data_file_size() if df.data_file is None:
except DiskFileError, e: # file is deleted, we found the tombstone
raise AuditException(str(e)) return
except DiskFileNotExist: try:
return obj_size = df.get_data_file_size()
if self.zero_byte_only_at_fps and obj_size: except DiskFileError, e:
self.passes += 1 raise AuditException(str(e))
return except DiskFileNotExist:
for chunk in df: return
self.bytes_running_time = ratelimit_sleep( if self.zero_byte_only_at_fps and obj_size:
self.bytes_running_time, self.max_bytes_per_second, self.passes += 1
incr_by=len(chunk)) return
self.bytes_processed += len(chunk) for chunk in df:
self.total_bytes_processed += len(chunk) self.bytes_running_time = ratelimit_sleep(
df.close() self.bytes_running_time, self.max_bytes_per_second,
if df.quarantined_dir: incr_by=len(chunk))
self.quarantines += 1 self.bytes_processed += len(chunk)
self.logger.error( self.total_bytes_processed += len(chunk)
_("ERROR Object %(path)s failed audit and will be " df.close()
"quarantined: ETag and file's md5 do not match"), if df.quarantined_dir:
{'path': path}) self.quarantines += 1
self.logger.error(
_("ERROR Object %(path)s failed audit and will be "
"quarantined: ETag and file's md5 do not match"),
{'path': path})
finally:
df.close(verify_file=False)
except AuditException, err: except AuditException, err:
self.quarantines += 1 self.quarantines += 1
self.logger.error(_('ERROR Object %(obj)s failed audit and will ' self.logger.error(_('ERROR Object %(obj)s failed audit and will '

View File

@@ -315,6 +315,26 @@ class TestAuditor(unittest.TestCase):
my_auditor._sleep() my_auditor._sleep()
self.assertEquals(round(time.time() - start, 2), 0.01) self.assertEquals(round(time.time() - start, 2), 0.01)
def test_object_run_fast_track_zero_check_closed(self):
rat = [False]
class FakeFile(DiskFile):
def close(self, verify_file=True):
rat[0] = True
DiskFile.close(self, verify_file=verify_file)
self.setup_bad_zero_byte()
was_df = object_server.DiskFile
try:
object_server.DiskFile = FakeFile
self.auditor.run_once(zero_byte_fps=50)
quarantine_path = os.path.join(self.devices,
'sda', 'quarantined', 'objects')
self.assertTrue(os.path.isdir(quarantine_path))
self.assertTrue(rat[0])
finally:
object_server.DiskFile = was_df
def test_run_forever(self): def test_run_forever(self):
class StopForever(Exception): class StopForever(Exception):