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
This commit is contained in:
Brian Elliott
2013-04-04 16:16:12 +00:00
parent 61565724b8
commit 92c3a2c173

View File

@@ -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()