forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remote: Prefetch input files into a temporary path first.
When building with build without bytes and dynamic execution, we need prefetch input files for local actions. Sometimes, multiple local actions could share the same input files, so there could be a case where multiple call sites share the same download instance. If the local action is cancelled (due to remote branch wins), the download it requested should also be cancelled only if that download is not shared with other local action (or all the releated local actions are cancelled). Before this change, the inputs are written to their final destination directly. This is fine if we can make sure no race or bug in the prefetcher. However, this is not true: bazelbuild#15010. The root cause is, when cancelling the downloads, sometimes, the partially downloaded files on the disk are not deleted. By making the prefetcher download input to a temporary path first, we can: 1. Mitigate the race: only the final move step will potentially cause the race condition. 2. Provide a way to observe the race: if these is no race, all temporary files should be either moved or deleted. But when running with this change, many temporary files exist. Working towards bazelbuild#12454. PiperOrigin-RevId: 447473693
- Loading branch information
1 parent
74fff55
commit 280ef69
Showing
5 changed files
with
149 additions
and
44 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
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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/google/devtools/build/lib/remote/util/TempPathGenerator.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,40 @@ | ||
// 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.util; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.devtools.build.lib.vfs.Path; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** A generator that generate temporary path under a given directory. */ | ||
@ThreadSafe | ||
public class TempPathGenerator { | ||
private final Path tempDir; | ||
private final AtomicInteger index = new AtomicInteger(); | ||
|
||
public TempPathGenerator(Path tempDir) { | ||
this.tempDir = tempDir; | ||
} | ||
|
||
/** Generates a temporary path */ | ||
public Path generateTempPath() { | ||
return tempDir.getChild(index.getAndIncrement() + ".tmp"); | ||
} | ||
|
||
@VisibleForTesting | ||
public Path getTempDir() { | ||
return tempDir; | ||
} | ||
} |
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