From 92c3a2c173201f99d1684db628afe4a21d209456 Mon Sep 17 00:00:00 2001 From: Brian Elliott Date: Thu, 4 Apr 2013 16:16:12 +0000 Subject: [PATCH] Optimize resource tracker queries for instances instance_get_all_by_host_and_node() had 4 different joins being done. The resource tracker is the only consumer of this method and does not need the joins. This optimization will save many unnecessary rows from being fetched during the update_available_resource() audit task. Change-Id: I414c219e4563634e270007fe3d0fa980b273e795 --- nova/tests/test_db_api.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 23b8ebcb..56d0685b 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -55,7 +55,8 @@ class DbTestCase(test.TestCase): def create_instances_with_args(self, **kwargs): args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1', - 'project_id': self.project_id, 'vm_state': 'fake'} + 'node': 'node1', 'project_id': self.project_id, + 'vm_state': 'fake'} if 'context' in kwargs: ctxt = kwargs.pop('context') args['project_id'] = ctxt.project_id @@ -151,6 +152,19 @@ class DbApiTestCase(DbTestCase): else: self.assertTrue(result[1]['deleted']) + def test_instance_get_all_by_host_and_node_no_join(self): + # Test that system metadata is not joined. + sys_meta = {'foo': 'bar'} + expected = self.create_instances_with_args(system_metadata=sys_meta) + + elevated = self.context.elevated() + instances = db.instance_get_all_by_host_and_node(elevated, 'host1', + 'node1') + self.assertEqual(1, len(instances)) + instance = instances[0] + self.assertEqual(expected['uuid'], instance['uuid']) + self.assertFalse('system_metadata' in dict(instance)) + def test_migration_get_unconfirmed_by_dest_compute(self): ctxt = context.get_admin_context()