X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/650265966e83fca4ce8e9a416e9b5e358e82be98..ba34a22d9918ae97306472c04701e69090821c82:/sdk/python/arvados/keep.py diff --git a/sdk/python/arvados/keep.py b/sdk/python/arvados/keep.py index ce4c6f81f6..b9e22748c1 100644 --- a/sdk/python/arvados/keep.py +++ b/sdk/python/arvados/keep.py @@ -316,12 +316,10 @@ class KeepBlockCache(object): return n, True def set(self, slot, blob): - tryagain = False - try: slot.set(blob) + return except OSError as e: - tryagain = True if e.errno == errno.ENOMEM: # Reduce max slots to current - 4, cap cache and retry with self._cache_lock: @@ -334,20 +332,24 @@ class KeepBlockCache(object): elif e.errno == errno.ENODEV: _logger.error("Unable to use disk cache: The underlying filesystem does not support memory mapping.") except Exception as e: - tryagain = True + pass + finally: + # Check if we should evict things from the cache. Either + # because we added a new thing or there was an error and + # we possibly adjusted the limits down, so we might need + # to push something out. + self.cap_cache() try: - if tryagain: - # There was an error. Evict some slots and try again. - self.cap_cache() - slot.set(blob) + # Only gets here if there was an error the first time. The + # exception handler adjusts limits downward in some cases + # to free up resources, which would make the operation + # succeed. + slot.set(blob) except Exception as e: # It failed again. Give up. + slot.set(None) raise arvados.errors.KeepCacheError("Unable to save block %s to disk cache: %s" % (slot.locator, e)) - finally: - # Set the notice that that we are done with the cache - # slot one way or another. - slot.ready.set() self.cap_cache()