Search in sources :

Example 1 with ContentAddressableStorage

use of build.buildfarm.cas.ContentAddressableStorage in project bazel-buildfarm by bazelbuild.

the class CASFileCacheTest method newInputThrowsNoSuchFileExceptionWithoutDelegate.

@Test
public void newInputThrowsNoSuchFileExceptionWithoutDelegate() throws Exception {
    ContentAddressableStorage undelegatedCAS = new CASFileCache(root, /* maxSizeInBytes=*/
    1024, /* maxEntrySizeInBytes=*/
    1024, /* hexBucketLevels=*/
    1, storeFileDirsIndexInMemory, DIGEST_UTIL, expireService, /* accessRecorder=*/
    directExecutor(), storage, /* directoriesIndexDbName=*/
    ":memory:", /* onPut=*/
    digest -> {
    }, /* onExpire=*/
    digests -> {
    }, /* delegate=*/
    null) {

        @Override
        protected InputStream newExternalInput(Digest digest) throws IOException {
            ByteString content = blobs.get(digest);
            if (content == null) {
                return fileCache.newTransparentInput(digest, 0);
            }
            return content.substring((int) (long) 0).newInput();
        }
    };
    ByteString blob = ByteString.copyFromUtf8("Missing Entry");
    Digest blobDigest = DIGEST_UTIL.compute(blob);
    NoSuchFileException expected = null;
    try (InputStream in = undelegatedCAS.newInput(blobDigest, /* offset=*/
    0)) {
        fail("should not get here");
    } catch (NoSuchFileException e) {
        expected = e;
    }
    assertThat(expected).isNotNull();
}
Also used : ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) NoSuchFileException(java.nio.file.NoSuchFileException) Test(org.junit.Test)

Example 2 with ContentAddressableStorage

use of build.buildfarm.cas.ContentAddressableStorage in project bazel-buildfarm by bazelbuild.

the class AbstractServerInstanceTest method outputDirectoriesFilesAreEnsuredPresent.

@SuppressWarnings("unchecked")
@Test
public void outputDirectoriesFilesAreEnsuredPresent() throws Exception {
    // our test subjects - these should appear in the findMissingBlobs request
    Digest fileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Root File Content"));
    Digest childFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Output Directory Child File Content"));
    Digest otherFileDigest = DIGEST_UTIL.compute(ByteString.copyFromUtf8("Another Output Directory File Content"));
    // setup block and ensureOutputsPresent trigger
    RequestMetadata requestMetadata = RequestMetadata.newBuilder().setCorrelatedInvocationsId("https://localhost:12345/test/build?ENSURE_OUTPUTS_PRESENT=true#92af266a-c5bf-48ca-a723-344ae516a786").build();
    ContentAddressableStorage contentAddressableStorage = mock(ContentAddressableStorage.class);
    ActionCache actionCache = mock(ActionCache.class);
    AbstractServerInstance instance = new DummyServerInstance(contentAddressableStorage, actionCache);
    Tree tree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(fileDigest)).build()).addChildren(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(childFileDigest)).build()).build();
    Tree otherTree = Tree.newBuilder().setRoot(Directory.newBuilder().addFiles(FileNode.newBuilder().setDigest(otherFileDigest)).build()).build();
    Digest treeDigest = DIGEST_UTIL.compute(tree);
    doBlob(contentAddressableStorage, treeDigest, tree.toByteString(), requestMetadata);
    Digest otherTreeDigest = DIGEST_UTIL.compute(otherTree);
    doBlob(contentAddressableStorage, otherTreeDigest, otherTree.toByteString(), requestMetadata);
    ActionKey actionKey = DigestUtil.asActionKey(DIGEST_UTIL.compute(ByteString.copyFromUtf8("action")));
    ActionResult actionResult = ActionResult.newBuilder().addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(treeDigest).build()).addOutputDirectories(OutputDirectory.newBuilder().setTreeDigest(otherTreeDigest).build()).build();
    when(actionCache.get(actionKey)).thenReturn(immediateFuture(actionResult));
    // invocation
    assertThat(instance.getActionResult(actionKey, requestMetadata).get()).isEqualTo(actionResult);
    // validation
    ArgumentCaptor<Iterable<Digest>> findMissingBlobsCaptor = ArgumentCaptor.forClass(Iterable.class);
    verify(contentAddressableStorage, times(1)).get(eq(treeDigest), /* offset=*/
    eq(0L), eq(treeDigest.getSizeBytes()), any(ServerCallStreamObserver.class), eq(requestMetadata));
    verify(contentAddressableStorage, times(1)).findMissingBlobs(findMissingBlobsCaptor.capture());
    assertThat(findMissingBlobsCaptor.getValue()).containsAtLeast(fileDigest, childFileDigest, otherFileDigest);
}
Also used : ActionCache(build.buildfarm.ac.ActionCache) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ActionResult(build.bazel.remote.execution.v2.ActionResult) Digest(build.bazel.remote.execution.v2.Digest) ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) Tree(build.bazel.remote.execution.v2.Tree) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Test(org.junit.Test)

