diff options
author | Jürg Billeter <j@bitron.ch> | 2018-10-17 11:02:49 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-11-05 17:18:12 +0000 |
commit | 626d20aefb52d25d987c61f377cc1ce3172da8c3 (patch) | |
tree | 5a451d29e9c793ba86ded6a5867c1f3911bfd662 /buildstream/_artifactcache/casserver.py | |
parent | e398f877ab2cb41e7fa531fd71ad9b503fbbedac (diff) | |
download | buildstream-626d20aefb52d25d987c61f377cc1ce3172da8c3.tar.gz |
Split up artifact cache and CAS cache
This changes CASCache from a subclass to a delegate object of
ArtifactCache. As the lower layer, CASCache no longer deals with
elements or projects.
Fixes #659.
Diffstat (limited to 'buildstream/_artifactcache/casserver.py')
-rw-r--r-- | buildstream/_artifactcache/casserver.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/buildstream/_artifactcache/casserver.py b/buildstream/_artifactcache/casserver.py index 31b05ce0f..ee84c4943 100644 --- a/buildstream/_artifactcache/casserver.py +++ b/buildstream/_artifactcache/casserver.py @@ -32,8 +32,9 @@ from .._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remo from .._protos.google.bytestream import bytestream_pb2, bytestream_pb2_grpc from .._protos.buildstream.v2 import buildstream_pb2, buildstream_pb2_grpc -from .._exceptions import ArtifactError -from .._context import Context +from .._exceptions import CASError + +from .cascache import CASCache # The default limit for gRPC messages is 4 MiB. @@ -55,26 +56,23 @@ class ArtifactTooLargeException(Exception): # enable_push (bool): Whether to allow blob uploads and artifact updates # def create_server(repo, *, enable_push): - context = Context() - context.artifactdir = os.path.abspath(repo) - - artifactcache = context.artifactcache + cas = CASCache(os.path.abspath(repo)) # Use max_workers default from Python 3.5+ max_workers = (os.cpu_count() or 1) * 5 server = grpc.server(futures.ThreadPoolExecutor(max_workers)) bytestream_pb2_grpc.add_ByteStreamServicer_to_server( - _ByteStreamServicer(artifactcache, enable_push=enable_push), server) + _ByteStreamServicer(cas, enable_push=enable_push), server) remote_execution_pb2_grpc.add_ContentAddressableStorageServicer_to_server( - _ContentAddressableStorageServicer(artifactcache, enable_push=enable_push), server) + _ContentAddressableStorageServicer(cas, enable_push=enable_push), server) remote_execution_pb2_grpc.add_CapabilitiesServicer_to_server( _CapabilitiesServicer(), server) buildstream_pb2_grpc.add_ReferenceStorageServicer_to_server( - _ReferenceStorageServicer(artifactcache, enable_push=enable_push), server) + _ReferenceStorageServicer(cas, enable_push=enable_push), server) return server @@ -333,7 +331,7 @@ class _ReferenceStorageServicer(buildstream_pb2_grpc.ReferenceStorageServicer): response.digest.hash = tree.hash response.digest.size_bytes = tree.size_bytes - except ArtifactError: + except CASError: context.set_code(grpc.StatusCode.NOT_FOUND) return response @@ -437,7 +435,7 @@ def _clean_up_cache(cas, object_size): return 0 # obtain a list of LRP artifacts - LRP_artifacts = cas.list_artifacts() + LRP_artifacts = cas.list_refs() removed_size = 0 # in bytes while object_size - removed_size > free_disk_space: |