]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix sqlalchemy reuse in multi-backend children
authorEric Harney <eharney@redhat.com>
Wed, 11 Mar 2015 18:00:44 +0000 (14:00 -0400)
committerJohn Griffith <john.griffith@solidfire.com>
Thu, 12 Mar 2015 15:49:48 +0000 (09:49 -0600)
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
cinder/db/base.py
cinder/db/sqlalchemy/api.py

index 06cc096c788307ca7dfadd87171649ec85f48931..8fe5d6724ddc2e62e628ab641ee1bdbf0a285cf8 100644 (file)
@@ -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
+
+
 ###################
 
 
index 69365c6dfb101b1957fcd314033dccfaa477861d..facb71f1c6d9bb6d483b8d747dff37f0847cfa6d 100644 (file)
@@ -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()
index 1a1bbe118b13b7ac48c20186ab654951da9a31f5..ff33c1586d64887a8e82eae2269c15cfed9022cd 100644 (file)
@@ -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'