From cd2e7df0b69bbd269cd3c4170e0fee8186a07c95 Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Tue, 22 Oct 2013 17:18:04 -0600 Subject: [PATCH] Add an __str__ method to brokers A few uses of broker.db_file are in printouts where we do need them, so the administrator may know what's up. Seems like an easy way to get rid of those is to make brokers identify themselves with common __str__. Alternative back-end implementations may supply something other than a filename here, for example a cluster name and a volume name. Note that I'm not sure if correct coercion would occur when brokers are bounced through dictionaries, hence explicit str(). Change-Id: I329788ebd1fbe39ffadcf9f9d5194a74a88dde58 --- swift/account/auditor.py | 4 ++-- swift/common/db.py | 8 ++++++++ swift/common/db_replicator.py | 6 +++--- swift/container/auditor.py | 4 ++-- swift/container/sync.py | 8 ++++---- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/swift/account/auditor.py b/swift/account/auditor.py index 3410089d6d..e93e8a9ca6 100644 --- a/swift/account/auditor.py +++ b/swift/account/auditor.py @@ -118,10 +118,10 @@ class AccountAuditor(Daemon): broker.get_info() self.logger.increment('passes') self.account_passes += 1 - self.logger.debug(_('Audit passed for %s') % broker.db_file) + self.logger.debug(_('Audit passed for %s') % broker) except (Exception, Timeout): self.logger.increment('failures') self.account_failures += 1 self.logger.exception(_('ERROR Could not get account info %s'), - (broker.db_file)) + path) self.logger.timing_since('timing', start_time) diff --git a/swift/common/db.py b/swift/common/db.py index aca0cc6d8f..5e3b1e221e 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -187,6 +187,14 @@ class DatabaseBroker(object): self.container = container self._db_version = -1 + def __str__(self): + """ + Returns a string indentifying the entity under broker to a human. + The baseline implementation returns a full pathname to a database. + This is vital for useful diagnostics. + """ + return self.db_file + def initialize(self, put_timestamp=None): """ Create the DB diff --git a/swift/common/db_replicator.py b/swift/common/db_replicator.py index 1ac38ac5e0..3481cba415 100644 --- a/swift/common/db_replicator.py +++ b/swift/common/db_replicator.py @@ -296,8 +296,8 @@ class Replicator(Daemon): if objects: self.logger.debug(_( 'Synchronization for %s has fallen more than ' - '%s rows behind; moving on and will try again next pass.') % - (broker.db_file, self.max_diffs * self.per_diff)) + '%s rows behind; moving on and will try again next pass.'), + broker, self.max_diffs * self.per_diff) self.stats['diff_capped'] += 1 self.logger.increment('diff_caps') else: @@ -606,7 +606,7 @@ class ReplicatorRpc(object): info = broker.get_replication_info() except (Exception, Timeout) as e: if 'no such table' in str(e): - self.logger.error(_("Quarantining DB %s") % broker.db_file) + self.logger.error(_("Quarantining DB %s"), broker) quarantine_db(broker.db_file, broker.db_type) return HTTPNotFound() raise diff --git a/swift/container/auditor.py b/swift/container/auditor.py index f0d414fee5..62491a3976 100644 --- a/swift/container/auditor.py +++ b/swift/container/auditor.py @@ -118,10 +118,10 @@ class ContainerAuditor(Daemon): broker.get_info() self.logger.increment('passes') self.container_passes += 1 - self.logger.debug(_('Audit passed for %s'), broker.db_file) + self.logger.debug(_('Audit passed for %s'), broker) except (Exception, Timeout): self.logger.increment('failures') self.container_failures += 1 self.logger.exception(_('ERROR Could not get container info %s'), - broker.db_file) + path) self.logger.timing_since('timing', start_time) diff --git a/swift/container/sync.py b/swift/container/sync.py index 9594c852fb..5fd7b34cdb 100644 --- a/swift/container/sync.py +++ b/swift/container/sync.py @@ -245,7 +245,7 @@ class ContainerSync(Daemon): if err: self.logger.info( _('ERROR %(db_file)s: %(validate_sync_to_err)s'), - {'db_file': broker.db_file, + {'db_file': str(broker), 'validate_sync_to_err': err}) self.container_failures += 1 self.logger.increment('failures') @@ -299,7 +299,7 @@ class ContainerSync(Daemon): self.container_failures += 1 self.logger.increment('failures') self.logger.exception(_('ERROR Syncing %s'), - broker.db_file if broker else path) + broker if broker else path) def container_sync_row(self, row, sync_to, sync_key, broker, info): """ @@ -397,14 +397,14 @@ class ContainerSync(Daemon): else: self.logger.exception( _('ERROR Syncing %(db_file)s %(row)s'), - {'db_file': broker.db_file, 'row': row}) + {'db_file': str(broker), 'row': row}) self.container_failures += 1 self.logger.increment('failures') return False except (Exception, Timeout) as err: self.logger.exception( _('ERROR Syncing %(db_file)s %(row)s'), - {'db_file': broker.db_file, 'row': row}) + {'db_file': str(broker), 'row': row}) self.container_failures += 1 self.logger.increment('failures') return False