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
This commit is contained in:
parent
d7dcb48511
commit
cd2e7df0b6
@ -118,10 +118,10 @@ class AccountAuditor(Daemon):
|
|||||||
broker.get_info()
|
broker.get_info()
|
||||||
self.logger.increment('passes')
|
self.logger.increment('passes')
|
||||||
self.account_passes += 1
|
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):
|
except (Exception, Timeout):
|
||||||
self.logger.increment('failures')
|
self.logger.increment('failures')
|
||||||
self.account_failures += 1
|
self.account_failures += 1
|
||||||
self.logger.exception(_('ERROR Could not get account info %s'),
|
self.logger.exception(_('ERROR Could not get account info %s'),
|
||||||
(broker.db_file))
|
path)
|
||||||
self.logger.timing_since('timing', start_time)
|
self.logger.timing_since('timing', start_time)
|
||||||
|
@ -187,6 +187,14 @@ class DatabaseBroker(object):
|
|||||||
self.container = container
|
self.container = container
|
||||||
self._db_version = -1
|
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):
|
def initialize(self, put_timestamp=None):
|
||||||
"""
|
"""
|
||||||
Create the DB
|
Create the DB
|
||||||
|
@ -296,8 +296,8 @@ class Replicator(Daemon):
|
|||||||
if objects:
|
if objects:
|
||||||
self.logger.debug(_(
|
self.logger.debug(_(
|
||||||
'Synchronization for %s has fallen more than '
|
'Synchronization for %s has fallen more than '
|
||||||
'%s rows behind; moving on and will try again next pass.') %
|
'%s rows behind; moving on and will try again next pass.'),
|
||||||
(broker.db_file, self.max_diffs * self.per_diff))
|
broker, self.max_diffs * self.per_diff)
|
||||||
self.stats['diff_capped'] += 1
|
self.stats['diff_capped'] += 1
|
||||||
self.logger.increment('diff_caps')
|
self.logger.increment('diff_caps')
|
||||||
else:
|
else:
|
||||||
@ -606,7 +606,7 @@ class ReplicatorRpc(object):
|
|||||||
info = broker.get_replication_info()
|
info = broker.get_replication_info()
|
||||||
except (Exception, Timeout) as e:
|
except (Exception, Timeout) as e:
|
||||||
if 'no such table' in str(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)
|
quarantine_db(broker.db_file, broker.db_type)
|
||||||
return HTTPNotFound()
|
return HTTPNotFound()
|
||||||
raise
|
raise
|
||||||
|
@ -118,10 +118,10 @@ class ContainerAuditor(Daemon):
|
|||||||
broker.get_info()
|
broker.get_info()
|
||||||
self.logger.increment('passes')
|
self.logger.increment('passes')
|
||||||
self.container_passes += 1
|
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):
|
except (Exception, Timeout):
|
||||||
self.logger.increment('failures')
|
self.logger.increment('failures')
|
||||||
self.container_failures += 1
|
self.container_failures += 1
|
||||||
self.logger.exception(_('ERROR Could not get container info %s'),
|
self.logger.exception(_('ERROR Could not get container info %s'),
|
||||||
broker.db_file)
|
path)
|
||||||
self.logger.timing_since('timing', start_time)
|
self.logger.timing_since('timing', start_time)
|
||||||
|
@ -245,7 +245,7 @@ class ContainerSync(Daemon):
|
|||||||
if err:
|
if err:
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
_('ERROR %(db_file)s: %(validate_sync_to_err)s'),
|
_('ERROR %(db_file)s: %(validate_sync_to_err)s'),
|
||||||
{'db_file': broker.db_file,
|
{'db_file': str(broker),
|
||||||
'validate_sync_to_err': err})
|
'validate_sync_to_err': err})
|
||||||
self.container_failures += 1
|
self.container_failures += 1
|
||||||
self.logger.increment('failures')
|
self.logger.increment('failures')
|
||||||
@ -299,7 +299,7 @@ class ContainerSync(Daemon):
|
|||||||
self.container_failures += 1
|
self.container_failures += 1
|
||||||
self.logger.increment('failures')
|
self.logger.increment('failures')
|
||||||
self.logger.exception(_('ERROR Syncing %s'),
|
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):
|
def container_sync_row(self, row, sync_to, sync_key, broker, info):
|
||||||
"""
|
"""
|
||||||
@ -397,14 +397,14 @@ class ContainerSync(Daemon):
|
|||||||
else:
|
else:
|
||||||
self.logger.exception(
|
self.logger.exception(
|
||||||
_('ERROR Syncing %(db_file)s %(row)s'),
|
_('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.container_failures += 1
|
||||||
self.logger.increment('failures')
|
self.logger.increment('failures')
|
||||||
return False
|
return False
|
||||||
except (Exception, Timeout) as err:
|
except (Exception, Timeout) as err:
|
||||||
self.logger.exception(
|
self.logger.exception(
|
||||||
_('ERROR Syncing %(db_file)s %(row)s'),
|
_('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.container_failures += 1
|
||||||
self.logger.increment('failures')
|
self.logger.increment('failures')
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user