Example 3 with ContentAddressableStorage

use of build.buildfarm.cas.ContentAddressableStorage in project bazel-buildfarm by bazelbuild.

the class Worker method createFuseExecFileSystem.

private ExecFileSystem createFuseExecFileSystem(InputStreamFactory remoteInputStreamFactory, ContentAddressableStorage storage) {
    InputStreamFactory storageInputStreamFactory = (digest, offset) -> storage.get(digest).getData().substring((int) offset).newInput();
    InputStreamFactory localPopulatingInputStreamFactory = (blobDigest, offset) -> {
        // FIXME use write
        ByteString content = ByteString.readFrom(remoteInputStreamFactory.newInput(blobDigest, offset));
        if (offset == 0) {
            // extra computations
            Blob blob = new Blob(content, digestUtil);
            // here's hoping that our digest matches...
            storage.put(blob);
        }
        return content.newInput();
    };
    return new FuseExecFileSystem(root, new FuseCAS(root, new EmptyInputStreamFactory(new FailoverInputStreamFactory(storageInputStreamFactory, localPopulatingInputStreamFactory))), storage);
}
Also used : Arrays(java.util.Arrays) LoadingCache(com.google.common.cache.LoadingCache) Blob(build.buildfarm.cas.ContentAddressableStorage.Blob) ShardWorker(build.buildfarm.v1test.ShardWorker) MemoryCAS(build.buildfarm.cas.MemoryCAS) PutOperationStage(build.buildfarm.worker.PutOperationStage) Status(io.grpc.Status) IOSupplier(build.buildfarm.common.function.IOSupplier) Path(java.nio.file.Path) ReportResultStage(build.buildfarm.worker.ReportResultStage) Set(java.util.Set) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) ByteStreams(com.google.common.io.ByteStreams) DigestUtil(build.buildfarm.common.DigestUtil) Strings(com.google.common.base.Strings) Code(io.grpc.Status.Code) UserPrincipal(java.nio.file.attribute.UserPrincipal) Lists(com.google.common.collect.Lists) ServerBuilder(io.grpc.ServerBuilder) Server(io.grpc.Server) Nullable(javax.annotation.Nullable) Backplane(build.buildfarm.backplane.Backplane) ContentAddressableStorageConfig(build.buildfarm.v1test.ContentAddressableStorageConfig) ExecuteActionStage(build.buildfarm.worker.ExecuteActionStage) ServingStatus(io.grpc.health.v1.HealthCheckResponse.ServingStatus) CASFileCache(build.buildfarm.cas.cfc.CASFileCache) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) PipelineStage(build.buildfarm.worker.PipelineStage) ShardWorkerOptions(build.buildfarm.common.config.ShardWorkerOptions) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) ContentAddressableStorages.createGrpcCAS(build.buildfarm.cas.ContentAddressableStorages.createGrpcCAS) AdminGrpc(build.buildfarm.v1test.AdminGrpc) InputStreamReader(java.io.InputStreamReader) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) InputFetchStage(build.buildfarm.worker.InputFetchStage) Paths(java.nio.file.Paths) ManagedChannel(io.grpc.ManagedChannel) OptionsParser(com.google.devtools.common.options.OptionsParser) NegotiationType(io.grpc.netty.NegotiationType) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Random(java.util.Random) ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) WorkerStubs(build.buildfarm.instance.shard.WorkerStubs) InputStreamFactory(build.buildfarm.common.InputStreamFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) RemoteInputStreamFactory(build.buildfarm.instance.shard.RemoteInputStreamFactory) ConfigAdjuster(build.buildfarm.common.config.ConfigAdjuster) Digest(build.bazel.remote.execution.v2.Digest) Gauge(io.prometheus.client.Gauge) Utils.getUser(build.buildfarm.common.io.Utils.getUser) PrometheusPublisher(build.buildfarm.metrics.prometheus.PrometheusPublisher) TextFormat(com.google.protobuf.TextFormat) ByteStreamService(build.buildfarm.server.ByteStreamService) MatchStage(build.buildfarm.worker.MatchStage) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) UUID(java.util.UUID) FileSystem(java.nio.file.FileSystem) Logger(java.util.logging.Logger) String.format(java.lang.String.format) Instance(build.buildfarm.instance.Instance) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ByteString(com.google.protobuf.ByteString) List(java.util.List) HashFunction(build.buildfarm.common.DigestUtil.HashFunction) Size(build.buildfarm.common.Size) ReindexCasRequest(build.buildfarm.v1test.ReindexCasRequest) LoggingMain(build.buildfarm.common.LoggingMain) ContentAddressableStorageService(build.buildfarm.server.ContentAddressableStorageService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DisableScaleInProtectionRequest(build.buildfarm.v1test.DisableScaleInProtectionRequest) INFO(java.util.logging.Level.INFO) ConfigurationException(javax.naming.ConfigurationException) Operation(com.google.longrunning.Operation) Counter(io.prometheus.client.Counter) SEVERE(java.util.logging.Level.SEVERE) Level(java.util.logging.Level) ImmutableList(com.google.common.collect.ImmutableList) DAYS(java.util.concurrent.TimeUnit.DAYS) FeedbackOutputStream(build.buildfarm.common.io.FeedbackOutputStream) FuseCAS(build.buildfarm.worker.FuseCAS) HealthStatusManager(io.grpc.services.HealthStatusManager) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) DequeueMatchSettings(build.buildfarm.worker.DequeueMatchSettings) FilesystemCASConfig(build.buildfarm.v1test.FilesystemCASConfig) Iterator(java.util.Iterator) RedisShardBackplane(build.buildfarm.instance.shard.RedisShardBackplane) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) Write(build.buildfarm.common.Write) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) Pipeline(build.buildfarm.worker.Pipeline) ShardWorkerConfig(build.buildfarm.v1test.ShardWorkerConfig) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) Blob(build.buildfarm.cas.ContentAddressableStorage.Blob) ByteString(com.google.protobuf.ByteString) FuseCAS(build.buildfarm.worker.FuseCAS) InputStreamFactory(build.buildfarm.common.InputStreamFactory) RemoteInputStreamFactory(build.buildfarm.instance.shard.RemoteInputStreamFactory)

