Skip to content

Commit

Permalink
Check that someone else has not moved a file into the cache already
Browse files Browse the repository at this point in the history
If multiple processes are sharing a cache directory and caching
on read then it is possible that the other process has already
copied the dataset into the cache. We therefore need to check
before we try to copy it.
  • Loading branch information
timj committed Oct 5, 2022
1 parent a994edc commit 1474ca6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ datastore:
threshold: 4
# Default cache value. This will be the default decision if no specific
# match is found in the "cacheable" section later on.
default: false
default: true
# Use a dict over list to simplify merging logic.
cacheable:
Exposure: true
Expand Down
8 changes: 8 additions & 0 deletions python/lsst/daf/butler/core/datastoreCacheManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,14 @@ def move_to_cache(self, uri: ResourcePath, ref: DatasetRef) -> Optional[Resource
# item.
self._expire_cache()

# The above reset the in-memory cache status. It's entirely possible
# that another process has just cached this file (if multiple
# processes are caching on read), so check our in-memory cache
# before attempting to cache the dataset.
path_in_cache = cached_location.relative_to(self.cache_directory)
if path_in_cache and path_in_cache in self._cache_entries:
return cached_location

# Move into the cache. Given that multiple processes might be
# sharing a single cache directory, and the file we need might have
# been copied in whilst we were checking, allow overwrite without
Expand Down

0 comments on commit 1474ca6

Please sign in to comment.