summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-10-29 17:15:27 +0100
committerJürg Billeter <j@bitron.ch>2020-12-09 14:51:06 +0000
commit8c697671cc9a717020839d2e38fd9e1a42449855 (patch)
tree67f80e41d5e0c1123cbcfd3d91270f832b9e8d9b /src
parent698330a601bcd51d7517edd9fc5466a136f1b1db (diff)
downloadbuildstream-8c697671cc9a717020839d2e38fd9e1a42449855.tar.gz
cascache.py: Generalize remote_missing_blobs() into missing_blobs()
The implementation can be reused to replace `local_missing_blobs()` and simplify `contains_files()`.
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/_artifactcache.py2
-rw-r--r--src/buildstream/_cas/cascache.py43
-rw-r--r--src/buildstream/sandbox/_sandboxremote.py6
3 files changed, 16 insertions, 35 deletions
diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py
index efced2807..41a620b49 100644
--- a/src/buildstream/_artifactcache.py
+++ b/src/buildstream/_artifactcache.py
@@ -339,7 +339,7 @@ class ArtifactCache(AssetCache):
for remote in push_remotes:
remote.init()
- remote_missing_blobs = self.cas.remote_missing_blobs(remote, missing_blobs)
+ remote_missing_blobs = self.cas.missing_blobs(missing_blobs, remote=remote)
for blob in remote_missing_blobs:
if blob not in remote_missing_blobs_list:
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index aa9bf17df..2fa143084 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -152,13 +152,7 @@ class CASCache:
# Returns: True if the files are in the cache, False otherwise
#
def contains_files(self, digests):
- cas = self.get_cas()
-
- request = remote_execution_pb2.FindMissingBlobsRequest()
- request.blob_digests.extend(digests)
-
- response = cas.FindMissingBlobs(request)
- return len(response.missing_blob_digests) == 0
+ return len(self.missing_blobs(digests)) == 0
# contains_directory():
#
@@ -400,7 +394,7 @@ class CASCache:
return utils._message_digest(root_directory)
- # remote_missing_blobs_for_directory():
+ # missing_blobs_for_directory():
#
# Determine which blobs of a directory tree are missing on the remote.
#
@@ -409,23 +403,27 @@ class CASCache:
#
# Returns: List of missing Digest objects
#
- def remote_missing_blobs_for_directory(self, remote, digest):
+ def missing_blobs_for_directory(self, digest, *, remote=None):
required_blobs = self.required_blobs_for_directory(digest)
- return self.remote_missing_blobs(remote, required_blobs)
+ return self.missing_blobs(required_blobs, remote=remote)
- # remote_missing_blobs():
+ # missing_blobs():
#
- # Determine which blobs are missing on the remote.
+ # Determine which blobs are missing locally or on the remote.
#
# Args:
# blobs ([Digest]): List of directory digests to check
#
# Returns: List of missing Digest objects
#
- def remote_missing_blobs(self, remote, blobs):
+ def missing_blobs(self, blobs, *, remote=None):
cas = self.get_cas()
- instance_name = remote.local_cas_instance_name
+
+ if remote:
+ instance_name = remote.local_cas_instance_name
+ else:
+ instance_name = ""
missing_blobs = dict()
# Limit size of FindMissingBlobs request
@@ -450,23 +448,6 @@ class CASCache:
return missing_blobs.values()
- # local_missing_blobs():
- #
- # Check local cache for missing blobs.
- #
- # Args:
- # digests (list): The Digests of blobs to check
- #
- # Returns: Missing Digest objects
- #
- def local_missing_blobs(self, digests):
- missing_blobs = []
- for digest in digests:
- objpath = self.objpath(digest)
- if not os.path.exists(objpath):
- missing_blobs.append(digest)
- return missing_blobs
-
# required_blobs_for_directory():
#
# Generator that returns the Digests of all blobs in the tree specified by
diff --git a/src/buildstream/sandbox/_sandboxremote.py b/src/buildstream/sandbox/_sandboxremote.py
index 2ac159337..3302b0dad 100644
--- a/src/buildstream/sandbox/_sandboxremote.py
+++ b/src/buildstream/sandbox/_sandboxremote.py
@@ -276,7 +276,7 @@ class SandboxRemote(SandboxREAPI):
dir_digest = vdir._get_digest()
required_blobs = cascache.required_blobs_for_directory(dir_digest)
- local_missing_blobs = cascache.local_missing_blobs(required_blobs)
+ local_missing_blobs = cascache.missing_blobs(required_blobs)
if local_missing_blobs:
if self._output_files_required:
# Fetch all blobs from Remote Execution CAS server
@@ -319,14 +319,14 @@ class SandboxRemote(SandboxREAPI):
# Determine blobs missing on remote
try:
input_root_digest = action.input_root_digest
- missing_blobs = list(cascache.remote_missing_blobs_for_directory(casremote, input_root_digest))
+ missing_blobs = list(cascache.missing_blobs_for_directory(input_root_digest, remote=casremote))
except grpc.RpcError as e:
raise SandboxError("Failed to determine missing blobs: {}".format(e)) from e
# Check if any blobs are also missing locally (partial artifact)
# and pull them from the artifact cache.
try:
- local_missing_blobs = cascache.local_missing_blobs(missing_blobs)
+ local_missing_blobs = cascache.missing_blobs(missing_blobs)
if local_missing_blobs:
artifactcache.fetch_missing_blobs(project, local_missing_blobs)
except (grpc.RpcError, BstError) as e: