forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.2] Remote: Fix a bug that outputs of actions tagged with no-remote…
… 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 <ckolli@google.com>
- Loading branch information
Showing
11 changed files
with
355 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
src/main/java/com/google/devtools/build/lib/remote/RemoteAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.