summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2013-03-11 14:02:30 -0700
committerChris Behrens <cbehrens@codestud.com>2013-03-11 16:28:29 -0700
commitf398b9e195cda582bad57396b097dec274384c07 (patch)
tree86c616b8adc8583d34b6ad60c494995d6ee4e7ba
parentf543f347c84e7f5de2c584ca55363e4dee5b0a3d (diff)
downloadnova-f398b9e195cda582bad57396b097dec274384c07.tar.gz
nova-f398b9e195cda582bad57396b097dec274384c07.tar.xz
nova-f398b9e195cda582bad57396b097dec274384c07.zip
Force resource updates to update updated_at
When there's no changes in resources, compute_node_update (and other DB update calls) won't modify 'updated_at'. 'updated_at' is what is used to invalidate the cache in the scheduler's host_manager. Because of a race with the compute manager, the scheduler could be out of sync with the compute_nodes table but have a newer time on its cache. By always updating 'updated_at' on resource updates, the periodic task will be sure to invalidate any bad cache the scheduler has. Fixes bug 1153778 Change-Id: I19b51a5b84f472cd0f4de6460a4edb540cc62da2
-rw-r--r--nova/db/sqlalchemy/api.py5
-rw-r--r--nova/tests/test_db_api.py6
2 files changed, 11 insertions, 0 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 96c77bce3..368cd9761 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -530,6 +530,11 @@ def compute_node_update(context, compute_id, values, prune_stats=False):
with session.begin():
_update_stats(context, stats, compute_id, session, prune_stats)
compute_ref = _compute_node_get(context, compute_id, session=session)
+ # Always update this, even if there's going to be no other
+ # changes in data. This ensures that we invalidate the
+ # scheduler cache of compute node data in case of races.
+ if 'updated_at' not in values:
+ values['updated_at'] = timeutils.utcnow()
convert_datetimes(values, 'created_at', 'deleted_at', 'updated_at')
compute_ref.update(values)
return compute_ref
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 769ddaea2..b779affaf 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -1511,6 +1511,12 @@ class CapacityTestCase(test.TestCase):
self.assertEqual(2, int(stats['num_proj_12345']))
self.assertEqual(1, int(stats['num_tribbles']))
+ def test_compute_node_update_always_updates_updated_at(self):
+ item = self._create_helper('host1')
+ item_updated = db.compute_node_update(self.ctxt,
+ item['id'], {})
+ self.assertNotEqual(item['updated_at'], item_updated['updated_at'])
+
def test_compute_node_stat_prune(self):
item = self._create_helper('host1')
for stat in item['stats']: