21639: Don't return broken cache slots
authorPeter Amstutz <peter.amstutz@curii.com>
Mon, 1 Apr 2024 15:10:52 +0000 (11:10 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Mon, 1 Apr 2024 15:10:52 +0000 (11:10 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

sdk/python/arvados/diskcache.py
sdk/python/arvados/keep.py

index 23c0a80cbfc0bd9c4f01e7f1dc152b8cbbfc65ff..4949574f2b07447d246083ea538ce3a985f7aeff 100644 (file)
@@ -13,6 +13,7 @@ import time
 import errno
 import logging
 import weakref
+import collections
 
 _logger = logging.getLogger('arvados.keep')
 
index 51d40dbece2525ae8cf537c5120a0c94b45de0ba..1d0fc5f159b18e8b490d044cb33ed3b0cfbf5921 100644 (file)
@@ -273,7 +273,7 @@ class KeepBlockCache(object):
 
         _evict_candidates = collections.deque(self._cache.values())
         sm = sum([slot.size() for slot in _evict_candidates])
-        while len(self._cache) > 0 and (sm > cache_max or len(self._cache) > max_slots):
+        while len(_evict_candidates) > 0 and (sm > cache_max or len(self._cache) > max_slots):
             slot = _evict_candidates.popleft()
             if not slot.ready.is_set():
                 continue
@@ -313,7 +313,10 @@ class KeepBlockCache(object):
         # Test if the locator is already in the cache
         if locator in self._cache:
             n = self._cache[locator]
-            self._cache.move_to_back(locator)
+            if n.ready.is_set() and n.content is None:
+                del self._cache[n.locator]
+                return None
+            self._cache.move_to_end(locator)
             return n
         if self._disk_cache:
             # see if it exists on disk