From: Eric Harney Date: Wed, 11 Mar 2015 18:00:44 +0000 (-0400) Subject: Fix sqlalchemy reuse in multi-backend children X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2cc0dbe3936e21f52c27bc945e2d999c40526b32;p=openstack-build%2Fcinder-build.git Fix sqlalchemy reuse in multi-backend children Multi-backend breaks because sqlalchemy objects are shared between child backends. When creating a new service (Base), call dispose to reset the sqlalchemy object and connection. Change-Id: I9d937c5b2fa850edc5523f26e031f59cad5a9e7e Closes-Bug: #1417018 --- diff --git a/cinder/db/api.py b/cinder/db/api.py index 06cc096c7..8fe5d6724 100644 --- a/cinder/db/api.py +++ b/cinder/db/api.py @@ -67,6 +67,22 @@ _BACKEND_MAPPING = {'sqlalchemy': 'cinder.db.sqlalchemy.api'} IMPL = db_concurrency.TpoolDbapiWrapper(CONF, _BACKEND_MAPPING) +################### + +def dispose_engine(): + """Force the engine to establish new connections.""" + + # FIXME(jdg): When using sqlite if we do the dispose + # we seem to lose our DB here. Adding this check + # means we don't do the dispose, but we keep our sqlite DB + # This likely isn't the best way to handle this + + if 'sqlite' not in IMPL.get_engine().name: + return IMPL.dispose_engine() + else: + return + + ################### diff --git a/cinder/db/base.py b/cinder/db/base.py index 69365c6df..facb71f1c 100644 --- a/cinder/db/base.py +++ b/cinder/db/base.py @@ -39,3 +39,4 @@ class Base(object): if not db_driver: db_driver = CONF.db_driver self.db = importutils.import_module(db_driver) # pylint: disable=C0103 + self.db.dispose_engine() diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 1a1bbe118..ff33c1586 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -90,6 +90,10 @@ def get_session(**kwargs): facade = _create_facade_lazily() return facade.get_session(**kwargs) + +def dispose_engine(): + get_engine().dispose() + _DEFAULT_QUOTA_NAME = 'default'