From 02c12aade7a0c28c66cb45b54786c90c0ae8fb09 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 18 Feb 2013 02:35:34 +0000 Subject: Move DB thread pooling to DB API loader Fixes bug 1128605 The dbpool code in sqlalchemy session is the wrong place to implement thread pooling as it wraps each individual SQL call to run in its own thread. When combined with SQL server locking, all threads can be eaten waiting on locks with none available to run a 'COMMIT'. The correct place to do thread pooling is around each DB API call. This patch removes dbpool from sqlalchemy and creates a common DB API loader for all openstack projects which implements the following configuration options: db_backend: Full path to DB API backend module (or a known short name if a project chooses to implement a mapping) dbapi_use_tpool: True or False whether to use thread pooling around all DB API calls. DB backend modules must implement a 'get_backend()' method. Example usage for nova/db/api.py would be: """ from nova.openstack.common.db import api as db_api _KNOWN_BACKENDS = {'sqlalchemy': 'nova.db.sqlalchemy.api'} IMPL = db_api.DBAPI(backend_mapping=_KNOWN_BACKENDS) """ NOTE: Enabling thread pooling will be broken until this issue is resolved in eventlet _OR_ until we modify our eventlet.monkey_patch() calls to include 'thread=False': https://bitbucket.org/eventlet/eventlet/issue/137/ Change-Id: Idf14563ea07cf8ccf2a77b3f53659d8528927fc7 --- tests/unit/db/sqlalchemy/test_sqlalchemy.py | 40 ----------------------------- 1 file changed, 40 deletions(-) (limited to 'tests/unit/db/sqlalchemy/test_sqlalchemy.py') diff --git a/tests/unit/db/sqlalchemy/test_sqlalchemy.py b/tests/unit/db/sqlalchemy/test_sqlalchemy.py index c063f0d..6b84f10 100644 --- a/tests/unit/db/sqlalchemy/test_sqlalchemy.py +++ b/tests/unit/db/sqlalchemy/test_sqlalchemy.py @@ -16,8 +16,6 @@ """Unit tests for SQLAlchemy specific code.""" -from eventlet import db_pool - from sqlalchemy import Column, MetaData, Table, UniqueConstraint from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import DateTime, Integer @@ -34,44 +32,6 @@ class TestException(Exception): pass -class DbPoolTestCase(test_utils.BaseTestCase): - def setUp(self): - super(DbPoolTestCase, self).setUp() - if MySQLdb is None: - self.skipTest("Required module MySQLdb missing.") - self.config(sql_dbpool_enable=True) - self.user_id = 'fake' - self.project_id = 'fake' - - def test_db_pool_option(self): - self.config(sql_idle_timeout=11, sql_min_pool_size=21, - sql_max_pool_size=42) - - info = {} - - class FakeConnectionPool(db_pool.ConnectionPool): - def __init__(self, mod_name, **kwargs): - info['module'] = mod_name - info['kwargs'] = kwargs - super(FakeConnectionPool, self).__init__(mod_name, - **kwargs) - - def connect(self, *args, **kwargs): - raise TestException() - - self.stubs.Set(db_pool, 'ConnectionPool', - FakeConnectionPool) - - sql_connection = 'mysql://user:pass@127.0.0.1/nova' - self.assertRaises(TestException, session.create_engine, - sql_connection) - - self.assertEqual(info['module'], MySQLdb) - self.assertEqual(info['kwargs']['max_idle'], 11) - self.assertEqual(info['kwargs']['min_size'], 21) - self.assertEqual(info['kwargs']['max_size'], 42) - - BASE = declarative_base() _TABLE_NAME = '__tmp__test__tmp__' -- cgit