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

Separate new-style-hash content in DiskCache #19073

Closed
Closed
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 @@ -15,8 +15,10 @@

import build.bazel.remote.execution.v2.ActionResult;
import build.bazel.remote.execution.v2.Digest;
import build.bazel.remote.execution.v2.DigestFunction;
import build.bazel.remote.execution.v2.Directory;
import build.bazel.remote.execution.v2.Tree;
import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import com.google.common.util.concurrent.Futures;
Expand Down Expand Up @@ -53,9 +55,16 @@ public class DiskCacheClient implements RemoteCacheClient {
* digest used to index that file.
*/
public DiskCacheClient(Path root, boolean verifyDownloads, DigestUtil digestUtil) {
this.root = root;
this.verifyDownloads = verifyDownloads;
this.digestUtil = digestUtil;

if (isOldStyleDigestFunction(digestUtil.getDigestFunction())) {
this.root = root;
} else {
this.root =
root.getChild(
Ascii.toLowerCase(digestUtil.getDigestFunction().getValueDescriptor().getName()));
}
}

/** Returns {@code true} if the provided {@code key} is stored in the CAS. */
Expand Down Expand Up @@ -214,6 +223,14 @@ protected Path toPathNoSplit(String key) {
return root.getChild(key);
}

private static boolean isOldStyleDigestFunction(DigestFunction.Value digestFunction) {
// Old-style digest functions (SHA256, etc) are distinguishable by the length
// of their hash alone and do not require extra specification, but newer
// digest functions (which may have the same length hashes as the older
// functions!) must be explicitly specified in the upload resource name.
return digestFunction.getNumber() <= 7;
}

protected Path toPath(String key, boolean actionResult) {
String cacheFolder = actionResult ? AC_DIRECTORY : CAS_DIRECTORY;
// Create the file in a subfolder to bypass possible folder file count limits
Expand Down