Skip to content

Commit c887c2a

Browse files
tjgqcopybara-github
authored andcommitted
Delete the --experimental_delay_virtual_input_materialization flag.
This flag was added in 8fd4fe8 as an attempt to roll out a fix for a sandboxing bug, but it turned out not to be the right fix and it was never flipped. PiperOrigin-RevId: 468168717 Change-Id: I3a58aaef9a26564e67da9558ff0d2f56e733b3e2
1 parent 40ccdba commit c887c2a

19 files changed

+102
-309
lines changed

src/main/java/com/google/devtools/build/lib/sandbox/AbstractContainerizingSandboxedSpawn.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public void createFileSystem() throws IOException {
115115
// Finally create what needs creating.
116116
SandboxHelpers.createDirectories(dirsToCreate, sandboxExecRoot, /* strict=*/ true);
117117
createInputs(inputsToCreate, inputs);
118-
inputs.materializeVirtualInputs(sandboxExecRoot);
119118
}
120119

121120
protected void filterInputsAndDirsToCreate(

src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java

Lines changed: 24 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.devtools.build.lib.sandbox;
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
18-
import static com.google.common.base.Preconditions.checkState;
1918
import static com.google.devtools.build.lib.vfs.Dirent.Type.DIRECTORY;
2019
import static com.google.devtools.build.lib.vfs.Dirent.Type.SYMLINK;
2120

@@ -62,21 +61,6 @@ public final class SandboxHelpers {
6261
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
6362

6463
private static final AtomicBoolean warnedAboutMovesBeingCopies = new AtomicBoolean(false);
65-
/**
66-
* If true, materialize virtual inputs only inside the sandbox, not the output tree. This flag
67-
* exists purely to support rolling this out as the defaut in a controlled manner.
68-
*/
69-
private final boolean delayVirtualInputMaterialization;
70-
71-
/**
72-
* Constructs a new collection of helpers.
73-
*
74-
* @param delayVirtualInputMaterialization whether to materialize virtual inputs only inside the
75-
* sandbox
76-
*/
77-
public SandboxHelpers(boolean delayVirtualInputMaterialization) {
78-
this.delayVirtualInputMaterialization = delayVirtualInputMaterialization;
79-
}
8064

8165
/**
8266
* Writes a virtual input file so that the final file is always consistent to all readers.
@@ -365,38 +349,21 @@ public static final class SandboxInputs {
365349
new AtomicInteger();
366350

367351
private final Map<PathFragment, Path> files;
368-
// Virtual inputs that are not materialized during {@link #processInputFiles}
369-
private final Set<VirtualActionInput> virtualInputsWithDelayedMaterialization;
370-
// Virtual inputs that are materialized during {@link #processInputFiles}.
371-
private final Map<VirtualActionInput, byte[]> materializedVirtualInputs;
352+
private final Map<VirtualActionInput, byte[]> virtualInputs;
372353
private final Map<PathFragment, PathFragment> symlinks;
373354

374355
private static final SandboxInputs EMPTY_INPUTS =
375-
new SandboxInputs(
376-
ImmutableMap.of(), ImmutableSet.of(), ImmutableMap.of(), ImmutableMap.of());
356+
new SandboxInputs(ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of());
377357

378358
public SandboxInputs(
379359
Map<PathFragment, Path> files,
380-
Set<VirtualActionInput> virtualInputsWithDelayedMaterialization,
381-
Map<VirtualActionInput, byte[]> materializedVirtualInputs,
360+
Map<VirtualActionInput, byte[]> virtualInputs,
382361
Map<PathFragment, PathFragment> symlinks) {
383-
checkState(
384-
virtualInputsWithDelayedMaterialization.isEmpty() || materializedVirtualInputs.isEmpty(),
385-
"Either virtualInputsWithDelayedMaterialization or materializedVirtualInputs should be"
386-
+ " empty.");
387362
this.files = files;
388-
this.virtualInputsWithDelayedMaterialization = virtualInputsWithDelayedMaterialization;
389-
this.materializedVirtualInputs = materializedVirtualInputs;
363+
this.virtualInputs = virtualInputs;
390364
this.symlinks = symlinks;
391365
}
392366

393-
public SandboxInputs(
394-
Map<PathFragment, Path> files,
395-
Set<VirtualActionInput> virtualInputsWithDelayedMaterialization,
396-
Map<PathFragment, PathFragment> symlinks) {
397-
this(files, virtualInputsWithDelayedMaterialization, ImmutableMap.of(), symlinks);
398-
}
399-
400367
public static SandboxInputs getEmptyInputs() {
401368
return EMPTY_INPUTS;
402369
}
@@ -425,8 +392,6 @@ public Map<PathFragment, PathFragment> getSymlinks() {
425392
private static byte[] materializeVirtualInput(
426393
VirtualActionInput input, Path execroot, boolean isExecRootSandboxed) throws IOException {
427394
if (input instanceof EmptyActionInput) {
428-
// TODO(b/150963503): We can turn this into an unreachable code path when the old
429-
// !delayVirtualInputMaterialization code path is deleted.
430395
return new byte[0];
431396
}
432397

@@ -447,31 +412,8 @@ private static byte[] materializeVirtualInput(
447412
return writeVirtualInputTo(input, outputPath);
448413
}
449414

450-
/**
451-
* Materializes virtual files inside the sandboxed execroot once it is known.
452-
*
453-
* <p>These are files that do not have to exist in the execroot: we can materialize them only
454-
* inside the sandbox, which means we can create them <i>before</i> we grab the output tree lock
455-
* (but assuming we do so inside the sandbox only).
456-
*
457-
* @param sandboxExecRoot the path to the <i>sandboxed</i> execroot
458-
* @return digests of written virtual inputs
459-
* @throws IOException if any virtual input cannot be materialized
460-
*/
461-
public ImmutableMap<VirtualActionInput, byte[]> materializeVirtualInputs(Path sandboxExecRoot)
462-
throws IOException {
463-
if (!materializedVirtualInputs.isEmpty()) {
464-
return ImmutableMap.copyOf(materializedVirtualInputs);
465-
}
466-
467-
ImmutableMap.Builder<VirtualActionInput, byte[]> digests =
468-
ImmutableMap.builderWithExpectedSize(virtualInputsWithDelayedMaterialization.size());
469-
for (VirtualActionInput input : virtualInputsWithDelayedMaterialization) {
470-
byte[] digest =
471-
materializeVirtualInput(input, sandboxExecRoot, /*isExecRootSandboxed=*/ false);
472-
digests.put(input, digest);
473-
}
474-
return digests.buildOrThrow();
415+
public ImmutableMap<VirtualActionInput, byte[]> getVirtualInputDigests() {
416+
return ImmutableMap.copyOf(virtualInputs);
475417
}
476418

477419
/**
@@ -481,19 +423,13 @@ public ImmutableMap<VirtualActionInput, byte[]> materializeVirtualInputs(Path sa
481423
public SandboxInputs limitedCopy(Set<PathFragment> allowed) {
482424
return new SandboxInputs(
483425
Maps.filterKeys(files, allowed::contains),
484-
ImmutableSet.of(),
485426
ImmutableMap.of(),
486427
Maps.filterKeys(symlinks, allowed::contains));
487428
}
488429

489430
@Override
490431
public String toString() {
491-
return "Files: "
492-
+ files
493-
+ "\nVirtualInputs: "
494-
+ virtualInputsWithDelayedMaterialization
495-
+ "\nSymlinks: "
496-
+ symlinks;
432+
return "Files: " + files + "\nVirtualInputs: " + virtualInputs + "\nSymlinks: " + symlinks;
497433
}
498434
}
499435

@@ -519,66 +455,37 @@ private static byte[] writeVirtualInputTo(VirtualActionInput input, Path target)
519455
* Returns the inputs of a Spawn as a map of PathFragments relative to an execRoot to paths in the
520456
* host filesystem where the input files can be found.
521457
*
522-
* <p>This does not (and must not) write any {@link VirtualActionInput}s found because we do not
523-
* yet know where they should be written to. We have a path to an {@code execRoot}, but this path
524-
* should be treated as read-only because we may not be holding its lock. The caller should use
525-
* {@link SandboxInputs#materializeVirtualInputs(Path)} to later write these inputs when it knows
526-
* where they should be written to.
527-
*
528458
* @throws IOException if processing symlinks fails
529459
*/
530460
public SandboxInputs processInputFiles(Map<PathFragment, ActionInput> inputMap, Path execRoot)
531461
throws IOException {
532462
Map<PathFragment, Path> inputFiles = new TreeMap<>();
533-
Set<VirtualActionInput> virtualInputsWithDelayedMaterialization = new HashSet<>();
534463
Map<PathFragment, PathFragment> inputSymlinks = new TreeMap<>();
535-
Map<VirtualActionInput, byte[]> materializedVirtualInputs = new HashMap<>();
464+
Map<VirtualActionInput, byte[]> virtualInputs = new HashMap<>();
536465

537466
for (Map.Entry<PathFragment, ActionInput> e : inputMap.entrySet()) {
538467
PathFragment pathFragment = e.getKey();
539468
ActionInput actionInput = e.getValue();
540469

541-
// TODO(b/150963503): Make delayVirtualInputMaterialization the default and remove the
542-
// alternate code path.
543-
if (delayVirtualInputMaterialization) {
544-
if (actionInput instanceof VirtualActionInput) {
545-
if (actionInput instanceof EmptyActionInput) {
546-
inputFiles.put(pathFragment, null);
547-
} else {
548-
virtualInputsWithDelayedMaterialization.add((VirtualActionInput) actionInput);
549-
}
550-
} else if (actionInput.isSymlink()) {
551-
Path inputPath = execRoot.getRelative(actionInput.getExecPath());
552-
inputSymlinks.put(pathFragment, inputPath.readSymbolicLink());
553-
} else {
554-
Path inputPath = execRoot.getRelative(actionInput.getExecPath());
555-
inputFiles.put(pathFragment, inputPath);
556-
}
557-
} else {
558-
if (actionInput instanceof VirtualActionInput) {
559-
byte[] digest =
560-
SandboxInputs.materializeVirtualInput(
561-
(VirtualActionInput) actionInput, execRoot, /* isExecRootSandboxed=*/ true);
562-
materializedVirtualInputs.put((VirtualActionInput) actionInput, digest);
563-
}
470+
if (actionInput instanceof VirtualActionInput) {
471+
byte[] digest =
472+
SandboxInputs.materializeVirtualInput(
473+
(VirtualActionInput) actionInput, execRoot, /* isExecRootSandboxed=*/ true);
474+
virtualInputs.put((VirtualActionInput) actionInput, digest);
475+
}
564476

565-
if (actionInput.isSymlink()) {
566-
Path inputPath = execRoot.getRelative(actionInput.getExecPath());
567-
inputSymlinks.put(pathFragment, inputPath.readSymbolicLink());
568-
} else {
569-
Path inputPath =
570-
actionInput instanceof EmptyActionInput
571-
? null
572-
: execRoot.getRelative(actionInput.getExecPath());
573-
inputFiles.put(pathFragment, inputPath);
574-
}
477+
if (actionInput.isSymlink()) {
478+
Path inputPath = execRoot.getRelative(actionInput.getExecPath());
479+
inputSymlinks.put(pathFragment, inputPath.readSymbolicLink());
480+
} else {
481+
Path inputPath =
482+
actionInput instanceof EmptyActionInput
483+
? null
484+
: execRoot.getRelative(actionInput.getExecPath());
485+
inputFiles.put(pathFragment, inputPath);
575486
}
576487
}
577-
return new SandboxInputs(
578-
inputFiles,
579-
virtualInputsWithDelayedMaterialization,
580-
materializedVirtualInputs,
581-
inputSymlinks);
488+
return new SandboxInputs(inputFiles, virtualInputs, inputSymlinks);
582489
}
583490

584491
/** The file and directory outputs of a sandboxed spawn. */

src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private void setup(CommandEnvironment cmdEnv, SpawnStrategyRegistry.Builder buil
199199
SandboxOptions options = checkNotNull(env.getOptions().getOptions(SandboxOptions.class));
200200
sandboxBase = computeSandboxBase(options, env);
201201

202-
SandboxHelpers helpers = new SandboxHelpers(options.delayVirtualInputMaterialization);
202+
SandboxHelpers helpers = new SandboxHelpers();
203203

204204
// Do not remove the sandbox base when --sandbox_debug was specified so that people can check
205205
// out the contents of the generated sandbox directories.

src/main/java/com/google/devtools/build/lib/sandbox/SandboxOptions.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,6 @@ public ImmutableSet<Path> getInaccessiblePaths(FileSystem fs) {
334334
+ " grows to the size specified by this flag when the server is idle.")
335335
public int asyncTreeDeleteIdleThreads;
336336

337-
@Option(
338-
name = "experimental_delay_virtual_input_materialization",
339-
defaultValue = "false",
340-
documentationCategory = OptionDocumentationCategory.EXECUTION_STRATEGY,
341-
effectTags = {OptionEffectTag.EXECUTION},
342-
help =
343-
"If set to true, creates virtual inputs (like params files) only inside the sandbox, "
344-
+ "not in the execroot, which fixes a race condition when using the dynamic "
345-
+ "scheduler. This flag exists purely to support rolling this bug fix out.")
346-
public boolean delayVirtualInputMaterialization;
347-
348337
@Option(
349338
name = "incompatible_legacy_local_fallback",
350339
defaultValue = "true",

src/main/java/com/google/devtools/build/lib/sandbox/SandboxfsSandboxedSpawn.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ public Path getStatisticsPath() {
182182
public void createFileSystem() throws IOException {
183183
sandboxScratchDir.createDirectory();
184184

185-
inputs.materializeVirtualInputs(sandboxScratchDir);
186-
187185
Set<PathFragment> dirsToCreate = new HashSet<>(writableDirs);
188186
for (PathFragment output : outputs.files()) {
189187
dirsToCreate.add(output.getParentDirectory());

src/main/java/com/google/devtools/build/lib/sandbox/WindowsSandboxedSpawnRunner.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ protected SandboxedSpawn prepareSpawn(Spawn spawn, SpawnExecutionContext context
7474
context.getInputMapping(PathFragment.EMPTY_FRAGMENT),
7575
execRoot);
7676

77-
readablePaths.materializeVirtualInputs(execRoot);
78-
7977
ImmutableSet.Builder<Path> writablePaths = ImmutableSet.builder();
8078
writablePaths.addAll(getWritableDirs(execRoot, environment));
8179
for (ActionInput output : spawn.getOutputFiles()) {

src/main/java/com/google/devtools/build/lib/worker/WorkerExecRoot.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public void createFileSystem(
6363
// we haven't seen what would break if we make it strict.
6464
SandboxHelpers.createDirectories(dirsToCreate, workDir, /* strict=*/ false);
6565
createInputs(inputsToCreate, inputs, workDir);
66-
67-
inputs.materializeVirtualInputs(workDir);
6866
}
6967

7068
static void createInputs(Iterable<PathFragment> inputsToCreate, SandboxInputs inputs, Path dir)

src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.google.devtools.build.lib.runtime.CommandEnvironment;
3232
import com.google.devtools.build.lib.runtime.commands.events.CleanStartingEvent;
3333
import com.google.devtools.build.lib.sandbox.SandboxHelpers;
34-
import com.google.devtools.build.lib.sandbox.SandboxOptions;
3534
import com.google.devtools.build.lib.vfs.Path;
3635
import com.google.devtools.build.lib.worker.WorkerPool.WorkerPoolConfig;
3736
import com.google.devtools.common.options.OptionsBase;
@@ -147,11 +146,10 @@ public void buildStarting(BuildStartingEvent event) {
147146
public void registerSpawnStrategies(
148147
SpawnStrategyRegistry.Builder registryBuilder, CommandEnvironment env) {
149148
checkNotNull(workerPool);
150-
SandboxOptions sandboxOptions = env.getOptions().getOptions(SandboxOptions.class);
151149
LocalEnvProvider localEnvProvider = LocalEnvProvider.forCurrentOs(env.getClientEnv());
152150
WorkerSpawnRunner spawnRunner =
153151
new WorkerSpawnRunner(
154-
new SandboxHelpers(sandboxOptions.delayVirtualInputMaterialization),
152+
new SandboxHelpers(),
155153
env.getExecRoot(),
156154
workerPool,
157155
env.getReporter(),

src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,13 @@ WorkResponse execInWorkerWorkerAsResource(
373373
WorkResponse response;
374374
WorkRequest request;
375375
ActionExecutionMetadata owner = spawn.getResourceOwner();
376-
ImmutableMap<VirtualActionInput, byte[]> virtualInputDigests;
376+
ImmutableMap<VirtualActionInput, byte[]> virtualInputDigests =
377+
inputFiles.getVirtualInputDigests();
378+
377379
Stopwatch setupInputsStopwatch = Stopwatch.createStarted();
378380

379381
try (SilentCloseable c =
380382
Profiler.instance().profile(ProfilerTask.WORKER_SETUP, "Preparing inputs")) {
381-
try {
382-
virtualInputDigests = inputFiles.materializeVirtualInputs(execRoot);
383-
} catch (IOException e) {
384-
restoreInterrupt(e);
385-
String message = "IOException while materializing virtual inputs:";
386-
throw createUserExecException(e, message, Code.VIRTUAL_INPUT_MATERIALIZATION_FAILURE);
387-
}
388-
389383
try {
390384
context.prefetchInputsAndWait();
391385
} catch (IOException e) {
@@ -521,19 +515,13 @@ WorkResponse execInWorkerClassic(
521515
WorkResponse response;
522516
WorkRequest request;
523517
ActionExecutionMetadata owner = spawn.getResourceOwner();
524-
ImmutableMap<VirtualActionInput, byte[]> virtualInputDigests;
518+
ImmutableMap<VirtualActionInput, byte[]> virtualInputDigests =
519+
inputFiles.getVirtualInputDigests();
520+
525521
try {
526522
Stopwatch setupInputsStopwatch = Stopwatch.createStarted();
527523
try (SilentCloseable c =
528524
Profiler.instance().profile(ProfilerTask.WORKER_SETUP, "Preparing inputs")) {
529-
try {
530-
virtualInputDigests = inputFiles.materializeVirtualInputs(execRoot);
531-
} catch (IOException e) {
532-
restoreInterrupt(e);
533-
String message = "IOException while materializing virtual inputs:";
534-
throw createUserExecException(e, message, Code.VIRTUAL_INPUT_MATERIALIZATION_FAILURE);
535-
}
536-
537525
try {
538526
context.prefetchInputsAndWait();
539527
} catch (IOException e) {

src/test/java/com/google/devtools/build/lib/sandbox/AbstractContainerizingSandboxedSpawnTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private static SandboxInputs createSandboxInputs(
377377
}
378378
return new SandboxInputs(
379379
filesMap,
380-
/*virtualInputs=*/ ImmutableSet.of(),
380+
/*virtualInputs=*/ ImmutableMap.of(),
381381
symlinks.entrySet().stream()
382382
.collect(
383383
toImmutableMap(

0 commit comments

Comments
 (0)