From 2cc0dbe3936e21f52c27bc945e2d999c40526b32 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 11 Mar 2015 14:00:44 -0400 Subject: [PATCH] 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 --- cinder/db/api.py | 16 ++++++++++++++++ cinder/db/base.py | 1 + cinder/db/sqlalchemy/api.py | 4 ++++ 3 files changed, 21 insertions(+) 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' -- 2.45.2