Skip to content

Commit cdf118a

Browse files
ulfjackCopybara-Service
authored and
Copybara-Service
committed
Enable --experimental_remote_spawn_cache by default
- It is now an error to specify the gRPC remote execution backend in combination with a local disk or HTTP-based cache. - It is now an error to specify both local disk and HTTP-based caches. Note that before this CL, enabling the local disk cache silently disabled remote execution - we now give an error in that case. With these combination no longer being accepted, remote execution being enabled now means that we only create a RemoteSpawnRunner, and don't provide a SpawnCache. This is not a semantic change - we never created both. In principle, it should be possible for users to combine local execution with remote caching for actions that are marked local or no-remote, and still use remote execution otherwise. However, Bazel cannot currently express this combination of execution strategies. RELNOTES: The --experimental_remote_spawn_cache flag is now enabled by default, and remote caching no longer needs --*_strategy=remote flags (it will fail if they are specified). PiperOrigin-RevId: 198280398
1 parent 2ad044c commit cdf118a

File tree

6 files changed

+28
-53
lines changed

6 files changed

+28
-53
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
*/
3939
final class RemoteActionContextProvider extends ActionContextProvider {
4040
private final CommandEnvironment env;
41-
private final AbstractRemoteActionCache cache;
42-
private final GrpcRemoteExecutor executor;
41+
@Nullable private final AbstractRemoteActionCache cache;
42+
@Nullable private final GrpcRemoteExecutor executor;
4343
private final DigestUtil digestUtil;
4444
private final Path logDir;
4545

@@ -64,7 +64,7 @@ public Iterable<? extends ActionContext> getActionContexts() {
6464
String buildRequestId = env.getBuildRequestId().toString();
6565
String commandId = env.getCommandId().toString();
6666

67-
if (remoteOptions.experimentalRemoteSpawnCache || remoteOptions.diskCache != null) {
67+
if (executor == null && cache != null) {
6868
RemoteSpawnCache spawnCache =
6969
new RemoteSpawnCache(
7070
env.getExecRoot(),

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

+22-10
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void serverInit(OptionsProvider startupOptions, ServerBuilder builder)
9797
}
9898

9999
@Override
100-
public void beforeCommand(CommandEnvironment env) {
100+
public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
101101
env.getEventBus().register(this);
102102
String buildRequestId = env.getBuildRequestId().toString();
103103
String commandId = env.getCommandId().toString();
@@ -113,6 +113,7 @@ public void beforeCommand(CommandEnvironment env) {
113113
} catch (IOException e) {
114114
env.getReporter()
115115
.handle(Event.error("Could not create base directory for remote logs: " + logDir));
116+
throw new AbruptExitException(ExitCode.LOCAL_ENVIRONMENTAL_ERROR, e);
116117
}
117118
RemoteOptions remoteOptions = env.getOptions().getOptions(RemoteOptions.class);
118119
AuthAndTLSOptions authAndTlsOptions = env.getOptions().getOptions(AuthAndTLSOptions.class);
@@ -126,10 +127,22 @@ public void beforeCommand(CommandEnvironment env) {
126127
return;
127128
}
128129

129-
try {
130-
boolean remoteOrLocalCache = SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions);
131-
boolean grpcCache = GrpcRemoteCache.isRemoteCacheOptions(remoteOptions);
130+
boolean enableRestCache = SimpleBlobStoreFactory.isRestUrlOptions(remoteOptions);
131+
boolean enableDiskCache = SimpleBlobStoreFactory.isDiskCache(remoteOptions);
132+
if (enableRestCache && enableDiskCache) {
133+
throw new AbruptExitException(
134+
"Cannot enable HTTP-based and local disk cache simultaneously",
135+
ExitCode.COMMAND_LINE_ERROR);
136+
}
137+
boolean enableBlobStoreCache = enableRestCache || enableDiskCache;
138+
boolean enableGrpcCache = GrpcRemoteCache.isRemoteCacheOptions(remoteOptions);
139+
if (enableBlobStoreCache && remoteOptions.remoteExecutor != null) {
140+
throw new AbruptExitException(
141+
"Cannot combine gRPC based remote execution with local disk or HTTP-based caching",
142+
ExitCode.COMMAND_LINE_ERROR);
143+
}
132144

145+
try {
133146
LoggingInterceptor logger = null;
134147
if (!remoteOptions.experimentalRemoteGrpcLog.isEmpty()) {
135148
rpcLogFile = new AsynchronousFileOutputStream(remoteOptions.experimentalRemoteGrpcLog);
@@ -139,10 +152,8 @@ public void beforeCommand(CommandEnvironment env) {
139152
RemoteRetrier retrier =
140153
new RemoteRetrier(
141154
remoteOptions, RemoteRetrier.RETRIABLE_GRPC_ERRORS, Retrier.ALLOW_ALL_CALLS);
142-
// TODO(davido): The naming is wrong here. "Remote"-prefix in RemoteActionCache class has no
143-
// meaning.
144155
final AbstractRemoteActionCache cache;
145-
if (remoteOrLocalCache) {
156+
if (enableBlobStoreCache) {
146157
cache =
147158
new SimpleBlobStoreActionCache(
148159
remoteOptions,
@@ -151,9 +162,9 @@ public void beforeCommand(CommandEnvironment env) {
151162
GoogleAuthUtils.newCredentials(authAndTlsOptions),
152163
env.getWorkingDirectory()),
153164
digestUtil);
154-
} else if (grpcCache || remoteOptions.remoteExecutor != null) {
165+
} else if (enableGrpcCache || remoteOptions.remoteExecutor != null) {
155166
// If a remote executor but no remote cache is specified, assume both at the same target.
156-
String target = grpcCache ? remoteOptions.remoteCache : remoteOptions.remoteExecutor;
167+
String target = enableGrpcCache ? remoteOptions.remoteCache : remoteOptions.remoteExecutor;
157168
Channel ch = GoogleAuthUtils.newChannel(target, authAndTlsOptions);
158169
if (logger != null) {
159170
ch = ClientInterceptors.intercept(ch, logger);
@@ -169,6 +180,8 @@ public void beforeCommand(CommandEnvironment env) {
169180
cache = null;
170181
}
171182

183+
// TODO(davido): The naming is wrong here. "Remote"-prefix in RemoteActionCache class has no
184+
// meaning.
172185
final GrpcRemoteExecutor executor;
173186
if (remoteOptions.remoteExecutor != null) {
174187
Channel ch = GoogleAuthUtils.newChannel(remoteOptions.remoteExecutor, authAndTlsOptions);
@@ -184,7 +197,6 @@ public void beforeCommand(CommandEnvironment env) {
184197
} else {
185198
executor = null;
186199
}
187-
188200
actionContextProvider =
189201
new RemoteActionContextProvider(env, cache, executor, digestUtil, logDir);
190202
} catch (IOException e) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ public final class RemoteOptions extends OptionsBase {
164164
)
165165
public double experimentalRemoteRetryJitter;
166166

167+
@Deprecated
167168
@Option(
168169
name = "experimental_remote_spawn_cache",
169170
defaultValue = "false",
170171
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
171-
effectTags = {OptionEffectTag.UNKNOWN},
172+
effectTags = {OptionEffectTag.NO_OP},
172173
help =
173174
"Whether to use the experimental spawn cache infrastructure for remote caching. "
174175
+ "Enabling this flag makes Bazel ignore any setting for remote_executor."

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static boolean isDiskCache(RemoteOptions options) {
7777
return options.diskCache != null;
7878
}
7979

80-
private static boolean isRestUrlOptions(RemoteOptions options) {
80+
static boolean isRestUrlOptions(RemoteOptions options) {
8181
return options.remoteHttpCache != null;
8282
}
8383
}

src/test/shell/bazel/remote/remote_execution_http_test.sh

-26
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ EOF
7878

7979
bazel clean --expunge >& $TEST_log
8080
bazel build \
81-
--experimental_remote_spawn_cache=true \
8281
--remote_http_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
8382
//a:test >& $TEST_log \
8483
|| fail "Failed to build //a:test with remote REST cache service"
@@ -112,7 +111,6 @@ EOF
112111

113112
bazel clean --expunge >& $TEST_log
114113
bazel build \
115-
--experimental_remote_spawn_cache=true \
116114
--remote_http_cache=http://bad.hostname/bad/cache \
117115
//a:test >& $TEST_log \
118116
|| fail "Failed to build //a:test with remote REST cache service"
@@ -136,15 +134,6 @@ genrule(
136134
)
137135
EOF
138136
bazel build \
139-
--genrule_strategy=remote \
140-
--noremote_allow_symlink_upload \
141-
--remote_http_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
142-
//:make-link &> $TEST_log \
143-
&& fail "should have failed" || true
144-
expect_log "/l is a symbolic link"
145-
146-
bazel build \
147-
--experimental_remote_spawn_cache \
148137
--noremote_allow_symlink_upload \
149138
--remote_http_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
150139
//:make-link &> $TEST_log \
@@ -161,15 +150,6 @@ genrule(
161150
)
162151
EOF
163152
bazel build \
164-
--genrule_strategy=remote \
165-
--noremote_allow_symlink_upload \
166-
--remote_http_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
167-
//:make-link &> $TEST_log \
168-
&& fail "should have failed" || true
169-
expect_log "dir/l is a symbolic link"
170-
171-
bazel build \
172-
--experimental_remote_spawn_cache \
173153
--noremote_allow_symlink_upload \
174154
--remote_http_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
175155
//:make-link &> $TEST_log \
@@ -224,7 +204,6 @@ function test_directory_artifact() {
224204
bazel build \
225205
--spawn_strategy=remote \
226206
--remote_executor=localhost:${worker_port} \
227-
--remote_cache=localhost:${worker_port} \
228207
//a:test >& $TEST_log \
229208
|| fail "Failed to build //a:test with remote execution"
230209
diff bazel-genfiles/a/qux/out.txt a/test_expected \
@@ -235,7 +214,6 @@ function test_directory_artifact_grpc_cache() {
235214
set_directory_artifact_testfixtures
236215

237216
bazel build \
238-
--spawn_strategy=remote \
239217
--remote_cache=localhost:${worker_port} \
240218
//a:test >& $TEST_log \
241219
|| fail "Failed to build //a:test with remote gRPC cache"
@@ -247,7 +225,6 @@ function test_directory_artifact_rest_cache() {
247225
set_directory_artifact_testfixtures
248226

249227
bazel build \
250-
--spawn_strategy=remote \
251228
--remote_rest_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
252229
//a:test >& $TEST_log \
253230
|| fail "Failed to build //a:test with remote REST cache"
@@ -320,7 +297,6 @@ function test_directory_artifact_skylark() {
320297
bazel build \
321298
--spawn_strategy=remote \
322299
--remote_executor=localhost:${worker_port} \
323-
--remote_cache=localhost:${worker_port} \
324300
//a:test >& $TEST_log \
325301
|| fail "Failed to build //a:test with remote execution"
326302
diff bazel-genfiles/a/qux/out.txt a/test_expected \
@@ -331,7 +307,6 @@ function test_directory_artifact_skylark_grpc_cache() {
331307
set_directory_artifact_skylark_testfixtures
332308

333309
bazel build \
334-
--spawn_strategy=remote \
335310
--remote_cache=localhost:${worker_port} \
336311
//a:test >& $TEST_log \
337312
|| fail "Failed to build //a:test with remote gRPC cache"
@@ -343,7 +318,6 @@ function test_directory_artifact_skylark_rest_cache() {
343318
set_directory_artifact_skylark_testfixtures
344319

345320
bazel build \
346-
--spawn_strategy=remote \
347321
--remote_rest_cache=http://localhost:${hazelcast_port}/hazelcast/rest/maps \
348322
//a:test >& $TEST_log \
349323
|| fail "Failed to build //a:test with remote REST cache"

src/test/shell/bazel/remote/remote_execution_test.sh

-12
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ EOF
8989
bazel build \
9090
--spawn_strategy=remote \
9191
--remote_executor=localhost:${worker_port} \
92-
--remote_cache=localhost:${worker_port} \
9392
//a:test >& $TEST_log \
9493
|| fail "Failed to build //a:test with remote execution"
9594
diff bazel-bin/a/test ${TEST_TMPDIR}/test_expected \
@@ -119,7 +118,6 @@ EOF
119118
bazel test \
120119
--spawn_strategy=remote \
121120
--remote_executor=localhost:${worker_port} \
122-
--remote_cache=localhost:${worker_port} \
123121
--test_output=errors \
124122
//a:test >& $TEST_log \
125123
|| fail "Failed to run //a:test with remote execution"
@@ -144,7 +142,6 @@ EOF
144142

145143
bazel clean --expunge >& $TEST_log
146144
bazel build \
147-
--spawn_strategy=remote \
148145
--remote_cache=localhost:${worker_port} \
149146
//a:test >& $TEST_log \
150147
|| fail "Failed to build //a:test with remote gRPC cache service"
@@ -168,7 +165,6 @@ EOF
168165
bazel test \
169166
--spawn_strategy=remote \
170167
--remote_executor=localhost:${worker_port} \
171-
--remote_cache=localhost:${worker_port} \
172168
--test_output=errors \
173169
//a:test >& $TEST_log \
174170
&& fail "Expected test failure" || true
@@ -194,7 +190,6 @@ EOF
194190
int main() { std::cout << "Fail me!" << std::endl; return 1; }
195191
EOF
196192
bazel test \
197-
--spawn_strategy=remote \
198193
--remote_cache=localhost:${worker_port} \
199194
--test_output=errors \
200195
//a:test >& $TEST_log \
@@ -219,7 +214,6 @@ EOF
219214
int main() { std::cout << "Fail me!" << std::endl; return 1; }
220215
EOF
221216
bazel test \
222-
--experimental_remote_spawn_cache \
223217
--remote_cache=localhost:${worker_port} \
224218
--test_output=errors \
225219
//a:test >& $TEST_log \
@@ -236,7 +230,6 @@ EOF
236230
int main() { std::cout << "Fail me again!" << std::endl; return 1; }
237231
EOF
238232
bazel test \
239-
--experimental_remote_spawn_cache \
240233
--remote_cache=localhost:${worker_port} \
241234
--test_output=errors \
242235
//a:test >& $TEST_log \
@@ -272,7 +265,6 @@ EOF
272265
bazel build \
273266
--spawn_strategy=remote \
274267
--remote_executor=localhost:${worker_port} \
275-
--remote_cache=localhost:${worker_port} \
276268
//a:large_output >& $TEST_log \
277269
|| fail "Failed to build //a:large_output with remote execution"
278270
diff bazel-genfiles/a/large_blob.txt ${TEST_TMPDIR}/large_blob_expected.txt \
@@ -296,7 +288,6 @@ EOF
296288
bazel test \
297289
--spawn_strategy=remote \
298290
--remote_executor=localhost:${worker_port} \
299-
--remote_cache=localhost:${worker_port} \
300291
--test_output=errors \
301292
//a:test >& $TEST_log \
302293
|| fail "Failed to run //a:test with remote execution"
@@ -331,7 +322,6 @@ EOF
331322
bazel test \
332323
--spawn_strategy=remote \
333324
--remote_executor=localhost:${worker_port} \
334-
--remote_cache=localhost:${worker_port} \
335325
--test_output=errors \
336326
//a:test >& $TEST_log \
337327
|| fail "Failed to run //a:test with remote execution"
@@ -370,7 +360,6 @@ EOF
370360
bazel test \
371361
--spawn_strategy=remote \
372362
--remote_executor=localhost:${worker_port} \
373-
--remote_cache=localhost:${worker_port} \
374363
--test_output=errors \
375364
//a:test >& $TEST_log \
376365
&& fail "Expected test failure" || true
@@ -400,7 +389,6 @@ package(default_visibility = ["//visibility:public"])
400389
empty(name = 'test')
401390
EOF
402391
bazel build \
403-
--spawn_strategy=remote \
404392
--remote_cache=localhost:${worker_port} \
405393
--test_output=errors \
406394
//a:test >& $TEST_log \

0 commit comments

Comments
 (0)