Task cleanup_running_deleted_instances can now use slave
Deployments that have a slave_connection configured can offload read queries generated by this periodic task there. For deployments with no slave, behavior remains the same. Partially-implements: blueprint periodic-tasks-to-db-slave Change-Id: Ie1e6cdfbefab096a2af62ef636786a5c8f659b13
This commit is contained in:
parent
dcd65f6756
commit
7e1b935acb
|
@ -657,7 +657,7 @@ class ComputeManager(manager.Manager):
|
|||
driver_uuids = self.driver.list_instance_uuids()
|
||||
filters['uuid'] = driver_uuids
|
||||
local_instances = instance_obj.InstanceList.get_by_filters(
|
||||
context, filters)
|
||||
context, filters, use_slave=True)
|
||||
return local_instances
|
||||
except NotImplementedError:
|
||||
pass
|
||||
|
@ -665,7 +665,8 @@ class ComputeManager(manager.Manager):
|
|||
# The driver doesn't support uuids listing, so we'll have
|
||||
# to brute force.
|
||||
driver_instances = self.driver.list_instances()
|
||||
instances = instance_obj.InstanceList.get_by_filters(context, filters)
|
||||
instances = instance_obj.InstanceList.get_by_filters(context, filters,
|
||||
use_slave=True)
|
||||
name_map = dict((instance.name, instance) for instance in instances)
|
||||
local_instances = []
|
||||
for driver_instance in driver_instances:
|
||||
|
@ -5345,7 +5346,8 @@ class ComputeManager(manager.Manager):
|
|||
with utils.temporary_mutation(context, read_deleted="yes"):
|
||||
for instance in self._running_deleted_instances(context):
|
||||
bdms = (block_device_obj.BlockDeviceMappingList.
|
||||
get_by_instance_uuid(context, instance.uuid))
|
||||
get_by_instance_uuid(context, instance.uuid,
|
||||
use_slave=True))
|
||||
|
||||
if action == "log":
|
||||
LOG.warning(_("Detected instance with name label "
|
||||
|
|
|
@ -1183,10 +1183,12 @@ def block_device_mapping_update_or_create(context, values, legacy=True):
|
|||
return IMPL.block_device_mapping_update_or_create(context, values, legacy)
|
||||
|
||||
|
||||
def block_device_mapping_get_all_by_instance(context, instance_uuid):
|
||||
def block_device_mapping_get_all_by_instance(context, instance_uuid,
|
||||
use_slave=False):
|
||||
"""Get all block device mapping belonging to an instance."""
|
||||
return IMPL.block_device_mapping_get_all_by_instance(context,
|
||||
instance_uuid)
|
||||
instance_uuid,
|
||||
use_slave)
|
||||
|
||||
|
||||
def block_device_mapping_get_by_volume_id(context, volume_id,
|
||||
|
|
|
@ -3461,11 +3461,12 @@ def get_snapshot_uuid_by_ec2_id(context, ec2_id):
|
|||
|
||||
|
||||
def _block_device_mapping_get_query(context, session=None,
|
||||
columns_to_join=None):
|
||||
columns_to_join=None, use_slave=False):
|
||||
if columns_to_join is None:
|
||||
columns_to_join = []
|
||||
|
||||
query = model_query(context, models.BlockDeviceMapping, session=session)
|
||||
query = model_query(context, models.BlockDeviceMapping,
|
||||
session=session, use_slave=use_slave)
|
||||
|
||||
for column in columns_to_join:
|
||||
query = query.options(joinedload(column))
|
||||
|
@ -3546,8 +3547,9 @@ def block_device_mapping_update_or_create(context, values, legacy=True):
|
|||
|
||||
|
||||
@require_context
|
||||
def block_device_mapping_get_all_by_instance(context, instance_uuid):
|
||||
return _block_device_mapping_get_query(context).\
|
||||
def block_device_mapping_get_all_by_instance(context, instance_uuid,
|
||||
use_slave=False):
|
||||
return _block_device_mapping_get_query(context, use_slave=use_slave).\
|
||||
filter_by(instance_uuid=instance_uuid).\
|
||||
all()
|
||||
|
||||
|
|
|
@ -175,7 +175,8 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject):
|
|||
class BlockDeviceMappingList(base.ObjectListBase, base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: BlockDeviceMapping <= version 1.1
|
||||
VERSION = '1.1'
|
||||
# Version 1.2: Added use_slave to get_by_instance_uuid
|
||||
VERSION = '1.2'
|
||||
|
||||
fields = {
|
||||
'objects': fields.ListOfObjectsField('BlockDeviceMapping'),
|
||||
|
@ -183,12 +184,13 @@ class BlockDeviceMappingList(base.ObjectListBase, base.NovaObject):
|
|||
child_versions = {
|
||||
'1.0': '1.0',
|
||||
'1.1': '1.1',
|
||||
'1.2': '1.1',
|
||||
}
|
||||
|
||||
@base.remotable_classmethod
|
||||
def get_by_instance_uuid(cls, context, instance_uuid):
|
||||
def get_by_instance_uuid(cls, context, instance_uuid, use_slave=False):
|
||||
db_bdms = db.block_device_mapping_get_all_by_instance(
|
||||
context, instance_uuid)
|
||||
context, instance_uuid, use_slave=use_slave)
|
||||
return base.obj_make_list(
|
||||
context, cls(), BlockDeviceMapping, db_bdms or [])
|
||||
|
||||
|
|
|
@ -2379,7 +2379,8 @@ class CloudTestCase(test.TestCase):
|
|||
|
||||
self.stubs.Set(fake._FakeImageService, 'show', fake_show)
|
||||
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id):
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id,
|
||||
use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'volume_id': volumes[0],
|
||||
'snapshot_id': snapshots[0],
|
||||
|
@ -2453,7 +2454,8 @@ class CloudTestCase(test.TestCase):
|
|||
'max_count': 1}
|
||||
ec2_instance_id = self._run_instance(**kwargs)
|
||||
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id):
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id,
|
||||
use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'volume_id': volumes[0],
|
||||
'snapshot_id': snapshots[0],
|
||||
|
|
|
@ -95,7 +95,7 @@ def fake_compute_volume_snapshot_create(self, context, volume_id,
|
|||
pass
|
||||
|
||||
|
||||
def fake_bdms_get_all_by_instance(context, instance_uuid):
|
||||
def fake_bdms_get_all_by_instance(context, instance_uuid, use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'id': 1,
|
||||
'instance_uuid': instance_uuid,
|
||||
|
|
|
@ -855,7 +855,8 @@ class ServerActionsControllerTest(test.TestCase):
|
|||
|
||||
image_service.create(None, original_image)
|
||||
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id):
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id,
|
||||
use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'volume_id': _fake_id('a'),
|
||||
'source_type': 'snapshot',
|
||||
|
@ -929,7 +930,8 @@ class ServerActionsControllerTest(test.TestCase):
|
|||
|
||||
image_service = glance.get_default_image_service()
|
||||
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id):
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id,
|
||||
use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'volume_id': _fake_id('a'),
|
||||
'source_type': 'snapshot',
|
||||
|
|
|
@ -1021,7 +1021,8 @@ class ServerActionsControllerTest(test.TestCase):
|
|||
|
||||
image_service.create(None, original_image)
|
||||
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id):
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id,
|
||||
use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'volume_id': _fake_id('a'),
|
||||
'source_type': 'snapshot',
|
||||
|
@ -1095,7 +1096,8 @@ class ServerActionsControllerTest(test.TestCase):
|
|||
|
||||
image_service = glance.get_default_image_service()
|
||||
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id):
|
||||
def fake_block_device_mapping_get_all_by_instance(context, inst_id,
|
||||
use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'volume_id': _fake_id('a'),
|
||||
'source_type': 'snapshot',
|
||||
|
|
|
@ -709,7 +709,7 @@ def stub_snapshot_get_all(self, context):
|
|||
stub_snapshot(102, project_id='superduperfake')]
|
||||
|
||||
|
||||
def stub_bdm_get_all_by_instance(context, instance_uuid):
|
||||
def stub_bdm_get_all_by_instance(context, instance_uuid, use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'id': 1, 'source_type': 'volume', 'destination_type': 'volume',
|
||||
'volume_id': 'volume_id1', 'instance_uuid': instance_uuid}),
|
||||
|
|
|
@ -5599,9 +5599,9 @@ class ComputeTestCase(BaseTestCase):
|
|||
self.compute._shutdown_instance(ctxt, inst1, bdms, notify=False).\
|
||||
AndRaise(test.TestingException)
|
||||
block_device_obj.BlockDeviceMappingList.get_by_instance_uuid(ctxt,
|
||||
inst1.uuid).AndReturn(bdms)
|
||||
inst1.uuid, use_slave=True).AndReturn(bdms)
|
||||
block_device_obj.BlockDeviceMappingList.get_by_instance_uuid(ctxt,
|
||||
inst2.uuid).AndReturn(bdms)
|
||||
inst2.uuid, use_slave=True).AndReturn(bdms)
|
||||
self.compute._shutdown_instance(ctxt, inst2, bdms, notify=False).\
|
||||
AndReturn(None)
|
||||
|
||||
|
|
|
@ -660,7 +660,8 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
self.mox.StubOutWithMock(rpcapi, 'terminate_instance')
|
||||
|
||||
db.block_device_mapping_get_all_by_instance(self.context,
|
||||
inst.uuid).AndReturn([])
|
||||
inst.uuid,
|
||||
use_slave=False).AndReturn([])
|
||||
inst.save()
|
||||
self.compute_api._create_reservations(self.context,
|
||||
inst, inst.instance_type_id,
|
||||
|
@ -764,7 +765,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
timeutils.set_time_override(delete_time)
|
||||
|
||||
db.block_device_mapping_get_all_by_instance(
|
||||
self.context, inst.uuid).AndReturn([])
|
||||
self.context, inst.uuid, use_slave=False).AndReturn([])
|
||||
inst.save().AndRaise(test.TestingException)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
@ -1517,7 +1518,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
'is_public': False
|
||||
}
|
||||
|
||||
def fake_get_all_by_instance(context, instance):
|
||||
def fake_get_all_by_instance(context, instance, use_slave=False):
|
||||
return copy.deepcopy(instance_bdms)
|
||||
|
||||
def fake_image_create(context, image_meta, data):
|
||||
|
|
|
@ -472,7 +472,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
inst in driver_instances]},
|
||||
'created_at', 'desc', columns_to_join=None,
|
||||
limit=None, marker=None,
|
||||
use_slave=False).AndReturn(
|
||||
use_slave=True).AndReturn(
|
||||
driver_instances)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
@ -513,7 +513,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
fake_context, filters,
|
||||
'created_at', 'desc', columns_to_join=None,
|
||||
limit=None, marker=None,
|
||||
use_slave=False).AndReturn(all_instances)
|
||||
use_slave=True).AndReturn(all_instances)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class ComputeValidateDeviceTestCase(test.TestCase):
|
|||
self.data = []
|
||||
|
||||
self.stubs.Set(db, 'block_device_mapping_get_all_by_instance',
|
||||
lambda context, instance: self.data)
|
||||
lambda context, instance, use_slave=False: self.data)
|
||||
|
||||
def _update_flavor(self, flavor_info):
|
||||
self.flavor = {
|
||||
|
|
|
@ -3797,7 +3797,8 @@ class AssistedVolumeSnapshotsXmlTest(AssistedVolumeSnapshotsJsonTest):
|
|||
class VolumeAttachmentsSampleBase(ServersSampleBase):
|
||||
def _stub_db_bdms_get_all_by_instance(self, server_id):
|
||||
|
||||
def fake_bdms_get_all_by_instance(context, instance_uui):
|
||||
def fake_bdms_get_all_by_instance(context, instance_uuid,
|
||||
use_slave=False):
|
||||
bdms = [
|
||||
fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'id': 1, 'volume_id': 'a26887c6-c47b-4654-abb5-dfadf7d3f803',
|
||||
|
|
|
@ -30,7 +30,8 @@ class ExtendedVolumesSampleJsonTests(test_servers.ServersSampleBase):
|
|||
|
||||
def _stub_compute_api_get_instance_bdms(self, server_id):
|
||||
|
||||
def fake_bdms_get_all_by_instance(context, instance_uui):
|
||||
def fake_bdms_get_all_by_instance(context, instance_uuid,
|
||||
use_slave=False):
|
||||
bdms = [
|
||||
fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'id': 1, 'volume_id': 'a26887c6-c47b-4654-abb5-dfadf7d3f803',
|
||||
|
|
|
@ -201,7 +201,7 @@ class MetadataTestCase(test.TestCase):
|
|||
'default_ephemeral_device': None,
|
||||
'default_swap_device': None})
|
||||
|
||||
def fake_bdm_get(ctxt, uuid):
|
||||
def fake_bdm_get(ctxt, uuid, use_slave=False):
|
||||
return [fake_block_device.FakeDbBlockDeviceDict(
|
||||
{'volume_id': 87654321,
|
||||
'snapshot_id': None,
|
||||
|
|
Loading…
Reference in New Issue