Skip to content

Commit 4d900ce

Browse files
coeuvreckolli5
andauthored
[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 <[email protected]>
1 parent 0758347 commit 4d900ce

11 files changed

+355
-235
lines changed

src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.devtools.build.lib.events.Event;
3131
import com.google.devtools.build.lib.events.ExtendedEventHandler;
3232
import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext;
33+
import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext.Step;
3334
import com.google.devtools.build.lib.remote.util.DigestUtil;
3435
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
3536
import com.google.devtools.build.lib.vfs.Path;
@@ -271,7 +272,8 @@ private Single<PathConverter> upload(Set<Path> files) {
271272

272273
RequestMetadata metadata =
273274
TracingMetadataUtils.buildMetadata(buildRequestId, commandId, "bes-upload", null);
274-
RemoteActionExecutionContext context = RemoteActionExecutionContext.createForBES(metadata);
275+
RemoteActionExecutionContext context = RemoteActionExecutionContext.create(metadata);
276+
context.setStep(Step.UPLOAD_BES_FILES);
275277

276278
return Single.using(
277279
remoteCache::retain,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright 2022 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.google.devtools.build.lib.remote;
15+
16+
import build.bazel.remote.execution.v2.Action;
17+
import build.bazel.remote.execution.v2.Command;
18+
import build.bazel.remote.execution.v2.Digest;
19+
import com.google.devtools.build.lib.actions.ActionInput;
20+
import com.google.devtools.build.lib.actions.ForbiddenActionInputException;
21+
import com.google.devtools.build.lib.actions.Spawn;
22+
import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext;
23+
import com.google.devtools.build.lib.remote.common.NetworkTime;
24+
import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext;
25+
import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey;
26+
import com.google.devtools.build.lib.remote.common.RemotePathResolver;
27+
import com.google.devtools.build.lib.remote.merkletree.MerkleTree;
28+
import com.google.devtools.build.lib.vfs.PathFragment;
29+
import java.io.IOException;
30+
import java.util.SortedMap;
31+
32+
/** A value class representing an action which can be executed remotely. */
33+
public class RemoteAction {
34+
35+
private final Spawn spawn;
36+
private final SpawnExecutionContext spawnExecutionContext;
37+
private final RemoteActionExecutionContext remoteActionExecutionContext;
38+
private final RemotePathResolver remotePathResolver;
39+
private final MerkleTree merkleTree;
40+
private final Digest commandHash;
41+
private final Command command;
42+
private final Action action;
43+
private final ActionKey actionKey;
44+
45+
RemoteAction(
46+
Spawn spawn,
47+
SpawnExecutionContext spawnExecutionContext,
48+
RemoteActionExecutionContext remoteActionExecutionContext,
49+
RemotePathResolver remotePathResolver,
50+
MerkleTree merkleTree,
51+
Digest commandHash,
52+
Command command,
53+
Action action,
54+
ActionKey actionKey) {
55+
this.spawn = spawn;
56+
this.spawnExecutionContext = spawnExecutionContext;
57+
this.remoteActionExecutionContext = remoteActionExecutionContext;
58+
this.remotePathResolver = remotePathResolver;
59+
this.merkleTree = merkleTree;
60+
this.commandHash = commandHash;
61+
this.command = command;
62+
this.action = action;
63+
this.actionKey = actionKey;
64+
}
65+
66+
public RemoteActionExecutionContext getRemoteActionExecutionContext() {
67+
return remoteActionExecutionContext;
68+
}
69+
70+
public SpawnExecutionContext getSpawnExecutionContext() {
71+
return spawnExecutionContext;
72+
}
73+
74+
/** Returns the {@link Spawn} that owns this action. */
75+
public Spawn getSpawn() {
76+
return spawn;
77+
}
78+
79+
/**
80+
* Returns the sum of file sizes plus protobuf sizes used to represent the inputs of this action.
81+
*/
82+
public long getInputBytes() {
83+
return merkleTree.getInputBytes();
84+
}
85+
86+
/** Returns the number of input files of this action. */
87+
public long getInputFiles() {
88+
return merkleTree.getInputFiles();
89+
}
90+
91+
/** Returns the id this is action. */
92+
public String getActionId() {
93+
return actionKey.getDigest().getHash();
94+
}
95+
96+
/** Returns the {@link ActionKey} of this action. */
97+
public ActionKey getActionKey() {
98+
return actionKey;
99+
}
100+
101+
/** Returns underlying {@link Action} of this remote action. */
102+
public Action getAction() {
103+
return action;
104+
}
105+
106+
public Digest getCommandHash() {
107+
return commandHash;
108+
}
109+
110+
public Command getCommand() {
111+
return command;
112+
}
113+
114+
public MerkleTree getMerkleTree() {
115+
return merkleTree;
116+
}
117+
118+
/**
119+
* Returns a {@link SortedMap} which maps from input paths for remote action to {@link
120+
* ActionInput}.
121+
*/
122+
public SortedMap<PathFragment, ActionInput> getInputMap()
123+
throws IOException, ForbiddenActionInputException {
124+
return remotePathResolver.getInputMapping(spawnExecutionContext);
125+
}
126+
127+
/**
128+
* Returns the {@link NetworkTime} instance used to measure the network time during the action
129+
* execution.
130+
*/
131+
public NetworkTime getNetworkTime() {
132+
return remoteActionExecutionContext.getNetworkTime();
133+
}
134+
}

0 commit comments

Comments
 (0)