From 91d007426f109dfef2142e28741edd51dcf1fdbc Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Fri, 11 May 2012 09:47:10 -0400 Subject: Eliminate a race condition on instance deletes. - Add constraint and equality conditions to nova.db[.sqlalchemy].api - Use host constraints to ensure the compute api doesn't simply delete an instance from the database that a compute manager has already started to run. This race condition is associated with bug #998117 Change-Id: Id74192d3e66bea073327342f57ce0f26987efd2d --- nova/compute/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index 9f96b8e6b..a3bd93bac 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -980,9 +980,15 @@ class API(base.Base): try: if not instance['host']: # Just update database, nothing else we can do - result = self.db.instance_destroy(context, instance['id']) - QUOTAS.commit(context, reservations) - return result + constraint = self.db.constraint(host=self.db.equal_any(host)) + try: + result = self.db.instance_destroy( + context, instance['uuid'], constraint) + QUOTAS.commit(context, reservations) + return result + except exception.ConstraintNotMet: + # Refresh to get new host information + instance = self.get(context, instance['uuid']) self.update(context, instance, -- cgit