Example 4 with ContentAddressableStorage

use of build.buildfarm.cas.ContentAddressableStorage in project bazel-buildfarm by bazelbuild.

the class Worker method createStorages.

private ContentAddressableStorage createStorages(InputStreamFactory remoteInputStreamFactory, ExecutorService removeDirectoryService, Executor accessRecorder, List<ContentAddressableStorageConfig> configs) throws ConfigurationException {
    ImmutableList.Builder<ContentAddressableStorage> storages = ImmutableList.builder();
    // must construct delegates first
    ContentAddressableStorage storage = null;
    ContentAddressableStorage delegate = null;
    for (ContentAddressableStorageConfig config : Lists.reverse(configs)) {
        storage = createStorage(remoteInputStreamFactory, removeDirectoryService, accessRecorder, config, delegate);
        storages.add(storage);
        delegate = storage;
    }
    return storage;
}
Also used : ContentAddressableStorage(build.buildfarm.cas.ContentAddressableStorage) ImmutableList(com.google.common.collect.ImmutableList) ContentAddressableStorageConfig(build.buildfarm.v1test.ContentAddressableStorageConfig)

Aggregations

ContentAddressableStorage (build.buildfarm.cas.ContentAddressableStorage)4 Digest (build.bazel.remote.execution.v2.Digest)3 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)2 ContentAddressableStorageConfig (build.buildfarm.v1test.ContentAddressableStorageConfig)2 ImmutableList (com.google.common.collect.ImmutableList)2 Test (org.junit.Test)2 ActionResult (build.bazel.remote.execution.v2.ActionResult)1 Tree (build.bazel.remote.execution.v2.Tree)1 ActionCache (build.buildfarm.ac.ActionCache)1 Backplane (build.buildfarm.backplane.Backplane)1 Blob (build.buildfarm.cas.ContentAddressableStorage.Blob)1 ContentAddressableStorages.createGrpcCAS (build.buildfarm.cas.ContentAddressableStorages.createGrpcCAS)1 MemoryCAS (build.buildfarm.cas.MemoryCAS)1 CASFileCache (build.buildfarm.cas.cfc.CASFileCache)1 DigestUtil (build.buildfarm.common.DigestUtil)1 ActionKey (build.buildfarm.common.DigestUtil.ActionKey)1 HashFunction (build.buildfarm.common.DigestUtil.HashFunction)1 InputStreamFactory (build.buildfarm.common.InputStreamFactory)1 LoggingMain (build.buildfarm.common.LoggingMain)1 Size (build.buildfarm.common.Size)1