From f1dacedfcd28358c856ff5766af34c5afd7cb688 Mon Sep 17 00:00:00 2001 From: Tyler Williams Date: Thu, 10 Aug 2023 03:14:05 -0700 Subject: [PATCH] Ensure disk cache root exists The disk cache root directory was previously being manually created in two places before creating the disk cache client. This CL instead ensures that the disk cache root directory is created when createDiskCache() is called, and simplifies the other callsites. This fixes an issue where the disk cache directory might not exist if using --digest_function=BLAKE3. Closes #19202. PiperOrigin-RevId: 555429326 Change-Id: Ifcfa8c686df30c03c9fca24be860b2db780a6374 --- .../build/lib/remote/RemoteCacheClientFactory.java | 13 ++----------- .../build/lib/remote/disk/DiskCacheClient.java | 6 ++++-- .../build/remote/worker/OnDiskBlobStoreCache.java | 3 ++- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactory.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactory.java index 8f68923f9fffcd..942ad85bfd9c03 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactory.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteCacheClientFactory.java @@ -139,10 +139,7 @@ private static DiskCacheClient createDiskCache( throws IOException { Path cacheDir = workingDirectory.getRelative(Preconditions.checkNotNull(diskCachePath, "diskCachePath")); - if (!cacheDir.exists()) { - cacheDir.createDirectoryAndParents(); - } - return new DiskCacheClient(cacheDir, verifyDownloads, checkActionResult, digestUtil); + return new DiskCacheClient(cacheDir, verifyDownloads, digestUtil); } private static RemoteCacheClient createDiskAndHttpCache( @@ -153,13 +150,7 @@ private static RemoteCacheClient createDiskAndHttpCache( AuthAndTLSOptions authAndTlsOptions, DigestUtil digestUtil) throws IOException { - Path cacheDir = - workingDirectory.getRelative(Preconditions.checkNotNull(diskCachePath, "diskCachePath")); - if (!cacheDir.exists()) { - cacheDir.createDirectoryAndParents(); - } - - RemoteCacheClient httpCache = createHttp(options, cred, authAndTlsOptions, digestUtil); + RemoteCacheClient httpCache = createHttp(options, cred, authAndTlsOptions, digestUtil, retrier); return createDiskAndRemoteClient( workingDirectory, diskCachePath, diff --git a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java index 1c0777f77bc0de..397217cde19cc6 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java +++ b/src/main/java/com/google/devtools/build/lib/remote/disk/DiskCacheClient.java @@ -58,8 +58,8 @@ public class DiskCacheClient implements RemoteCacheClient { * @param checkActionResult whether check referenced blobs exist in CAS when checking AC. If this * is {@code true} and blobs referenced by the AC are missing, ignore the AC. */ - public DiskCacheClient( - Path root, boolean verifyDownloads, boolean checkActionResult, DigestUtil digestUtil) { + public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil) + throws IOException { this.verifyDownloads = verifyDownloads; this.checkActionResult = checkActionResult; this.digestUtil = digestUtil; @@ -71,6 +71,8 @@ public DiskCacheClient( root.getChild( Ascii.toLowerCase(digestUtil.getDigestFunction().getValueDescriptor().getName())); } + + this.root.createDirectoryAndParents(); } /** Returns {@code true} if the provided {@code key} is stored in the CAS. */ diff --git a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java index c67577c54b92b7..b52afe681df8cf 100644 --- a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java +++ b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/OnDiskBlobStoreCache.java @@ -43,7 +43,8 @@ class OnDiskBlobStoreCache extends RemoteCache { .setSymlinkAbsolutePathStrategy(SymlinkAbsolutePathStrategy.Value.ALLOWED) .build(); - public OnDiskBlobStoreCache(RemoteOptions options, Path cacheDir, DigestUtil digestUtil) { + public OnDiskBlobStoreCache(RemoteOptions options, Path cacheDir, DigestUtil digestUtil) + throws IOException { super( CAPABILITIES, new DiskCacheClient(