From ea520f9d1d77fcb72bc8ebc119781107c094c245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Tue, 30 Jun 2020 14:02:05 +0200 Subject: _artifactcache.py: Skip push only if server has identical artifact The existing artifact on a server may refer to a previous build and the referenced blobs may no longer exist. As we push blobs referenced by the local artifact proto, we can skip pushing the artifact proto only if the artifact proto on the server is identical. It would be more efficient to always push the artifact proto without checking what artifact proto is currently on the server. However, we need the extra information to mark push jobs as skipped. This is clearer to users and also required by some test cases. --- src/buildstream/_artifactcache.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py index c1e87b6dc..46fc5fbfb 100644 --- a/src/buildstream/_artifactcache.py +++ b/src/buildstream/_artifactcache.py @@ -541,26 +541,27 @@ class ArtifactCache(BaseCache): keys = list(utils._deduplicate([artifact_proto.strong_key, artifact_proto.weak_key])) - # Check whether the artifact is on the server + pushed = False + for key in keys: try: - remote.get_artifact(element.get_artifact_name(key=key)) + remote_artifact = remote.get_artifact(element.get_artifact_name(key=key)) + # Skip push if artifact is already on the server + if remote_artifact == artifact_proto: + continue except grpc.RpcError as e: if e.code() != grpc.StatusCode.NOT_FOUND: raise ArtifactError( "Error checking artifact cache with status {}: {}".format(e.code().name, e.details()) ) - else: - return False - # If not, we send the artifact proto - for key in keys: try: remote.update_artifact(element.get_artifact_name(key=key), artifact_proto) + pushed = True except grpc.RpcError as e: raise ArtifactError("Failed to push artifact with status {}: {}".format(e.code().name, e.details())) - return True + return pushed # _pull_artifact_storage(): # -- cgit v1.2.1