def object_audit(self, path, device, partition): """ Audits the given object path. :param path: a path to an object :param device: the device the path is on :param partition: the partition the path is on """ try: try: name = object_server.read_metadata(path)['name'] except (Exception, Timeout) as exc: raise AuditException('Error when reading metadata: %s' % exc) _junk, account, container, obj = name.split('/', 3) df = object_server.DiskFile(self.devices, device, partition, account, container, obj, self.logger, keep_data_fp=True) try: try: obj_size = df.get_data_file_size() except DiskFileError as e: raise AuditException(str(e)) except DiskFileNotExist: return if self.stats_sizes: self.record_stats(obj_size) if self.zero_byte_only_at_fps and obj_size: self.passes += 1 return for chunk in df: self.bytes_running_time = ratelimit_sleep( self.bytes_running_time, self.max_bytes_per_second, incr_by=len(chunk)) self.bytes_processed += len(chunk) self.total_bytes_processed += len(chunk) df.close() if df.quarantined_dir: 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 as err: self.logger.increment('quarantines') self.quarantines += 1 self.logger.error(_('ERROR Object %(obj)s failed audit and will ' 'be quarantined: %(err)s'), {'obj': path, 'err': err}) object_server.quarantine_renamer( os.path.join(self.devices, device), path) return except (Exception, Timeout): self.logger.increment('errors') self.errors += 1 self.logger.exception(_('ERROR Trying to audit %s'), path) return self.passes += 1
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: self.quarantines += 1 self.logger.error( _('ERROR Object %(obj)s failed audit and will ' 'be quarantined: %(err)s'), { 'obj': path, 'err': err }) object_server.quarantine_renamer( os.path.join(self.devices, device), path) return except (Exception, Timeout): self.errors += 1 self.logger.exception(_('ERROR Trying to audit %s'), path) return self.passes += 1 class ObjectAuditor(Daemon): """Audit objects.""" def __init__(self, conf, **options): self.conf = conf self.logger = get_logger(conf, log_route='object-auditor') self.conf_zero_byte_fps = int( conf.get('zero_byte_files_per_second', 50))
self.bytes_running_time, self.max_bytes_per_second, incr_by=len(chunk)) self.bytes_processed += len(chunk) self.total_bytes_processed += len(chunk) df.close() if df.quarantined_dir: 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}) except AuditException, err: self.quarantines += 1 self.logger.error(_('ERROR Object %(obj)s failed audit and will ' 'be quarantined: %(err)s'), {'obj': path, 'err': err}) object_server.quarantine_renamer( os.path.join(self.devices, device), path) return except Exception: self.errors += 1 self.logger.exception(_('ERROR Trying to audit %s'), path) return self.passes += 1 class ObjectAuditor(Daemon): """Audit objects.""" def __init__(self, conf, **options): self.conf = conf self.logger = get_logger(conf, log_route='object-auditor') self.conf_zero_byte_fps = int(conf.get(