From: Peter Amstutz Date: Wed, 30 Mar 2022 03:09:46 +0000 (-0400) Subject: 18941: Rename cache_slot_get option to 'prefetch' for clarity X-Git-Tag: 2.4.0~20^2~2 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/d3051d45df5ee760a05a84bf4d385799c4326477 18941: Rename cache_slot_get option to 'prefetch' for clarity Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- diff --git a/sdk/python/arvados/arvfile.py b/sdk/python/arvados/arvfile.py index a13575b715..2ce0e46b30 100644 --- a/sdk/python/arvados/arvfile.py +++ b/sdk/python/arvados/arvfile.py @@ -593,7 +593,7 @@ class _BlockManager(object): b = self._prefetch_queue.get() if b is None: return - self._keep.get(b, cache_slot_get=False) + self._keep.get(b, prefetch=True) except Exception: _logger.exception("Exception doing block prefetch") @@ -846,7 +846,6 @@ class _BlockManager(object): return self.start_get_threads() - # _logger.debug("pushing %s to prefetch", locator) self._prefetch_queue.put(locator) diff --git a/sdk/python/arvados/keep.py b/sdk/python/arvados/keep.py index 53776017db..7c05cc0a6a 100644 --- a/sdk/python/arvados/keep.py +++ b/sdk/python/arvados/keep.py @@ -1058,7 +1058,7 @@ class KeepClient(object): def get(self, loc_s, **kwargs): return self._get_or_head(loc_s, method="GET", **kwargs) - def _get_or_head(self, loc_s, method="GET", num_retries=None, request_id=None, headers=None, cache_slot_get=True): + def _get_or_head(self, loc_s, method="GET", num_retries=None, request_id=None, headers=None, prefetch=False): """Get data from Keep. This method fetches one or more blocks of data from Keep. It @@ -1097,16 +1097,19 @@ class KeepClient(object): if method == "GET": slot, first = self.block_cache.reserve_cache(locator.md5sum) if not first: - self.hits_counter.add(1) - if cache_slot_get: - blob = slot.get() - if blob is None: - raise arvados.errors.KeepReadError( - "failed to read {}".format(loc_s)) - return blob - else: - slot = None # prevent finally from calling slot.set() + if prefetch: + # this is request for a prefetch, if it is + # already in flight, return immediately. + # clear 'slot' to prevent finally block from + # calling slot.set() + slot = None return None + self.hits_counter.add(1) + blob = slot.get() + if blob is None: + raise arvados.errors.KeepReadError( + "failed to read {}".format(loc_s)) + return blob self.misses_counter.add(1) diff --git a/sdk/python/tests/test_arvfile.py b/sdk/python/tests/test_arvfile.py index fce48479a2..b45a592ecd 100644 --- a/sdk/python/tests/test_arvfile.py +++ b/sdk/python/tests/test_arvfile.py @@ -27,7 +27,7 @@ class ArvadosFileWriterTestCase(unittest.TestCase): def __init__(self, blocks): self.blocks = blocks self.requests = [] - def get(self, locator, num_retries=0, cache_slot_get=None): + def get(self, locator, num_retries=0, prefetch=False): self.requests.append(locator) return self.blocks.get(locator) def get_from_cache(self, locator): diff --git a/sdk/python/tests/test_collections.py b/sdk/python/tests/test_collections.py index e2d644b867..5cf4993b2f 100644 --- a/sdk/python/tests/test_collections.py +++ b/sdk/python/tests/test_collections.py @@ -320,7 +320,7 @@ class ArvadosCollectionsTest(run_test_server.TestCaseWithServers, def __init__(self, content, num_retries=0): self.content = content - def get(self, locator, num_retries=0, cache_slot_get=None): + def get(self, locator, num_retries=0, prefetch=False): return self.content[locator] def test_stream_reader(self):