From 995d62e379493b04e8eb8966fa8e4da26bcb619d Mon Sep 17 00:00:00 2001 From: olaola Date: Thu, 8 Feb 2018 09:38:53 -0800 Subject: User-friendlier representation of a missing digest. I moved it into DigestUtil preemptively in case we switch to binary instead of hex representation. TESTED=manually RELNOTES: None PiperOrigin-RevId: 185007558 --- .../google/devtools/build/lib/remote/CacheNotFoundException.java | 4 ++-- src/main/java/com/google/devtools/build/lib/remote/DigestUtil.java | 4 ++++ .../java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java | 6 +++--- .../devtools/build/lib/remote/SimpleBlobStoreActionCache.java | 6 +++--- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/remote/CacheNotFoundException.java b/src/main/java/com/google/devtools/build/lib/remote/CacheNotFoundException.java index 15ff3ef3ad..2f9e0c3ed0 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/CacheNotFoundException.java +++ b/src/main/java/com/google/devtools/build/lib/remote/CacheNotFoundException.java @@ -24,8 +24,8 @@ import java.io.IOException; public final class CacheNotFoundException extends IOException { private final Digest missingDigest; - CacheNotFoundException(Digest missingDigest) { - super("Missing digest: " + missingDigest); + CacheNotFoundException(Digest missingDigest, DigestUtil digestUtil) { + super("Missing digest: " + digestUtil.toString(missingDigest)); this.missingDigest = missingDigest; } diff --git a/src/main/java/com/google/devtools/build/lib/remote/DigestUtil.java b/src/main/java/com/google/devtools/build/lib/remote/DigestUtil.java index 2ef23b54fa..d3c93bbde2 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/DigestUtil.java +++ b/src/main/java/com/google/devtools/build/lib/remote/DigestUtil.java @@ -104,6 +104,10 @@ public class DigestUtil { return Digest.newBuilder().setHash(hexHash).setSizeBytes(size).build(); } + public String toString(Digest digest) { + return digest.getHash() + "/" + digest.getSizeBytes(); + } + public static Digest getFromInputCache(ActionInput input, MetadataProvider cache) throws IOException { Metadata metadata = cache.getMetadata(input); diff --git a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java index f0bc22b7b8..377c50d091 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/GrpcRemoteCache.java @@ -185,7 +185,7 @@ public class GrpcRemoteCache extends AbstractRemoteActionCache { if (!options.remoteInstanceName.isEmpty()) { resourceName += options.remoteInstanceName + "/"; } - resourceName += "blobs/" + digest.getHash() + "/" + digest.getSizeBytes(); + resourceName += "blobs/" + digestUtil.toString(digest); Iterator replies = bsBlockingStub() .read(ReadRequest.newBuilder().setResourceName(resourceName).build()); while (replies.hasNext()) { @@ -205,7 +205,7 @@ public class GrpcRemoteCache extends AbstractRemoteActionCache { }); } catch (RetryException e) { if (RemoteRetrierUtils.causedByStatus(e, Status.Code.NOT_FOUND)) { - throw new CacheNotFoundException(digest); + throw new CacheNotFoundException(digest, digestUtil); } throw e; } @@ -225,7 +225,7 @@ public class GrpcRemoteCache extends AbstractRemoteActionCache { }); } catch (RetryException e) { if (RemoteRetrierUtils.causedByStatus(e, Status.Code.NOT_FOUND)) { - throw new CacheNotFoundException(digest); + throw new CacheNotFoundException(digest, digestUtil); } throw e; } diff --git a/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCache.java b/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCache.java index d9c67dce4a..21ad4489bb 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCache.java @@ -196,7 +196,7 @@ public final class SimpleBlobStoreActionCache extends AbstractRemoteActionCache ByteArrayOutputStream out = new ByteArrayOutputStream(); boolean success = blobStore.getActionResult(digest.getHash(), out); if (!success) { - throw new CacheNotFoundException(digest); + throw new CacheNotFoundException(digest, digestUtil); } return out.toByteArray(); } @@ -216,7 +216,7 @@ public final class SimpleBlobStoreActionCache extends AbstractRemoteActionCache try (OutputStream out = dest.getOutputStream()) { boolean success = blobStore.get(digest.getHash(), out); if (!success) { - throw new CacheNotFoundException(digest); + throw new CacheNotFoundException(digest, digestUtil); } } } @@ -229,7 +229,7 @@ public final class SimpleBlobStoreActionCache extends AbstractRemoteActionCache try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { boolean success = blobStore.get(digest.getHash(), out); if (!success) { - throw new CacheNotFoundException(digest); + throw new CacheNotFoundException(digest, digestUtil); } return out.toByteArray(); } -- cgit v1.2.3