Reduce the scope of RT work while holding the big lock
This makes the RT.update_available_resource() method do what it can in the way of prep work before grabbing the lock to update the database stats. Change-Id: I1132e2ab99427688529566c1a1fffb33eab07f3f Related-Bug: #1371677
This commit is contained in:
parent
8cf117af1c
commit
84ff466c83
|
@ -301,7 +301,6 @@ class ResourceTracker(object):
|
|||
notifier.info(context, 'compute.metrics.update', metrics_info)
|
||||
return metrics
|
||||
|
||||
@utils.synchronized(COMPUTE_RESOURCE_SEMAPHORE)
|
||||
def update_available_resource(self, context):
|
||||
"""Override in-memory calculations of compute node resource usage based
|
||||
on data audited from the hypervisor layer.
|
||||
|
@ -330,6 +329,10 @@ class ResourceTracker(object):
|
|||
|
||||
self._report_hypervisor_resource_view(resources)
|
||||
|
||||
return self._update_available_resource(context, resources)
|
||||
|
||||
@utils.synchronized(COMPUTE_RESOURCE_SEMAPHORE)
|
||||
def _update_available_resource(self, context, resources):
|
||||
if 'pci_passthrough_devices' in resources:
|
||||
if not self.pci_tracker:
|
||||
self.pci_tracker = pci_manager.PciDevTracker()
|
||||
|
|
|
@ -1422,6 +1422,20 @@ class TrackerPeriodicTestCase(BaseTrackerTestCase):
|
|||
self.tracker.update_available_resource(self.context)
|
||||
self.assertEqual(2, self.update_call_count)
|
||||
|
||||
def test_update_available_resource_calls_locked_inner(self):
|
||||
@mock.patch.object(self.tracker, 'driver')
|
||||
@mock.patch.object(self.tracker,
|
||||
'_update_available_resource')
|
||||
@mock.patch.object(self.tracker, '_verify_resources')
|
||||
@mock.patch.object(self.tracker, '_report_hypervisor_resource_view')
|
||||
def _test(mock_rhrv, mock_vr, mock_uar, mock_driver):
|
||||
resources = {'there is someone in my head': 'but it\'s not me'}
|
||||
mock_driver.get_available_resource.return_value = resources
|
||||
self.tracker.update_available_resource(self.context)
|
||||
mock_uar.assert_called_once_with(self.context, resources)
|
||||
|
||||
_test()
|
||||
|
||||
|
||||
class StatsDictTestCase(BaseTrackerTestCase):
|
||||
"""Test stats handling for a virt driver that provides
|
||||
|
|
Loading…
Reference in New Issue