mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-06 00:14:02 -07:00
Db cache fix (#29048)
* cleaner get for file based caches * now db based facts behave like file ones we now keep local in mem cache to avoid race conditions on expiration during ansible runs
This commit is contained in:
parent
f9f0472ba5
commit
13d1520f3d
3 changed files with 63 additions and 50 deletions
40
lib/ansible/plugins/cache/__init__.py
vendored
40
lib/ansible/plugins/cache/__init__.py
vendored
|
@ -105,29 +105,29 @@ class BaseFileCacheModule(BaseCacheModule):
|
|||
and it would be problematic if the key did expire after some long running tasks and
|
||||
user gets 'undefined' error in the same play """
|
||||
|
||||
if key in self._cache:
|
||||
return self._cache.get(key)
|
||||
if key not in self._cache:
|
||||
|
||||
if self.has_expired(key) or key == "":
|
||||
raise KeyError
|
||||
if self.has_expired(key) or key == "":
|
||||
raise KeyError
|
||||
|
||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||
try:
|
||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||
try:
|
||||
value = self._load(cachefile)
|
||||
self._cache[key] = value
|
||||
return value
|
||||
except ValueError as e:
|
||||
display.warning("error in '%s' cache plugin while trying to read %s : %s. "
|
||||
"Most likely a corrupt file, so erasing and failing." % (self.plugin_name, cachefile, to_bytes(e)))
|
||||
self.delete(key)
|
||||
raise AnsibleError("The cache file %s was corrupt, or did not otherwise contain valid data. "
|
||||
"It has been removed, so you can re-run your command now." % cachefile)
|
||||
except (OSError, IOError) as e:
|
||||
display.warning("error in '%s' cache plugin while trying to read %s : %s" % (self.plugin_name, cachefile, to_bytes(e)))
|
||||
raise KeyError
|
||||
except Exception as e:
|
||||
raise AnsibleError("Error while decoding the cache file %s: %s" % (cachefile, to_bytes(e)))
|
||||
try:
|
||||
value = self._load(cachefile)
|
||||
self._cache[key] = value
|
||||
except ValueError as e:
|
||||
display.warning("error in '%s' cache plugin while trying to read %s : %s. "
|
||||
"Most likely a corrupt file, so erasing and failing." % (self.plugin_name, cachefile, to_bytes(e)))
|
||||
self.delete(key)
|
||||
raise AnsibleError("The cache file %s was corrupt, or did not otherwise contain valid data. "
|
||||
"It has been removed, so you can re-run your command now." % cachefile)
|
||||
except (OSError, IOError) as e:
|
||||
display.warning("error in '%s' cache plugin while trying to read %s : %s" % (self.plugin_name, cachefile, to_bytes(e)))
|
||||
raise KeyError
|
||||
except Exception as e:
|
||||
raise AnsibleError("Error while decoding the cache file %s: %s" % (cachefile, to_bytes(e)))
|
||||
|
||||
return self._cache.get(key)
|
||||
|
||||
def set(self, key, value):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue