Don't load non-referenced resources from DB
During a convergence check operation, we should never load resources from the database. However, all resources will inevitably be created whenever we do stack[some_resource]. Previously, resources not represented in the cached data (i.e. the ones we were least interested in) would get loaded from the database when this occurred. This change ensures that only the resource being checked is loaded from the database, as intended, and adds asserts to prevent any future regression occurring silently. Change-Id: I9e568640d776748a1c9f2950f8bb0a8cea325996 Closes-Bug: #1656429
This commit is contained in:
parent
af46280c8a
commit
4507322675
@ -260,11 +260,11 @@ class Resource(object):
|
|||||||
self.current_template_id = None
|
self.current_template_id = None
|
||||||
self.root_stack_id = None
|
self.root_stack_id = None
|
||||||
|
|
||||||
if not stack.has_cache_data(name):
|
if stack.cache_data is None:
|
||||||
resource = stack.db_resource_get(name)
|
resource = stack.db_resource_get(name)
|
||||||
if resource:
|
if resource:
|
||||||
self._load_data(resource)
|
self._load_data(resource)
|
||||||
else:
|
elif stack.has_cache_data(name):
|
||||||
self.action = stack.cache_data[name]['action']
|
self.action = stack.cache_data[name]['action']
|
||||||
self.status = stack.cache_data[name]['status']
|
self.status = stack.cache_data[name]['status']
|
||||||
self.id = stack.cache_data[name]['id']
|
self.id = stack.cache_data[name]['id']
|
||||||
|
@ -315,6 +315,8 @@ class Stack(collections.Mapping):
|
|||||||
def _find_filtered_resources(self, filters=None):
|
def _find_filtered_resources(self, filters=None):
|
||||||
rsrc_def_cache = {self.t.id: self.t.resource_definitions(self)}
|
rsrc_def_cache = {self.t.id: self.t.resource_definitions(self)}
|
||||||
if filters:
|
if filters:
|
||||||
|
assert self.cache_data is None, \
|
||||||
|
"Resources should not be loaded from the DB"
|
||||||
resources = resource_objects.Resource.get_all_by_stack(
|
resources = resource_objects.Resource.get_all_by_stack(
|
||||||
self.context, self.id, filters)
|
self.context, self.id, filters)
|
||||||
else:
|
else:
|
||||||
@ -354,6 +356,8 @@ class Stack(collections.Mapping):
|
|||||||
|
|
||||||
def _db_resources_get(self):
|
def _db_resources_get(self):
|
||||||
if self._db_resources is None:
|
if self._db_resources is None:
|
||||||
|
assert self.cache_data is None, \
|
||||||
|
"Resources should not be loaded from the DB"
|
||||||
_db_resources = resource_objects.Resource.get_all_by_stack(
|
_db_resources = resource_objects.Resource.get_all_by_stack(
|
||||||
self.context, self.id)
|
self.context, self.id)
|
||||||
if not _db_resources:
|
if not _db_resources:
|
||||||
@ -1219,6 +1223,7 @@ class Stack(collections.Mapping):
|
|||||||
self.t = template
|
self.t = template
|
||||||
self.reset_dependencies()
|
self.reset_dependencies()
|
||||||
self._resources = None
|
self._resources = None
|
||||||
|
self.cache_data = None
|
||||||
|
|
||||||
if action is not self.CREATE:
|
if action is not self.CREATE:
|
||||||
self.updated_time = oslo_timeutils.utcnow()
|
self.updated_time = oslo_timeutils.utcnow()
|
||||||
|
Loading…
Reference in New Issue
Block a user