diff --git a/ceilometer/alarm/storage/impl_sqlalchemy.py b/ceilometer/alarm/storage/impl_sqlalchemy.py index 18fbbc897..9ea599892 100644 --- a/ceilometer/alarm/storage/impl_sqlalchemy.py +++ b/ceilometer/alarm/storage/impl_sqlalchemy.py @@ -77,10 +77,13 @@ class Connection(base.Connection): ) def __init__(self, url): - self._engine_facade = db_session.EngineFacade( - url, - **dict(cfg.CONF.database.items()) - ) + # Set max_retries to 0, since oslo.db in certain cases may attempt + # to retry making the db connection retried max_retries ^ 2 times + # in failure case and db reconnection has already been implemented + # in storage.__init__.get_connection_from_config function + options = dict(cfg.CONF.database.items()) + options['max_retries'] = 0 + self._engine_facade = db_session.EngineFacade(url, **options) def upgrade(self): # NOTE(gordc): to minimise memory, only import migration when needed diff --git a/ceilometer/event/storage/impl_sqlalchemy.py b/ceilometer/event/storage/impl_sqlalchemy.py index 89038b3f8..35f992ce6 100644 --- a/ceilometer/event/storage/impl_sqlalchemy.py +++ b/ceilometer/event/storage/impl_sqlalchemy.py @@ -85,10 +85,13 @@ class Connection(base.Connection): ) def __init__(self, url): - self._engine_facade = db_session.EngineFacade( - url, - **dict(cfg.CONF.database.items()) - ) + # Set max_retries to 0, since oslo.db in certain cases may attempt + # to retry making the db connection retried max_retries ^ 2 times + # in failure case and db reconnection has already been implemented + # in storage.__init__.get_connection_from_config function + options = dict(cfg.CONF.database.items()) + options['max_retries'] = 0 + self._engine_facade = db_session.EngineFacade(url, **options) def upgrade(self): # NOTE(gordc): to minimise memory, only import migration when needed diff --git a/ceilometer/storage/__init__.py b/ceilometer/storage/__init__.py index 3c53a9cc1..f4c803f91 100644 --- a/ceilometer/storage/__init__.py +++ b/ceilometer/storage/__init__.py @@ -88,21 +88,24 @@ class StorageBadAggregate(Exception): code = 400 -# Convert retry_interval secs to msecs for retry decorator -@retrying.retry(wait_fixed=cfg.CONF.database.retry_interval * 1000, - stop_max_attempt_number=cfg.CONF.database.max_retries - if cfg.CONF.database.max_retries >= 0 - else None) def get_connection_from_config(conf, purpose=None): - if conf.database_connection: - conf.set_override('connection', conf.database_connection, - group='database') - namespace = 'ceilometer.metering.storage' - url = conf.database.connection - if purpose: - namespace = 'ceilometer.%s.storage' % purpose - url = getattr(conf.database, '%s_connection' % purpose) or url - return get_connection(url, namespace) + retries = conf.database.max_retries + + # Convert retry_interval secs to msecs for retry decorator + @retrying.retry(wait_fixed=conf.database.retry_interval * 1000, + stop_max_attempt_number=retries if retries >= 0 else None) + def _inner(): + if conf.database_connection: + conf.set_override('connection', conf.database_connection, + group='database') + namespace = 'ceilometer.metering.storage' + url = conf.database.connection + if purpose: + namespace = 'ceilometer.%s.storage' % purpose + url = getattr(conf.database, '%s_connection' % purpose) or url + return get_connection(url, namespace) + + return _inner() def get_connection(url, namespace): diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index fcb39ba34..982898e01 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -221,11 +221,9 @@ class Connection(base.Connection): # to retry making the db connection retried max_retries ^ 2 times # in failure case and db reconnection has already been implemented # in storage.__init__.get_connection_from_config function - cfg.CONF.set_override('max_retries', 0, group='database') - self._engine_facade = db_session.EngineFacade( - url, - **dict(cfg.CONF.database.items()) - ) + options = dict(cfg.CONF.database.items()) + options['max_retries'] = 0 + self._engine_facade = db_session.EngineFacade(url, **options) def upgrade(self): # NOTE(gordc): to minimise memory, only import migration when needed