Let update_available_resource hit 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.

Change-Id: Ie663ccc4e3e4334af4bdf75a95689c41ecc959b9
Blueprint: juno-slaveification
This commit is contained in:
Michael H Wilson 2014-08-19 09:16:20 -07:00
parent 2a97e1afe6
commit e6fed3c7f2
8 changed files with 46 additions and 28 deletions

View File

@ -5741,7 +5741,8 @@ class ComputeManager(manager.Manager):
new_resource_tracker_dict[nodename] = rt
# Delete orphan compute node not reported by driver but still in db
compute_nodes_in_db = self._get_compute_nodes_in_db(context)
compute_nodes_in_db = self._get_compute_nodes_in_db(context,
use_slave=True)
for cn in compute_nodes_in_db:
if cn.hypervisor_hostname not in nodenames:
@ -5750,12 +5751,15 @@ class ComputeManager(manager.Manager):
self._resource_tracker_dict = new_resource_tracker_dict
def _get_compute_nodes_in_db(self, context):
service = objects.Service.get_by_compute_host(context, self.host)
def _get_compute_nodes_in_db(self, context, use_slave=False):
service = objects.Service.get_by_compute_host(context, self.host,
use_slave=use_slave)
if not service:
LOG.error(_("No service record for host %s"), self.host)
return []
return objects.ComputeNodeList.get_by_service(context, service)
return objects.ComputeNodeList.get_by_service(context,
service,
use_slave=use_slave)
@periodic_task.periodic_task(
spacing=CONF.running_deleted_instance_poll_interval)

View File

@ -133,10 +133,12 @@ def service_destroy(context, service_id):
return IMPL.service_destroy(context, service_id)
def service_get(context, service_id, with_compute_node=False):
def service_get(context, service_id, with_compute_node=False,
use_slave=False):
"""Get a service or raise if it does not exist."""
return IMPL.service_get(context, service_id,
with_compute_node=with_compute_node)
with_compute_node=with_compute_node,
use_slave=use_slave)
def service_get_by_host_and_topic(context, host, topic):
@ -159,12 +161,13 @@ def service_get_all_by_host(context, host):
return IMPL.service_get_all_by_host(context, host)
def service_get_by_compute_host(context, host):
def service_get_by_compute_host(context, host, use_slave=False):
"""Get the service entry for a given compute host.
Returns the service entry joined with the compute_node entry.
"""
return IMPL.service_get_by_compute_host(context, host)
return IMPL.service_get_by_compute_host(context, host,
use_slave=use_slave)
def service_get_by_args(context, host, binary):

View File

@ -430,8 +430,10 @@ def service_destroy(context, service_id):
soft_delete(synchronize_session=False)
def _service_get(context, service_id, with_compute_node=True, session=None):
query = model_query(context, models.Service, session=session).\
def _service_get(context, service_id, with_compute_node=True, session=None,
use_slave=False):
query = model_query(context, models.Service, session=session,
use_slave=use_slave).\
filter_by(id=service_id)
if with_compute_node:
@ -445,9 +447,11 @@ def _service_get(context, service_id, with_compute_node=True, session=None):
@require_admin_context
def service_get(context, service_id, with_compute_node=False):
def service_get(context, service_id, with_compute_node=False,
use_slave=False):
return _service_get(context, service_id,
with_compute_node=with_compute_node)
with_compute_node=with_compute_node,
use_slave=use_slave)
@require_admin_context
@ -485,8 +489,9 @@ def service_get_all_by_host(context, host):
@require_admin_context
def service_get_by_compute_host(context, host):
result = model_query(context, models.Service, read_deleted="no").\
def service_get_by_compute_host(context, host, use_slave=False):
result = model_query(context, models.Service, read_deleted="no",
use_slave=use_slave).\
options(joinedload('compute_node')).\
filter_by(host=host).\
filter_by(topic=CONF.compute_topic).\

View File

@ -142,7 +142,8 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
# Version 1.2 Add get_by_service()
# Version 1.3 ComputeNode version 1.4
# Version 1.4 ComputeNode version 1.5
VERSION = '1.4'
# Version 1.5 Add use_slave to get_by_service
VERSION = '1.5'
fields = {
'objects': fields.ListOfObjectsField('ComputeNode'),
}
@ -153,6 +154,7 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
'1.2': '1.3',
'1.3': '1.4',
'1.4': '1.5',
'1.5': '1.5',
}
@base.remotable_classmethod
@ -169,12 +171,13 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
db_computes)
@base.remotable_classmethod
def _get_by_service(cls, context, service_id):
def _get_by_service(cls, context, service_id, use_slave=False):
db_service = db.service_get(context, service_id,
with_compute_node=True)
with_compute_node=True,
use_slave=use_slave)
return base.obj_make_list(context, cls(context), objects.ComputeNode,
db_service['compute_node'])
@classmethod
def get_by_service(cls, context, service):
return cls._get_by_service(context, service.id)
def get_by_service(cls, context, service, use_slave=False):
return cls._get_by_service(context, service.id, use_slave=use_slave)

