From 4b90fe9f00ba1535212fe1f49154a11d78478191 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Mon, 16 Jan 2017 16:58:04 -0500 Subject: [PATCH] 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. The asserts added in master to prevent regressions are *not* included in the backport, since they add risk without benefit to a stable branch. Change-Id: I9e568640d776748a1c9f2950f8bb0a8cea325996 Closes-Bug: #1656429 (cherry picked from commit 45073226752c58d640ea5a59b7e532c022a4939b) --- heat/engine/resource.py | 4 ++-- heat/engine/stack.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index bd753a123e..18eca92e61 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -259,11 +259,11 @@ class Resource(object): self.current_template_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) if resource: self._load_data(resource) - else: + elif stack.has_cache_data(name): self.action = stack.cache_data[name]['action'] self.status = stack.cache_data[name]['status'] self.id = stack.cache_data[name]['id'] diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 551f8a57d3..8c70ff6fa8 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -1194,6 +1194,7 @@ class Stack(collections.Mapping): self.t = template self.reset_dependencies() self._resources = None + self.cache_data = None if action is not self.CREATE: self.updated_time = oslo_timeutils.utcnow()