Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote: async upload #13655

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.actions;

import com.google.auto.value.AutoValue;
import com.google.devtools.build.lib.events.ExtendedEventHandler.ProgressLike;

/** Notifications for the uploads to the remote server. */
@AutoValue
public abstract class RemoteUploadEvent implements ProgressLike {

public static RemoteUploadEvent create(String resourceId, String progress, boolean finished) {
return new AutoValue_RemoteUploadEvent(resourceId, progress, finished);
}

/** The id that uniquely determines the resource being uploaded among all events within an build. */
public abstract String resourceId();

/** Human readable description of the upload progress. */
public abstract String progress();

/** Whether the upload progress reported about is finished already. */
public abstract boolean finished();
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,23 @@ public ListenableFuture<ActionResult> downloadActionResult(
}

@Override
public void uploadActionResult(
RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult)
throws IOException, InterruptedException {
try {
Utils.refreshIfUnauthenticated(
() ->
retrier.execute(
() ->
acBlockingStub(context)
.updateActionResult(
UpdateActionResultRequest.newBuilder()
.setInstanceName(options.remoteInstanceName)
.setActionDigest(actionKey.getDigest())
.setActionResult(actionResult)
.build())),
callCredentialsProvider);
} catch (StatusRuntimeException e) {
throw new IOException(e);
}
public ListenableFuture<Void> uploadActionResult(
RemoteActionExecutionContext context, ActionKey actionKey, ActionResult actionResult) {
ListenableFuture<ActionResult> upload =
Utils.refreshIfUnauthenticatedAsync(
() ->
retrier.executeAsync(
() ->
acFutureStub(context)
.updateActionResult(
UpdateActionResultRequest.newBuilder()
.setInstanceName(options.remoteInstanceName)
.setActionDigest(actionKey.getDigest())
.setActionResult(actionResult)
.build())),
callCredentialsProvider);

return Futures.transform(upload, ac -> null, MoreExecutors.directExecutor());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
import com.google.devtools.build.lib.actions.ActionGraph;
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.exec.ExecutionOptions;
import com.google.devtools.build.lib.exec.ExecutorLifecycleListener;
import com.google.devtools.build.lib.exec.ModuleActionContextRegistry;
import com.google.devtools.build.lib.exec.SpawnCache;
import com.google.devtools.build.lib.exec.SpawnStrategyRegistry;
Expand All @@ -35,11 +32,10 @@
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.vfs.Path;
import java.util.function.Supplier;
import javax.annotation.Nullable;

/** Provides a remote execution context. */
final class RemoteActionContextProvider implements ExecutorLifecycleListener {
final class RemoteActionContextProvider {

private final CommandEnvironment env;
@Nullable private final RemoteCache cache;
Expand Down Expand Up @@ -120,8 +116,12 @@ private RemoteExecutionService getRemoteExecutionService() {
workingDirectory.getRelative(remoteOptions.remoteCaptureCorruptedOutputs);
}

boolean verboseFailures =
checkNotNull(env.getOptions().getOptions(ExecutionOptions.class)).verboseFailures;
remoteExecutionService =
new RemoteExecutionService(
env.getReporter(),
verboseFailures,
env.getExecRoot(),
createRemotePathResolver(),
env.getBuildRequestId(),
Expand All @@ -132,6 +132,7 @@ private RemoteExecutionService getRemoteExecutionService() {
executor,
filesToDownload,
captureCorruptedOutputsDir);
env.getEventBus().register(remoteExecutionService);
}

return remoteExecutionService;
Expand Down Expand Up @@ -189,20 +190,9 @@ void setFilesToDownload(ImmutableSet<ActionInput> topLevelOutputs) {
this.filesToDownload = Preconditions.checkNotNull(topLevelOutputs, "filesToDownload");
}

@Override
public void executorCreated() {}

@Override
public void executionPhaseStarting(
ActionGraph actionGraph, Supplier<ImmutableSet<Artifact>> topLevelArtifacts) {}

@Override
public void executionPhaseEnding() {
if (cache != null) {
cache.close();
}
if (executor != null) {
executor.close();
public void afterCommand() {
if (remoteExecutionService != null) {
remoteExecutionService.shutdown();
}
}
}
Loading