Repository: ambari Updated Branches: refs/heads/branch-3.0-perf cc835ae54 -> 857bef7cd
AMBARI-22119. Cache becomes corrupt (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/857bef7c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/857bef7c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/857bef7c Branch: refs/heads/branch-3.0-perf Commit: 857bef7cdd360c8d3862024138bf99a9942fec93 Parents: cc835ae Author: Andrew Onishuk <[email protected]> Authored: Mon Oct 9 16:12:07 2017 +0300 Committer: Andrew Onishuk <[email protected]> Committed: Mon Oct 9 16:12:07 2017 +0300 ---------------------------------------------------------------------- .../main/python/ambari_agent/ClusterCache.py | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/857bef7c/ambari-agent/src/main/python/ambari_agent/ClusterCache.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/ClusterCache.py b/ambari-agent/src/main/python/ambari_agent/ClusterCache.py index 40b3288..b924420 100644 --- a/ambari-agent/src/main/python/ambari_agent/ClusterCache.py +++ b/ambari-agent/src/main/python/ambari_agent/ClusterCache.py @@ -45,7 +45,6 @@ class ClusterCache(dict): """ self.cluster_cache_dir = cluster_cache_dir - self.hash = None self.__current_cache_json_file = os.path.join(self.cluster_cache_dir, self.get_cache_name()+'.json') self.__current_cache_hash_file = os.path.join(self.cluster_cache_dir, '.'+self.get_cache_name()+'.hash') @@ -53,16 +52,22 @@ class ClusterCache(dict): self._cache_lock = threading.RLock() self.__file_lock = ClusterCache.file_locks[self.__current_cache_json_file] - # if the file exists, then load it + self.hash = None cache_dict = {} - with self.__file_lock: - if os.path.isfile(self.__current_cache_json_file): - with open(self.__current_cache_json_file, 'r') as fp: - cache_dict = json.load(fp) - if os.path.isfile(self.__current_cache_hash_file): - with open(self.__current_cache_hash_file, 'r') as fp: - self.hash = fp.read() + try: + with self.__file_lock: + if os.path.isfile(self.__current_cache_json_file): + with open(self.__current_cache_json_file, 'r') as fp: + cache_dict = json.load(fp) + + if os.path.isfile(self.__current_cache_hash_file): + with open(self.__current_cache_hash_file, 'r') as fp: + self.hash = fp.read() + except (IOError,ValueError): + logger.exception("Cannot load data from {0} and {1}".format(self.__current_cache_json_file, self.__current_cache_hash_file)) + self.hash = None + cache_dict = {} self.rewrite_cache(cache_dict, self.hash)
