From 4251bba3bd456f7ba1c7481bb84d839a5fafc757 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 15 May 2013 09:23:26 +0000 Subject: [PATCH] Don't update API cell on get_nwinfo Every call to get_instance_nw_info() updates an instance's info_cache. The purpose of this is to make sure we're constantly healing the info_cache table. However, this causes a lot of unneeded updates traveling up to the API cell. Cells has its own periodic task that heals all instance data. Fixes bug 1180304 Change-Id: I07774712a6358999fd1fdd0f5a90c6f05e3d8d6e --- nova/cells/messaging.py | 4 ++-- nova/db/api.py | 13 ++---------- nova/network/api.py | 26 ++++++++++++++++++++---- nova/tests/cells/test_cells_messaging.py | 6 ++---- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/nova/cells/messaging.py b/nova/cells/messaging.py index 60f11ad12535..1ea68d29fe54 100644 --- a/nova/cells/messaging.py +++ b/nova/cells/messaging.py @@ -847,8 +847,8 @@ class _BroadcastMessageMethods(_BaseMessageMethods): self.db.instance_create(message.ctxt, instance) if info_cache: try: - self.db.instance_info_cache_update(message.ctxt, - instance_uuid, info_cache, update_cells=False) + self.db.instance_info_cache_update( + message.ctxt, instance_uuid, info_cache) except exception.InstanceInfoCacheNotFound: # Can happen if we try to update a deleted instance's # network information. diff --git a/nova/db/api.py b/nova/db/api.py index 322247311777..677ed771b903 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -719,22 +719,13 @@ def instance_info_cache_get(context, instance_uuid): return IMPL.instance_info_cache_get(context, instance_uuid) -def instance_info_cache_update(context, instance_uuid, values, - update_cells=True): +def instance_info_cache_update(context, instance_uuid, values): """Update an instance info cache record in the table. :param instance_uuid: = uuid of info cache's instance :param values: = dict containing column values to update """ - rv = IMPL.instance_info_cache_update(context, instance_uuid, values) - if update_cells: - try: - cells_rpcapi.CellsAPI().instance_info_cache_update_at_top( - context, rv) - except Exception: - LOG.exception(_("Failed to notify cells of instance info " - "cache update")) - return rv + return IMPL.instance_info_cache_update(context, instance_uuid, values) def instance_info_cache_delete(context, instance_uuid): diff --git a/nova/network/api.py b/nova/network/api.py index 26bf0344677e..1654bb32c3fa 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -21,6 +21,7 @@ import functools import inspect +from nova.cells import rpcapi as cells_rpcapi from nova.compute import flavors from nova.db import base from nova import exception @@ -64,7 +65,8 @@ def refresh_cache(f): def update_instance_cache_with_nw_info(api, context, instance, - nw_info=None, conductor_api=None): + nw_info=None, conductor_api=None, + update_cells=True): try: if not isinstance(nw_info, network_model.NetworkInfo): nw_info = None @@ -73,9 +75,20 @@ def update_instance_cache_with_nw_info(api, context, instance, # update cache cache = {'network_info': nw_info.json()} if conductor_api: - conductor_api.instance_info_cache_update(context, instance, cache) + rv = conductor_api.instance_info_cache_update(context, + instance, + cache) else: - api.db.instance_info_cache_update(context, instance['uuid'], cache) + rv = api.db.instance_info_cache_update(context, + instance['uuid'], + cache) + if update_cells: + cells_api = cells_rpcapi.CellsAPI() + try: + cells_api.instance_info_cache_update_at_top(context, rv) + except Exception: + LOG.exception(_("Failed to notify cells of instance info " + "cache update")) except Exception: LOG.exception(_('Failed storing info cache'), instance=instance) @@ -366,8 +379,13 @@ class API(base.Base): def get_instance_nw_info(self, context, instance, conductor_api=None): """Returns all network info related to an instance.""" result = self._get_instance_nw_info(context, instance) + # NOTE(comstud): Don't update API cell with new info_cache every + # time we pull network info for an instance. The periodic healing + # of info_cache causes too many cells messages. Healing the API + # will happen separately. update_instance_cache_with_nw_info(self, context, instance, - result, conductor_api) + result, conductor_api, + update_cells=False) return result def _get_instance_nw_info(self, context, instance): diff --git a/nova/tests/cells/test_cells_messaging.py b/nova/tests/cells/test_cells_messaging.py index 51a7929756c4..1de39de1f98f 100644 --- a/nova/tests/cells/test_cells_messaging.py +++ b/nova/tests/cells/test_cells_messaging.py @@ -1033,8 +1033,7 @@ class CellsBroadcastMethodsTestCase(test.TestCase): expected_instance, update_cells=False) self.tgt_db_inst.instance_info_cache_update(self.ctxt, 'fake_uuid', - expected_info_cache, - update_cells=False) + expected_info_cache) self.mox.ReplayAll() self.src_msg_runner.instance_update_at_top(self.ctxt, fake_instance) @@ -1086,8 +1085,7 @@ class CellsBroadcastMethodsTestCase(test.TestCase): expected_instance, update_cells=False) self.tgt_db_inst.instance_info_cache_update(self.ctxt, 'fake_uuid', - expected_info_cache, - update_cells=False) + expected_info_cache) self.mox.ReplayAll() self.src_msg_runner.instance_update_at_top(self.ctxt, fake_instance)