18842: Clean up keep cache set() a little bit
authorPeter Amstutz <peter.amstutz@curii.com>
Fri, 2 Dec 2022 16:04:27 +0000 (11:04 -0500)
committerPeter Amstutz <peter.amstutz@curii.com>
Fri, 2 Dec 2022 16:04:27 +0000 (11:04 -0500)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

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

index 74b2a77b28506b2b5fd15b64b7977d877ea0ace8..f3984bbca493237a868d4c705a710be899fda637 100644 (file)
@@ -66,6 +66,8 @@ class DiskCacheSlot(object):
             tmpfile = None
 
             self.content = mmap.mmap(self.filehandle.fileno(), 0, access=mmap.ACCESS_READ)
+            # only set the event when mmap is successful
+            self.ready.set()
         finally:
             if tmpfile is not None:
                 # If the tempfile hasn't been renamed on disk yet, try to delete it.
index ce4c6f81f62d997cc5adfd37ebf4e3664ec68be7..44f10e4fb9dd8f09f5577b79437200b9d2cee0b0 100644 (file)
@@ -336,11 +336,18 @@ class KeepBlockCache(object):
         except Exception as e:
             tryagain = True
 
+        # Check if we should evict things from the cache.  Either
+        # because we added a new thing or we adjusted the limits down,
+        # so we might need to push something out.
+        self.cap_cache()
+
+        if not tryagain:
+            # Done
+            return
+
         try:
-            if tryagain:
-                # There was an error.  Evict some slots and try again.
-                self.cap_cache()
-                slot.set(blob)
+            # There was an error, we ran cap_cache so try one more time.
+            slot.set(blob)
         except Exception as e:
             # It failed again.  Give up.
             raise arvados.errors.KeepCacheError("Unable to save block %s to disk cache: %s" % (slot.locator, e))
@@ -349,7 +356,6 @@ class KeepBlockCache(object):
             # slot one way or another.
             slot.ready.set()
 
-        self.cap_cache()
 
 class Counter(object):
     def __init__(self, v=0):