Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AOSP-pick] Do not wait for the write lock #7130

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ private FileTime readAccessTime(Path entry) throws IOException {
@Override
public void clean(long maxTargetSizeBytes, Duration minKeepDuration) throws BuildException {
// Ensure that no artifacts are added or read from the cache while we're cleaning:
long stamp = lock.writeLock();
long stamp = lock.tryWriteLock();
if (stamp == 0) {
logger.warning("Failed to clean the build cache at " + cacheDir + " Failed to obtain the write lock");
return; // Just exit. WE will clean the cache next time.
}
try {
needClean = false;
clean(maxTargetSizeBytes, Instant.now().minus(minKeepDuration));
Expand Down Expand Up @@ -467,7 +471,11 @@ void clean(long maxTargetSize, Instant minAgeToDelete) throws IOException {

public void purge() throws BuildException {
// Ensure that no artifacts are added or read from the cache while we're cleaning:
long stamp = lock.writeLock();
long stamp = lock.tryWriteLock();
if (stamp == 0) {
// TODO: b/373957467 - Report this error to the user properly.
throw new BuildException("Failed to purge the build artifact cache. Cannot obtain the write lock.");
}
try {
MoreFiles.deleteDirectoryContents(cacheDir);
} catch (IOException e) {
Expand Down
Loading