diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-27 17:22:27 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-27 17:22:27 +0000 |
| commit | 7caa6e7755a945cd0840e033c974f4b2d1a73770 (patch) | |
| tree | 9b235e35f53b9aef70dfc5a98f3b4f7b5a5cbcb7 | |
| parent | aa8bffb3ac1dfb86bb9ff213e74c518aa058c224 (diff) | |
| parent | 3fd86122ca7085dd6112d50ea831eaf36e40e882 (diff) | |
Merge "Improve filter_scheduler performance"
| -rw-r--r-- | nova/db/api.py | 4 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 15 | ||||
| -rw-r--r-- | nova/scheduler/host_manager.py | 3 | ||||
| -rw-r--r-- | nova/tests/scheduler/fakes.py | 3 | ||||
| -rw-r--r-- | nova/tests/scheduler/test_host_manager.py | 4 |
5 files changed, 17 insertions, 12 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index d3c55c332..cbf609e06 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -563,9 +563,9 @@ def instance_get(context, instance_id): return IMPL.instance_get(context, instance_id) -def instance_get_all(context): +def instance_get_all(context, columns_to_join=None): """Get all instances.""" - return IMPL.instance_get_all(context) + return IMPL.instance_get_all(context, columns_to_join=columns_to_join) def instance_get_all_by_filters(context, filters, sort_key='created_at', diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 1c323d106..26243a0e1 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1455,13 +1455,14 @@ def _build_instance_get(context, session=None): @require_admin_context -def instance_get_all(context): - return model_query(context, models.Instance).\ - options(joinedload('info_cache')).\ - options(joinedload('security_groups')).\ - options(joinedload('metadata')).\ - options(joinedload('instance_type')).\ - all() +def instance_get_all(context, columns_to_join=None): + if columns_to_join is None: + columns_to_join = ['info_cache', 'security_groups', + 'metadata', 'instance_type'] + query = model_query(context, models.Instance) + for column in columns_to_join: + query = query.options(joinedload(column)) + return query.all() @require_context diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index 2d5f41bae..6de5ebc8f 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -333,7 +333,8 @@ class HostManager(object): host_state_map[host] = host_state # "Consume" resources from the host the instance resides on. - instances = db.instance_get_all(context) + instances = db.instance_get_all(context, + columns_to_join=['instance_type']) for instance in instances: host = instance['host'] if not host: diff --git a/nova/tests/scheduler/fakes.py b/nova/tests/scheduler/fakes.py index 83fbfe8b7..29d4807ac 100644 --- a/nova/tests/scheduler/fakes.py +++ b/nova/tests/scheduler/fakes.py @@ -139,4 +139,5 @@ def mox_host_manager_db_calls(mock, context): mock.StubOutWithMock(db, 'instance_get_all') db.compute_node_get_all(mox.IgnoreArg()).AndReturn(COMPUTE_NODES) - db.instance_get_all(mox.IgnoreArg()).AndReturn(INSTANCES) + db.instance_get_all(mox.IgnoreArg(), + columns_to_join=['instance_type']).AndReturn(INSTANCES) diff --git a/nova/tests/scheduler/test_host_manager.py b/nova/tests/scheduler/test_host_manager.py index 987bffea1..d28e51c00 100644 --- a/nova/tests/scheduler/test_host_manager.py +++ b/nova/tests/scheduler/test_host_manager.py @@ -250,7 +250,9 @@ class HostManagerTestCase(test.TestCase): db.compute_node_get_all(context).AndReturn(fakes.COMPUTE_NODES) # Invalid service host_manager.LOG.warn("No service for compute ID 5") - db.instance_get_all(context).AndReturn(fakes.INSTANCES) + db.instance_get_all(context, + columns_to_join=['instance_type']).AndReturn( + fakes.INSTANCES) self.mox.ReplayAll() host_states = self.host_manager.get_all_host_states(context, topic) |