View File

@ -30,7 +30,8 @@ class Service(base.NovaPersistentObject, base.NovaObject):
# Version 1.1: Added compute_node nested object
# Version 1.2: String attributes updated to support unicode
# Version 1.3: ComputeNode version 1.5
VERSION = '1.3'
# Version 1.4: Added use_slave to get_by_compute_host
VERSION = '1.4'
fields = {
'id': fields.IntegerField(read_only=True),
@ -104,7 +105,7 @@ class Service(base.NovaPersistentObject, base.NovaObject):
return cls._from_db_object(context, cls(), db_service)
@base.remotable_classmethod
def get_by_compute_host(cls, context, host):
def get_by_compute_host(cls, context, host, use_slave=False):
db_service = db.service_get_by_compute_host(context, host)
return cls._from_db_object(context, cls(), db_service)
@ -138,7 +139,8 @@ class ServiceList(base.ObjectListBase, base.NovaObject):
# Version 1.0: Initial version
# Service <= version 1.2
# Version 1.1 Service version 1.3
VERSION = '1.1'
# Version 1.2: Service version 1.4
VERSION = '1.2'
fields = {
'objects': fields.ListOfObjectsField('Service'),
@ -147,6 +149,7 @@ class ServiceList(base.ObjectListBase, base.NovaObject):
'1.0': '1.2',
# NOTE(danms): Service was at 1.2 before we added this
'1.1': '1.3',
'1.2': '1.4',
}
@base.remotable_classmethod

View File

@ -176,7 +176,7 @@ class BaseTestCase(test.TestCase):
self.compute.driver, NODENAME)
self.compute._resource_tracker_dict[NODENAME] = fake_rt
def fake_get_compute_nodes_in_db(context):
def fake_get_compute_nodes_in_db(context, use_slave=False):
fake_compute_nodes = [{'local_gb': 259,
'vcpus_used': 0,
'deleted': 0,

View File

@ -84,7 +84,7 @@ class MultiNodeComputeTestCase(BaseTestCase):
self.conductor = self.start_service('conductor',
manager=CONF.conductor.manager)
def fake_get_compute_nodes_in_db(context):
def fake_get_compute_nodes_in_db(context, use_slave=False):
fake_compute_nodes = [{'local_gb': 259,
'vcpus_used': 0,
'deleted': 0,
@ -150,7 +150,7 @@ class MultiNodeComputeTestCase(BaseTestCase):
context=ctx, hypervisor_hostname='B', id=3),
]
def fake_get_compute_nodes_in_db(context):
def fake_get_compute_nodes_in_db(context, use_slave=False):
return fake_compute_nodes
def fake_compute_node_delete(context, compute_node_id):

View File

@ -936,7 +936,7 @@ object_data = {
'BlockDeviceMapping': '1.1-9968ffe513e7672484b0f528b034cd0f',
'BlockDeviceMappingList': '1.2-a6df0a8ef84d6bbaba51143499e9bed2',
'ComputeNode': '1.5-57ce5a07c727ffab6c51723bb8dccbfe',
'ComputeNodeList': '1.4-a993fa58c16f423c72496c7555e99987',
'ComputeNodeList': '1.5-a1641ab314063538470d57daaa5c7831',
'DNSDomain': '1.0-5bdc288d7c3b723ce86ede998fd5c9ba',
'DNSDomainList': '1.0-cfb3e7e82be661501c31099523154db4',
'EC2InstanceMapping': '1.0-627baaf4b12c9067200979bdc4558a99',
@ -977,8 +977,8 @@ object_data = {
'SecurityGroupList': '1.0-528e6448adfeeb78921ebeda499ab72f',
'SecurityGroupRule': '1.1-a9175baf7664439af1a16c2010b55576',
'SecurityGroupRuleList': '1.1-667fca3a9928f23d2d10e61962c55f3c',
'Service': '1.3-5a3df338c669e1148251431370b440ef',
'ServiceList': '1.1-818bc6a463721e42fbb4fbf6f68c4eeb',
'Service': '1.4-82bbfd46a744a9c89bc44b47a1b81683',
'ServiceList': '1.2-7529974a2565ec1eda23124a16aebe43',
'TestSubclassedObject': '1.6-c63feb2f2533b7d075490c04a2cc10dd',
'VirtualInterface': '1.0-10fdac4c704102b6d57d6936d6d790d2',
'VirtualInterfaceList': '1.0-accbf02628a8063c1d885077a2bf49b6',