Skip to content

Commit

Permalink
[5.2] Remote: Fix a bug that outputs of actions tagged with no-remote…
Browse files Browse the repository at this point in the history
… are u... (bazelbuild#15453)

* Remote: Fix a bug that outputs of actions tagged with no-remote are u…

…ploaded to remote cache when remote execution is enabled.

Fixes bazelbuild#14900.

Also fixes an issue that action result from just remotely executed action is not saved to disk cache. The root cause is the action result is inlined in the execution response hence not downloaded through remote cache, hence not saved to disk cache. This results in the second build misses the disk cache, but it can still hit the remote cache and fill the disk cache. The third build can hit disk cache.

Closes bazelbuild#15212.

PiperOrigin-RevId: 441426469

* Fix test

Co-authored-by: Chenchu K <[email protected]>
  • Loading branch information
coeuvre and ckolli5 authored May 27, 2022
1 parent 0758347 commit 4d900ce
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext;
import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext.Step;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -271,7 +272,8 @@ private Single<PathConverter> upload(Set<Path> files) {

RequestMetadata metadata =
TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "bes-upload", null);
RemoteActionExecutionContext context = RemoteActionExecutionContext.createForBES(metadata);
RemoteActionExecutionContext context = RemoteActionExecutionContext.create(metadata);
context.setStep(Step.UPLOAD_BES_FILES);

return Single.using(
remoteCache::retain,
Expand Down
134 changes: 134 additions & 0 deletions src/main/java/com/google/devtools/build/lib/remote/RemoteAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2022 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.remote;

import build.bazel.remote.execution.v2.Action;
import build.bazel.remote.execution.v2.Command;
import build.bazel.remote.execution.v2.Digest;
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.ForbiddenActionInputException;
import com.google.devtools.build.lib.actions.Spawn;
import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext;
import com.google.devtools.build.lib.remote.common.NetworkTime;
import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext;
import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey;
import com.google.devtools.build.lib.remote.common.RemotePathResolver;
import com.google.devtools.build.lib.remote.merkletree.MerkleTree;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
import java.util.SortedMap;

/** A value class representing an action which can be executed remotely. */
public class RemoteAction {

private final Spawn spawn;
private final SpawnExecutionContext spawnExecutionContext;
private final RemoteActionExecutionContext remoteActionExecutionContext;
private final RemotePathResolver remotePathResolver;
private final MerkleTree merkleTree;
private final Digest commandHash;
private final Command command;
private final Action action;
private final ActionKey actionKey;

RemoteAction(
Spawn spawn,
SpawnExecutionContext spawnExecutionContext,
RemoteActionExecutionContext remoteActionExecutionContext,
RemotePathResolver remotePathResolver,
MerkleTree merkleTree,
Digest commandHash,
Command command,
Action action,
ActionKey actionKey) {
this.spawn = spawn;
this.spawnExecutionContext = spawnExecutionContext;
this.remoteActionExecutionContext = remoteActionExecutionContext;
this.remotePathResolver = remotePathResolver;
this.merkleTree = merkleTree;
this.commandHash = commandHash;
this.command = command;
this.action = action;
this.actionKey = actionKey;
}

public RemoteActionExecutionContext getRemoteActionExecutionContext() {
return remoteActionExecutionContext;
}

public SpawnExecutionContext getSpawnExecutionContext() {
return spawnExecutionContext;
}

/** Returns the {@link Spawn} that owns this action. */
public Spawn getSpawn() {
return spawn;
}

/**
* Returns the sum of file sizes plus protobuf sizes used to represent the inputs of this action.
*/
public long getInputBytes() {
return merkleTree.getInputBytes();
}

/** Returns the number of input files of this action. */
public long getInputFiles() {
return merkleTree.getInputFiles();
}

/** Returns the id this is action. */
public String getActionId() {
return actionKey.getDigest().getHash();
}

/** Returns the {@link ActionKey} of this action. */
public ActionKey getActionKey() {
return actionKey;
}

/** Returns underlying {@link Action} of this remote action. */
public Action getAction() {
return action;
}

public Digest getCommandHash() {
return commandHash;
}

public Command getCommand() {
return command;
}

public MerkleTree getMerkleTree() {
return merkleTree;
}

/**
* Returns a {@link SortedMap} which maps from input paths for remote action to {@link
* ActionInput}.
*/
public SortedMap<PathFragment, ActionInput> getInputMap()
throws IOException, ForbiddenActionInputException {
return remotePathResolver.getInputMapping(spawnExecutionContext);
}

/**
* Returns the {@link NetworkTime} instance used to measure the network time during the action
* execution.
*/
public NetworkTime getNetworkTime() {
return remoteActionExecutionContext.getNetworkTime();
}
}
Loading

0 comments on commit 4d900ce

Please sign in to comment.